Skip to content

Commit

Permalink
fix: Use the stable github_advisory_id instead of the now unstable id…
Browse files Browse the repository at this point in the history
… in NPM audit results

Fixes #5419
  • Loading branch information
aikebah committed Mar 8, 2023
1 parent 8abb041 commit 247e071
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -451,11 +451,11 @@ protected void processResults(final List<Advisory> advisories, Engine engine,
//Create a new vulnerability out of the advisory returned by nsp.
final Vulnerability vuln = new Vulnerability();
vuln.setDescription(advisory.getOverview());
vuln.setName(String.valueOf(advisory.getId()));
vuln.setName(String.valueOf(advisory.getGhsaId()));
vuln.setUnscoredSeverity(advisory.getSeverity());
vuln.setSource(Vulnerability.Source.NPM);
vuln.addReference(
"Advisory " + advisory.getId() + ": " + advisory.getTitle(),
"NPM Advisory " + advisory.getGhsaId() + ": " + advisory.getTitle(),
advisory.getReferences(),
null
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ public class Advisory implements Serializable {
/**
* Serial version UID.
*/
private static final long serialVersionUID = -6157232800626565476L;
private static final long serialVersionUID = -6157232800626565475L;

/**
* The unique ID of the advisory as issued by NPM.
* The github_advisory_id of the advisory as issued by GHSA-hosted NPM Audit API.
*/
private int id;
private String ghsaId;

/**
* The timestamp of which the advisory was created.
Expand Down Expand Up @@ -122,13 +122,6 @@ public class Advisory implements Serializable {
*/
private String cwe;

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

public String getCreated() {
return created;
Expand Down Expand Up @@ -258,4 +251,11 @@ public void setCwe(String cwe) {
this.cwe = cwe;
}

public String getGhsaId() {
return ghsaId;
}

public void setGhsaId(String ghsaId) {
this.ghsaId = ghsaId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public List<Advisory> parse(JSONObject jsonResponse) throws JSONException {
*/
private Advisory parseAdvisory(JSONObject object) throws JSONException {
final Advisory advisory = new Advisory();
advisory.setId(object.getInt("id"));
advisory.setGhsaId(object.getString("github_advisory_id"));
advisory.setOverview(object.optString("overview", null));
advisory.setReferences(object.optString("references", null));
advisory.setCreated(object.optString("created", null));
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/resources/templates/htmlReport.vsl
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,7 @@ Getting Help: <a href="https://github.com/jeremylong/DependencyCheck/issues" tar
#if($vuln.getSource().name().equals("NVD"))
<p><b><a target="_blank" href="http://web.nvd.nist.gov/view/vuln/detail?vulnId=$enc.url($vuln.name)">$enc.html($vuln.name)</a></b>&nbsp;&nbsp;<button class="copybutton" title="Generate Suppression XML for this CVE for this file" data-display-name="$enc.html($dependency.DisplayFileName)" data-sha1="$enc.html($dependency.Sha1sum)" data-pkgurl="#if($supressPkgUrl)$enc.html($supressPkgUrl)#end" data-type-to-suppress="cve" data-id-to-suppress="$enc.html($vuln.name)">suppress</button></p>
#elseif($vuln.getSource().name().equals("NPM"))
<p><b><a target="_blank" href="https://www.npmjs.com/advisories/$enc.url($vuln.name)">NPM-$enc.html($vuln.name)</a></b>&nbsp;&nbsp;<button class="copybutton" title="Generate Suppression XML for this vulnerability for this file" data-display-name="$enc.html($dependency.DisplayFileName)" data-sha1="$enc.html($dependency.Sha1sum)" data-pkgurl="#if($supressPkgUrl)$enc.html($supressPkgUrl)#end" data-type-to-suppress="vulnerabilityName" data-id-to-suppress="$enc.html($vuln.name)">suppress</button></p>
<p><b><a target="_blank" href="https://github.com/advisories/$enc.url($vuln.name)">$enc.html($vuln.name) (NPM)</a></b>&nbsp;&nbsp;<button class="copybutton" title="Generate Suppression XML for this vulnerability for this file" data-display-name="$enc.html($dependency.DisplayFileName)" data-sha1="$enc.html($dependency.Sha1sum)" data-pkgurl="#if($supressPkgUrl)$enc.html($supressPkgUrl)#end" data-type-to-suppress="vulnerabilityName" data-id-to-suppress="$enc.html($vuln.name)">suppress</button></p>
#else
<p><span class="underline"><b>$enc.html($vuln.name)</b>&nbsp;($vuln.getSource().name())</span>&nbsp;&nbsp;<button class="copybutton" title="Generate Suppression XML for this vulnerability for this file" data-display-name="$enc.html($dependency.DisplayFileName)" data-sha1="$enc.html($dependency.Sha1sum)" data-pkgurl="#if($supressPkgUrl)$enc.html($supressPkgUrl)#end" data-type-to-suppress="vulnerabilityName" data-id-to-suppress="$enc.html($vuln.name)">suppress</button></p>
#end
Expand Down Expand Up @@ -1159,7 +1159,7 @@ Getting Help: <a href="https://github.com/jeremylong/DependencyCheck/issues" tar
#if($vuln.getSource().name().equals("NVD"))
<p><b><a target="_blank" href="http://web.nvd.nist.gov/view/vuln/detail?vulnId=$enc.url($vuln.name)">$enc.html($vuln.name)</a></b>&nbsp;&nbsp;<span class="suppressedLabel" >suppressed</span></p>
#elseif($vuln.getSource().name().equals("NPM"))
<p><b><a target="_blank" href="https://www.npmjs.com/advisories/$enc.url($vuln.name)">NPM-$enc.html($vuln.name)</a></b>&nbsp;&nbsp;<span class="suppressedLabel" >suppressed</span></p>
<p><b><a target="_blank" href="https://github.com/advisories/$enc.url($vuln.name)">$enc.html($vuln.name) (NPM)</a></b>&nbsp;&nbsp;<span class="suppressedLabel" >suppressed</span></p>
#else
<p><b>$enc.html($vuln.name)</b> ($vuln.getSource().name())&nbsp;&nbsp;<span class="suppressedLabel" >suppressed</span></p>
#end
Expand Down Expand Up @@ -1250,7 +1250,7 @@ Getting Help: <a href="https://github.com/jeremylong/DependencyCheck/issues" tar
<br/>
This report may contain data retrieved from the <a href="https://www.cisa.gov/known-exploited-vulnerabilities-catalog">CISA Known Exploited Vulnerability Catalog</a>.
<br/>
This report may contain data retrieved from the <a href="https://www.npmjs.com/advisories">NPM Public Advisories</a>.
This report may contain data retrieved from the <a href="https://github.com/advisories/">Github Advisory Database (via NPM Audit API)</a>.
<br/>
This report may contain data retrieved from <a href="https://retirejs.github.io/retire.js/">RetireJS</a>.
<br/>
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/resources/templates/jenkinsReport.vsl
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ Getting Help: <a href="https://github.com/jeremylong/DependencyCheck/issues" tar
#if($vuln.getSource().name().equals("NVD"))
<p><b><a target="_blank" href="http://web.nvd.nist.gov/view/vuln/detail?vulnId=$enc.url($vuln.name)">$enc.html($vuln.name)</a></b></p>
#elseif($vuln.getSource().name().equals("NPM"))
<p><b><a target="_blank" href="https://www.npmjs.com/advisories/$enc.url($vuln.name)">NPM-$enc.html($vuln.name)</a></b></p>
<p><b><a target="_blank" href="https://github.com/advisories/$enc.url($vuln.name)">$enc.html($vuln.name) (NPM)</a></b></p>
#else
<p><span class="underline"><b>$enc.html($vuln.name)</b>&nbsp;($vuln.getSource().name())</span></p>
#end
Expand Down Expand Up @@ -787,7 +787,7 @@ Getting Help: <a href="https://github.com/jeremylong/DependencyCheck/issues" tar
<br/>
This report may contain data retrieved from the <a href="https://www.cisa.gov/known-exploited-vulnerabilities-catalog">CISA Known Exploited Vulnerability Catalog</a>.
<br/>
This report may contain data retrieved from the <a href="https://www.npmjs.com/advisories">NPM Public Advisories</a>.
This report may contain data retrieved from the <a href="https://github.com/advisories/">Github Advisory Database (via NPM Audit API)</a>.
<br/>
This report may contain data retrieved from <a href="https://retirejs.github.io/retire.js/">RetireJS</a>.
<br/>
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/resources/templates/jsonReport.vsl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"credits": {
"NVD": "This report contains data retrieved from the National Vulnerability Database: http://nvd.nist.gov",
"CISA": "This report may contain data retrieved from the CISA Known Exploited Vulnerability Catalog: https://www.cisa.gov/known-exploited-vulnerabilities-catalog",
"NPM": "This report may contain data retrieved from the NPM Public Advisories: https://www.npmjs.com/advisories",
"NPM": "This report may contain data retrieved from the Github Advisory Database (via NPM Audit API): https://github.com/advisories/",
"RETIREJS": "This report may contain data retrieved from the RetireJS community: https://retirejs.github.io/retire.js/",
"OSSINDEX": "This report may contain data retrieved from the Sonatype OSS Index: https://ossindex.sonatype.org"
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/resources/templates/sarifReport.vsl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"help": {
"text": "",
"markdown": "#if($rule.getSource().equals("NVD"))For more information see [$enc.json($rule.name)](http://web.nvd.nist.gov/view/vuln/detail?vulnId=$enc.url($rule.name)).\n
#elseif($rule.getSource().equals("NPM"))For more information see [NPM-$enc.json($rule.name)](https://www.npmjs.com/advisories/$enc.url($rule.name))\n#end
#elseif($rule.getSource().equals("NPM"))For more information see [$enc.json($rule.name)](https://github.com/advisories/$enc.url($rule.name))\n#end
\n\n
If this is a false positive - consider using the HTML report to generate a suppression file.
For more information see [How dependency-check works](https://jeremylong.github.io/DependencyCheck/general/internals.html),
Expand Down Expand Up @@ -63,7 +63,7 @@ For more information see [How dependency-check works](https://jeremylong.github.
"disclaimer": "Dependency-Check is an open source tool performing a best effort analysis of 3rd party dependencies; false positives and false negatives may exist in the analysis performed by the tool. Use of the tool and the reporting provided constitutes acceptance for use in an AS IS condition, and there are NO warranties, implied or otherwise, with regard to the analysis or its use. Any use of the tool and the reporting provided is at the user's risk. In no event shall the copyright holder or OWASP be held liable for any damages whatsoever arising out of or in connection with the use of this tool, the analysis performed, or the resulting report.",
"nvd": "This report contains data retrieved from the National Vulnerability Database: http://nvd.nist.gov",
"cisa": "This report may contain data retrieved from the CISA Known Exploited Vulnerability Catalog: https://www.cisa.gov/known-exploited-vulnerabilities-catalog",
"npm": "This report may contain data retrieved from the NPM Public Advisories: https://www.npmjs.com/advisories",
"npm": "This report may contain data retrieved from the the Github Advisory Database (via NPM Audit API): https://github.com/advisories/",
"retirejs": "This report may contain data retrieved from the RetireJS community: https://retirejs.github.io/retire.js/",
"ossindex": "This report may contain data retrieved from the Sonatype OSS Index: https://ossindex.sonatype.org"
#foreach($prop in $properties.getMetaData().entrySet())
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/resources/templates/xmlReport.vsl
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Copyright (c) 2018 Jeremy Long. All Rights Reserved.
<version>$enc.xml($applicationVersion)</version>
#end
<reportDate>$scanDateXML</reportDate>
<credits>This report contains data retrieved from the National Vulnerability Database: https://nvd.nist.gov, NPM Public Advisories: https://www.npmjs.com/advisories, and the RetireJS community.</credits>
<credits>This report contains data retrieved from the National Vulnerability Database: https://nvd.nist.gov, Github Advisory Database (via NPM Audit API): https://github.com/advisories/, and the RetireJS community.</credits>
</projectInfo>
<dependencies>
#foreach($dependency in $dependencies)
Expand Down

0 comments on commit 247e071

Please sign in to comment.