Skip to content

Commit 06f2805

Browse files
committed
feat: add CSAF 2.0 product tree generator
Signed-off-by: Rifa Achrinza <[email protected]>
1 parent 6e16597 commit 06f2805

File tree

3 files changed

+51
-3
lines changed

3 files changed

+51
-3
lines changed

advisories/lbsa-20201130.csaf.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,13 @@
6161
],
6262
"title": "Security Advisory 11-30-2020",
6363
"tracking": {
64-
"current_release_date": "2022-03-05T16:39:00.000Z",
64+
"current_release_date": "2022-03-07T03:42:00.000Z",
6565
"id": "LBSA-20201130",
6666
"initial_release_date": "2022-01-18T00:00:00.000Z",
6767
"revision_history": [
6868
{
6969
"date": "2022-03-07T03:42:00.000Z",
70-
"number": "1.2.0",
70+
"number": "2.0.0",
7171
"summary": "Updated product tree, product status."
7272
},
7373
{
@@ -87,7 +87,7 @@
8787
}
8888
],
8989
"status": "final",
90-
"version": "1.1.0"
90+
"version": "2.0.0"
9191
}
9292
},
9393
"product_tree": {

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"prettier:check": "npm run prettier:cli -- -l",
1919
"prettier:fix": "npm run prettier:cli -- --write",
2020
"ts-node": "ts-node --project=scripts/tsconfig.json",
21+
"generate-csaf20-product-tree": "npm run ts-node -- scripts/advisories/generate-csaf20-product-tree.ts",
2122
"validate-csaf20": "npm run ts-node -- scripts/advisories/validate-csaf20.ts",
2223
"validate-osv": "npm run ts-node -- scripts/advisories/validate-osv.ts"
2324
},
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// SPDX-FileCopyrightText: LoopBack Contributors
2+
// SPDX-License-Identifier: MIT
3+
4+
// This is a rudimentary script which reads a newline-delimited list of GitHub
5+
// tag name of format `<package name>@<package semver>` and generates the final
6+
// branch of the CSAF 2.0 Product Tree to stdout. Currently, it's only designed
7+
// for LoopBack 4 packages (i.e. `@loopback/*`).
8+
//
9+
// To generate a list of Git Tags for this script:
10+
// git tag --sort=taggerdate | grep <package name>@
11+
12+
import readline from 'readline';
13+
14+
var rl = readline.createInterface({
15+
input: process.stdin,
16+
output: process.stdout,
17+
terminal: false,
18+
});
19+
20+
const entries = [];
21+
22+
rl.on('line', line => {
23+
if (line.startsWith('@loopback/')) {
24+
const nameVerSeperator = line.lastIndexOf('@');
25+
const name = line.substring(0, nameVerSeperator);
26+
const version = line.substring(nameVerSeperator + 1);
27+
28+
entries.push({
29+
category: 'product_version',
30+
name: `Version ${version}`,
31+
product: {
32+
name: `${name} - Version ${version}`,
33+
product_id: `${entries.length + 1}`,
34+
product_identification_helper: {
35+
cpe: `cpe:2.3:a:loopback:${name
36+
.replace('/', '_')
37+
.replace('@', '')}:${version}:*:*:*:*:*:*:*`,
38+
purl: `pkg:npm/${encodeURIComponent(name)}@${version}`,
39+
},
40+
},
41+
});
42+
}
43+
});
44+
45+
rl.on('close', () => {
46+
console.log(JSON.stringify(entries, undefined, 2));
47+
});

0 commit comments

Comments
 (0)