Skip to content
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

Update 'isExcepted' to check for CVE id #73

Merged
merged 1 commit into from
Mar 10, 2022

Conversation

kyleclark1824
Copy link

@kyleclark1824 kyleclark1824 commented Mar 7, 2022

Making this PR because every time a vulnerability get's updated the ID seems to change. So I constantly have to update my .nsprc file with the new ID.

It looks like the JSON output from the audit contains a cves property with the GitHub CVE ID's. So would something like this work?

So if we don't have a match to the cur.id check the cve id's. Not ideal having numeric a non-numeric ID's but that should allow the CVE ID to be used in the .nsprc as well as the other standard ID's.

Related issue: #60

@leedm777
Copy link

leedm777 commented Mar 7, 2022

I stumbled across this looking for alternatives due to IBM/audit-ci#211.

I think you're going to need to look at the advisory URL; not just the CVEs. There are at least some vulnerabilities that don't get assigned CVEs. See this comment on the audit-ci issue:

Does every vulnerability in the database have a CVE? It looks like here's maybe a few examples of ones that don't have CVEs: GHSA-r8hm-w5f7-wj39, GHSA-pjwm-rvh2-c87w, GHSA-xx4c-jj58-r7x6

@kyleclark1824
Copy link
Author

@leedm777, good point. Maybe even the github_advisory_id would be a good place to check. I'm just not positive which "ID's" change as things get updated.

@leedm777
Copy link

leedm777 commented Mar 8, 2022

@kyleclark1824 ,

Maybe even the github_advisory_id would be a good place to check.

I don't see auditReportVersion in the v2 output given by npm v8. Closest I see is via.url.

I'm just not positive which "ID's" change as things get updated.

That's entirely unclear, and probably an unintended consequence. The changing ids feels like a bug, but I'm not even sure where to report it.

What I observe changing is the via.source field from the v2 format, which looks like it's the same thing as the id field in the old format.

@guillermaster
Copy link

@kyleclark1824 the solution looks good, it will be very useful to have it merged soon. For some odd reason, those are IDs being currently used are changing frequently.
@jeemok do you mind reviewing this PR?

@kyleclark1824 kyleclark1824 force-pushed the feature/use-cve-id branch 2 times, most recently from 6b1995c to 296c681 Compare March 9, 2022 15:10
@leedm777
Copy link

leedm777 commented Mar 9, 2022

This patch only fixes npm v6 handling. npm v7 and newer doesn't even list the CVE in the JSON output; at least not with npm v8.3.1 😕

@kyle-clark1824
Copy link
Contributor

This patch only fixes npm v6 handling. npm v7 and newer doesn't even list the CVE in the JSON output; at least not with npm v8.3.1 😕

Yeah @leedm777, I was worried about that as well. This "fix" shouldn't hurt in those cases but a full fix would definitely be required. I'll see if I can find the JSON output for the other versions and add a more robust fix. Probably poke at it tonight.

I'm not seeing auditReportVersion in v 6.x either. Ideally there is a good way to determine what version is being run, then use that info to determine how to set isExcepted. But I'll take a look, worst case we can just have some more conditionals to handle additional cases.

@kyle-clark1824
Copy link
Contributor

@leedm777, I added some more conditions. The issue with auditReportVersion2 looks like more inconsistent data. Sometimes the via array is just a single string. In those cases I don't see any sort of Identifier.

I updated to check 4 places:

  • The id field - original
  • The cve array - my original change
  • The via array source - looks to be an ID
  • The via array url for matching github ID

There are still cases where a v8 vuln (maybe 7?) will not "find" a matching ID with this logic but this gives us much more options for ways to add exceptions. Below is an example of one of those cases using npm@latest

  "@angular-devkit/build-angular": {
      "name": "@angular-devkit/build-angular",
      "severity": "high",
      "isDirect": true,
      "via": [
        "webpack-dev-server"
      ],
      "effects": [],
      "range": "0.8.8 - 0.1102.17 || 0.1200.0-next.0 - 12.2.14 || 13.0.0-next.0 - 13.0.0-rc.3",
      "nodes": [
        "node_modules/@angular-devkit/build-angular"
      ],
      "fixAvailable": {
        "name": "@angular-devkit/build-angular",
        "version": "12.2.16",
        "isSemVerMajor": false
      }
    }
    
    ```
    
    I don't really see any way to capture ID's when the output looks like that (other than `name`?).

@jeemok jeemok changed the base branch from master to beta March 10, 2022 11:28
@jeemok
Copy link
Owner

jeemok commented Mar 10, 2022

hey @kyle-clark1824, thanks for initiating this change! let's work on this in a separate branch beta, I'll focus on v6 support first and try to cover different version later

if (cur.id && exceptionIds.includes(Number(cur.id)) || // NPM v6 contains 'id's to use
(cur.cves && exceptionIds.filter(id => cur.cves.includes(id)).length > 0) || // NPM v6 can also have an array of cve id's
(cur.via && cur.via[0].source && exceptionIds.includes(Number(cur.via[0].source))) || //auditReportVersion: 2. Check via.source for id
(cur.via && cur.via[0].url && exceptionIds.filter(id => cur.via[0].url.contains(id)).length > 0 )) //auditReportVersion: 2. Check via.url for github id
Copy link
Owner

Choose a reason for hiding this comment

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

this seems to be v7/v8 report structure, might need to move this checking to below v7 handling

Copy link
Contributor

Choose a reason for hiding this comment

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

Hey @jeemok. Yup I would say the v7/8 work should be down with the v7 handling, sorry about that! Glad you're able to take a look, I was really just hoping to get some ideas out there on how we could improve the ID stability a bit.

@jeemok
Copy link
Owner

jeemok commented Mar 10, 2022

let me merge this in first and help with the eslint issue and adding unit tests, etc.

@jeemok jeemok merged commit 5f30166 into jeemok:beta Mar 10, 2022
@kyle-clark1824
Copy link
Contributor

Sounds good @jeemok thanks!

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.

None yet

5 participants