-
Notifications
You must be signed in to change notification settings - Fork 547
refactor: refactor javascript parser (#1721) #1722
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 18 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
ffba885
Updated spelling.yml
XDRAGON2002 c191f20
Merge branch 'main' of https://github.com/intel/cve-bin-tool into main
XDRAGON2002 576871b
Merge branch 'main' of https://github.com/intel/cve-bin-tool into main
XDRAGON2002 5707392
Merge branch 'main' of https://github.com/intel/cve-bin-tool into main
XDRAGON2002 63981f0
Merge branch 'main' of https://github.com/intel/cve-bin-tool into main
XDRAGON2002 ad0032f
Merge branch 'main' of https://github.com/intel/cve-bin-tool into main
XDRAGON2002 a38777e
Merge branch 'main' of https://github.com/intel/cve-bin-tool into main
XDRAGON2002 db3e815
Merge branch 'main' of https://github.com/intel/cve-bin-tool into main
XDRAGON2002 e3d5602
Merge branch 'main' of https://github.com/intel/cve-bin-tool into main
XDRAGON2002 eadbc73
Merge branch 'main' of https://github.com/intel/cve-bin-tool into main
XDRAGON2002 a23f5c3
Merge branch 'main' of https://github.com/intel/cve-bin-tool into main
XDRAGON2002 2b5759a
Merge branch 'main' of https://github.com/intel/cve-bin-tool into main
XDRAGON2002 8723ee4
Merge branch 'main' of https://github.com/intel/cve-bin-tool into main
XDRAGON2002 dd8c8d3
Merge branch 'main' of https://github.com/intel/cve-bin-tool into main
XDRAGON2002 0d78f26
Merge branch 'main' of https://github.com/intel/cve-bin-tool into main
XDRAGON2002 78f041d
Merge branch 'main' of https://github.com/intel/cve-bin-tool into main
XDRAGON2002 d48bc14
Merge branch 'main' of https://github.com/intel/cve-bin-tool into main
XDRAGON2002 402bdb9
refactor: refactor javascript parser
XDRAGON2002 dfab7b1
fix: update file handling
XDRAGON2002 3b7217b
Merge branch 'main' into issue_1721
terriko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# Copyright (C) 2022 Intel Corporation | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
import json | ||
|
||
from cve_bin_tool.parsers import Parser | ||
from cve_bin_tool.util import ProductInfo, ScanInfo | ||
|
||
|
||
class JavascriptParser(Parser): | ||
def __init__(self, cve_db, logger): | ||
self.cve_db = cve_db | ||
self.logger = logger | ||
self.filename = "" | ||
|
||
def find_vendor(self, product, version): | ||
"""Find vendor for Javascript product""" | ||
if version == "*": | ||
return None | ||
vendor_package_pair = self.cve_db.get_vendor_product_pairs(product) | ||
vendorlist: list[ScanInfo] = [] | ||
if vendor_package_pair != []: | ||
# To handle multiple vendors, return all combinations of product/vendor mappings | ||
for v in vendor_package_pair: | ||
vendor = v["vendor"] | ||
file_path = self.filename | ||
# Tidy up version string | ||
if "^" in version: | ||
version = version[1:] | ||
self.logger.debug(f"{file_path} {product} {version} by {vendor}") | ||
vendorlist.append( | ||
ScanInfo(ProductInfo(vendor, product, version), file_path) | ||
) | ||
return vendorlist if len(vendorlist) > 0 else None | ||
return None | ||
|
||
def run_checker(self, filename): | ||
"""Process package-lock.json file and extract product and dependency details""" | ||
self.filename = filename | ||
fh = open(self.filename) | ||
data = json.load(fh) | ||
product = data["name"] | ||
version = data["version"] | ||
vendor = self.find_vendor(product, version) | ||
if vendor is not None: | ||
yield from vendor | ||
# Now process dependencies | ||
for i in data["dependencies"]: | ||
# To handle @actions/<product>: lines, extract product name from line | ||
product = i.split("/")[1] if "/" in i else i | ||
# Handle different formats. Either <product> : <version> or | ||
# <product>: { | ||
# ... | ||
# "version" : <version> | ||
# ... | ||
# } | ||
try: | ||
version = data["dependencies"][i]["version"] | ||
except Exception: | ||
# Cater for case when version field not present | ||
version = data["dependencies"][i] | ||
vendor = self.find_vendor(product, version) | ||
if vendor is not None: | ||
yield from vendor | ||
if "requires" in data["dependencies"][i]: | ||
for r in data["dependencies"][i]["requires"]: | ||
# To handle @actions/<product>: lines, extract product name from line | ||
product = r.split("/")[1] if "/" in r else r | ||
version = data["dependencies"][i]["requires"][r] | ||
vendor = self.find_vendor(product, version) | ||
if vendor is not None: | ||
yield from vendor | ||
self.logger.debug(f"Done scanning file: {self.filename}") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.