Skip to content

fix: fail gracefully for npm .package-lock.json files #3654

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 2 commits into from
Jan 16, 2024

Conversation

terriko
Copy link
Contributor

@terriko terriko commented Dec 20, 2023

npm has a .package-lock.json file with a similar name but slightly different format than the package-lock.json file we can parse with our javascript language parser. This changes the javascript parser so it fails more gracefully if the format of a package-lock.json file does not appear to be what we can parse. As in, it prints a warning that it was unable to parse the file and does not halt the scan.

We should probably build a parser to handle these files correctly in the future, but for now this will skip them.

Also, I added some docstrings to the files I changed so interrogate would be happy.

* fixes intel#3559

npm has a .package-lock.json file with a similar name but slightly different
format than the package-lock.json file we can parse with our javascript
language parser.  This changes the javascript parser so it fails more
gracefully if the format of a package-lock.json file does not appear to
be what we can parse.  As in, it prints a warning that it was unable to
parse the file and does not halt the scan.

We should probably build a parser to handle these files correctly in the
future, but for now this will skip them.

Also, I added some docstrings to the files I changed so interrogate
would be happy.

Signed-off-by: Terri Oda <[email protected]>
@terriko
Copy link
Contributor Author

terriko commented Jan 3, 2024

Updating branch for tests.

@codecov-commenter
Copy link

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (427bb87) 79.47% compared to head (4c2f7ea) 79.27%.
Report is 2 commits behind head on main.

Files Patch % Lines
test/test_language_scanner.py 60.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3654      +/-   ##
==========================================
- Coverage   79.47%   79.27%   -0.21%     
==========================================
  Files         797      797              
  Lines       11944    11952       +8     
  Branches     1603     1605       +2     
==========================================
- Hits         9493     9475      -18     
- Misses       1991     2040      +49     
+ Partials      460      437      -23     
Flag Coverage Δ
longtests 73.78% <75.00%> (-0.01%) ⬇️
win-longtests 77.33% <75.00%> (-0.21%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@antoniogi antoniogi self-requested a review January 11, 2024 21:47
if "dependencies" not in data.keys():
self.logger.warning(
f"Cannot parse {self.filename}: no dependencies array found."
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That looks good. The only thing I can think of is: is there a case where you can have more than 1 "dependencies" keys? If so, would it be better to also add the product and version to the warning message? (Feel free to ignore if too dumb of a comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, in theory people could give us just about anything so it would be possible, but I haven't seen any tool generate this yet or anyone complain about us not parsing it. I'll put a note about it when I file an issue about handling the npm package locks, though, since it might be relevant then.

@terriko terriko merged commit 0dcd807 into intel:main Jan 16, 2024
inosmeet pushed a commit to inosmeet/cve-bin-tool that referenced this pull request Feb 6, 2024
* fixes intel#3559

npm has a .package-lock.json file with a similar name but slightly different
format than the package-lock.json file we can parse with our javascript
language parser.  This changes the javascript parser so it fails more
gracefully if the format of a package-lock.json file does not appear to
be what we can parse.  As in, it prints a warning that it was unable to
parse the file and does not halt the scan.

We should probably build a parser to handle these files correctly in the
future, but for now this will skip them.

Also, I added some docstrings to the files I changed so interrogate
would be happy.

Signed-off-by: Terri Oda <[email protected]>
inosmeet pushed a commit to inosmeet/cve-bin-tool that referenced this pull request Feb 16, 2024
* fixes intel#3559

npm has a .package-lock.json file with a similar name but slightly different
format than the package-lock.json file we can parse with our javascript
language parser.  This changes the javascript parser so it fails more
gracefully if the format of a package-lock.json file does not appear to
be what we can parse.  As in, it prints a warning that it was unable to
parse the file and does not halt the scan.

We should probably build a parser to handle these files correctly in the
future, but for now this will skip them.

Also, I added some docstrings to the files I changed so interrogate
would be happy.

Signed-off-by: Terri Oda <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fix: KeyError: 'dependencies' with npm projects
3 participants