Skip to content

Commit

Permalink
Remove duplicate filenames in CycloneDX JSON output
Browse files Browse the repository at this point in the history
  • Loading branch information
eoftedal committed Jul 4, 2024
1 parent 4b40446 commit 5baff2d
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 12 deletions.
2 changes: 1 addition & 1 deletion chrome/extension/js/generated/retire-chrome.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function deepScan(content, repo) {
*/

var exports = exports || {};
exports.version = '5.1.0';
exports.version = '5.1.1';

function isDefined(o) {
return typeof o !== 'undefined';
Expand Down
8 changes: 7 additions & 1 deletion node/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
# Changelog

## [5.1.1]

### Bugfix

- Remove duplicates in filename output in CycloneDX JSON formats

## [5.1.0]

## Add
### Add

- Support for CycloneDX 1.6 JSON as output format
- Adding file location as property in CycloneDX 1.4 JSON output
Expand Down
2 changes: 1 addition & 1 deletion node/lib/retire.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

var exports = exports || {};
exports.version = '5.1.0';
exports.version = '5.1.1';

function isDefined(o) {
return typeof o !== 'undefined';
Expand Down
4 changes: 2 additions & 2 deletions node/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"author": "Erlend Oftedal <[email protected]>",
"name": "retire",
"description": "Retire is a tool for detecting use of vulnerable libraries",
"version": "5.1.0",
"version": "5.1.1",
"license": "Apache-2.0",
"repository": {
"type": "git",
Expand Down
8 changes: 6 additions & 2 deletions node/src/reporters/cyclonedx-1_6-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,12 @@ function configureCycloneDXJSONLogger(logger: Logger, writer: Writer, config: Lo
];
}
const purl = generatePURL(dep);
if (seen.has(purl)) {
seen.get(purl)?.evidence.occurrences.push(...evidence.occurrences);
const existing = seen.get(purl);
if (existing) {
const missing = evidence.occurrences.filter(
(x) => !existing.evidence.occurrences.some((y) => y.location == x.location),
);
existing.evidence.occurrences.push(...missing);
return undefined;
}
const result = {
Expand Down
18 changes: 14 additions & 4 deletions node/src/reporters/cyclonedx-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,13 @@ function configureCycloneDXJSONLogger(logger: Logger, writer: Writer, config: Lo
}
};

type Component = {
properties: Array<{ name: string; value: string }>;
};

logger.close = function (callback) {
const write = vulnsFound ? writer.err : writer.out;
const seen = new Set<string>();
const seen = new Map<string, Component>();
const components = finalResults.data
.filter((d) => d.results)
.map((r) =>
Expand All @@ -57,16 +61,22 @@ function configureCycloneDXJSONLogger(logger: Logger, writer: Writer, config: Lo
];
}
const purl = generatePURL(dep);
if (seen.has(purl)) return undefined;
seen.add(purl);
return {
const existing = seen.get(purl);
if (existing) {
const missing = properties.filter((p) => !existing.properties.some((ep) => ep.value === p.value));
existing.properties.push(...missing);
return undefined;
}
const result = {
type: 'library',
name: dep.component,
version: dep.version,
purl: purl,
hashes: hashes,
properties,
};
seen.set(purl, result);
return result;
})
.filter((x) => x != undefined),
)
Expand Down

0 comments on commit 5baff2d

Please sign in to comment.