retire 4.1.0 → 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -2
- package/lib/cli.js +46 -34
- package/lib/depsdev.d.ts +2 -2
- package/lib/depsdev.js +46 -25
- package/lib/repo.d.ts +1 -1
- package/lib/repo.js +7 -10
- package/lib/reporters/console.d.ts +1 -1
- package/lib/reporters/console.js +14 -7
- package/lib/reporters/cyclonedx-json.d.ts +1 -1
- package/lib/reporters/cyclonedx-json.js +29 -20
- package/lib/reporters/cyclonedx.d.ts +1 -1
- package/lib/reporters/cyclonedx.js +16 -7
- package/lib/reporters/depcheck.d.ts +1 -1
- package/lib/reporters/depcheck.js +34 -19
- package/lib/reporters/json.d.ts +1 -1
- package/lib/reporters/json.js +8 -4
- package/lib/reporting.d.ts +2 -2
- package/lib/reporting.js +33 -17
- package/lib/resolve.d.ts +2 -2
- package/lib/resolve.js +2 -2
- package/lib/retire.js +117 -120
- package/lib/scanner.d.ts +1 -1
- package/lib/scanner.js +17 -19
- package/lib/types.d.ts +4 -3
- package/lib/types.js +1 -1
- package/lib/utils.d.ts +1 -1
- package/lib/utils.js +0 -2
- package/package.json +6 -5
package/lib/scanner.js
CHANGED
|
@@ -32,17 +32,15 @@ const path = __importStar(require("path"));
|
|
|
32
32
|
const depsdev_1 = require("./depsdev");
|
|
33
33
|
const events = new events_1.EventEmitter();
|
|
34
34
|
const hash = {
|
|
35
|
-
|
|
35
|
+
sha1: (data) => {
|
|
36
36
|
const shasum = crypto.createHash('sha1');
|
|
37
37
|
shasum.update(data);
|
|
38
38
|
return shasum.digest('hex');
|
|
39
|
-
}
|
|
39
|
+
},
|
|
40
40
|
};
|
|
41
41
|
function emitResults(finding, options) {
|
|
42
42
|
if (options.includeOsv === true) {
|
|
43
|
-
Promise
|
|
44
|
-
.all(finding.results.map((r) => (0, depsdev_1.checkOSV)(r.component, r.version, options).then(v => { var _a; return r.vulnerabilities = ((_a = r.vulnerabilities) !== null && _a !== void 0 ? _a : []).concat(v); })))
|
|
45
|
-
.then(() => filterAndEmitResults(finding, options));
|
|
43
|
+
Promise.all(finding.results.map((r) => (0, depsdev_1.checkOSV)(r.component, r.version, options).then((v) => { var _a; return (r.vulnerabilities = ((_a = r.vulnerabilities) !== null && _a !== void 0 ? _a : []).concat(v)); }))).then(() => filterAndEmitResults(finding, options));
|
|
46
44
|
}
|
|
47
45
|
else {
|
|
48
46
|
filterAndEmitResults(finding, options);
|
|
@@ -60,18 +58,18 @@ function uniqueVulnerabilities(vulnerabilities) {
|
|
|
60
58
|
return undefined;
|
|
61
59
|
const unique = [];
|
|
62
60
|
for (const v of vulnerabilities) {
|
|
63
|
-
if (!unique.some(u => getIdentifiers(u).some(i => getIdentifiers(v).includes(i)))) {
|
|
61
|
+
if (!unique.some((u) => getIdentifiers(u).some((i) => getIdentifiers(v).includes(i)))) {
|
|
64
62
|
unique.push(v);
|
|
65
63
|
}
|
|
66
64
|
}
|
|
67
65
|
return unique;
|
|
68
66
|
}
|
|
69
67
|
function filterAndEmitResults(finding, options) {
|
|
70
|
-
finding.results.forEach(r => r.vulnerabilities = uniqueVulnerabilities(r.vulnerabilities));
|
|
68
|
+
finding.results.forEach((r) => (r.vulnerabilities = uniqueVulnerabilities(r.vulnerabilities)));
|
|
71
69
|
if (options.ignore)
|
|
72
70
|
removeIgnored(finding.results, options.ignore);
|
|
73
71
|
if (!options.verbose)
|
|
74
|
-
finding.results = finding.results.filter(f => retire.isVulnerable([f]));
|
|
72
|
+
finding.results = finding.results.filter((f) => retire.isVulnerable([f]));
|
|
75
73
|
if (finding.results.length == 0)
|
|
76
74
|
return;
|
|
77
75
|
if (retire.isVulnerable(finding.results)) {
|
|
@@ -83,25 +81,26 @@ function filterAndEmitResults(finding, options) {
|
|
|
83
81
|
}
|
|
84
82
|
function shouldIgnorePath(fileSpecs, ignores) {
|
|
85
83
|
var _a, _b;
|
|
86
|
-
return (_b = (_a = ignores.paths) === null || _a === void 0 ? void 0 : _a.some((i) => {
|
|
84
|
+
return ((_b = (_a = ignores.paths) === null || _a === void 0 ? void 0 : _a.some((i) => {
|
|
87
85
|
return fileSpecs.some((j) => i.test(j) || i.test(path.resolve(j)));
|
|
88
|
-
})) !== null && _b !== void 0 ? _b : false;
|
|
86
|
+
})) !== null && _b !== void 0 ? _b : false);
|
|
89
87
|
}
|
|
90
88
|
function removeIgnored(results, ignores) {
|
|
91
|
-
if (!(
|
|
89
|
+
if (!('descriptors' in ignores))
|
|
92
90
|
return;
|
|
93
91
|
results.forEach((r) => {
|
|
94
92
|
var _a, _b;
|
|
95
|
-
if (!(
|
|
93
|
+
if (!('vulnerabilities' in r))
|
|
96
94
|
return;
|
|
97
|
-
(_a = ignores.descriptors) === null || _a === void 0 ? void 0 : _a.filter((d) =>
|
|
95
|
+
(_a = ignores.descriptors) === null || _a === void 0 ? void 0 : _a.filter((d) => 'component' in d).forEach((i) => {
|
|
98
96
|
var _a;
|
|
99
97
|
if (r.component !== i.component)
|
|
100
98
|
return;
|
|
101
99
|
if (i.version && r.version !== i.version)
|
|
102
100
|
return;
|
|
103
|
-
if (i.severity) {
|
|
104
|
-
|
|
101
|
+
if (i.severity) {
|
|
102
|
+
//Remove vulnerabilities with the severity we want to drop
|
|
103
|
+
r.vulnerabilities = (_a = r.vulnerabilities) === null || _a === void 0 ? void 0 : _a.filter((v) => v.severity != i.severity);
|
|
105
104
|
return;
|
|
106
105
|
}
|
|
107
106
|
if (i.identifiers) {
|
|
@@ -117,7 +116,7 @@ function removeIgnored(results, ignores) {
|
|
|
117
116
|
function removeIgnoredVulnerabilitiesByIdentifier(identifiers, result) {
|
|
118
117
|
var _a;
|
|
119
118
|
result.vulnerabilities = (_a = result.vulnerabilities) === null || _a === void 0 ? void 0 : _a.filter((v) => {
|
|
120
|
-
if (!(
|
|
119
|
+
if (!('identifiers' in v))
|
|
121
120
|
return true;
|
|
122
121
|
return !Object.entries(identifiers || {}).every(([key, value]) => hasIdentifier(Object.assign({}, v.identifiers), key, value));
|
|
123
122
|
});
|
|
@@ -134,7 +133,7 @@ function scanJsFile(file, repo, options) {
|
|
|
134
133
|
}
|
|
135
134
|
let results = retire.scanFileName(file, repo);
|
|
136
135
|
if (!results || results.length === 0) {
|
|
137
|
-
results = retire.scanFileContent(fs.readFileSync(file,
|
|
136
|
+
results = retire.scanFileContent(fs.readFileSync(file, 'utf-8'), repo, hash);
|
|
138
137
|
}
|
|
139
138
|
emitResults({ file: file, results: results }, options);
|
|
140
139
|
}
|
|
@@ -144,7 +143,7 @@ function scanBowerFile(file, repo, options) {
|
|
|
144
143
|
return;
|
|
145
144
|
}
|
|
146
145
|
try {
|
|
147
|
-
const bower = JSON.parse(fs.readFileSync(file,
|
|
146
|
+
const bower = JSON.parse(fs.readFileSync(file, 'utf-8'));
|
|
148
147
|
if (bower.version) {
|
|
149
148
|
const results = retire.check(bower.name, bower.version, repo);
|
|
150
149
|
emitResults({ file: file, results: results }, options);
|
|
@@ -159,4 +158,3 @@ function on(event, handler) {
|
|
|
159
158
|
events.on(event, handler);
|
|
160
159
|
}
|
|
161
160
|
exports.on = on;
|
|
162
|
-
;
|
package/lib/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { Logger } from
|
|
2
|
+
import { Logger } from './reporting';
|
|
3
3
|
export type Repository = Record<string, {
|
|
4
4
|
bowername?: string;
|
|
5
5
|
vulnerabilities: Vulnerability[];
|
|
@@ -16,6 +16,7 @@ export type Vulnerability = {
|
|
|
16
16
|
below: string;
|
|
17
17
|
atOrAbove?: string;
|
|
18
18
|
severity: SeverityLevel;
|
|
19
|
+
cwe: string[];
|
|
19
20
|
identifiers?: {
|
|
20
21
|
CVE?: string[];
|
|
21
22
|
bug?: string;
|
|
@@ -53,10 +54,10 @@ export type ComponentDescriptor = {
|
|
|
53
54
|
component: string;
|
|
54
55
|
version?: string;
|
|
55
56
|
severity?: string;
|
|
56
|
-
identifiers?: Vulnerability[
|
|
57
|
+
identifiers?: Vulnerability['identifiers'];
|
|
57
58
|
justification?: string;
|
|
58
59
|
};
|
|
59
|
-
type Descriptor =
|
|
60
|
+
type Descriptor = PathDescriptor | ComponentDescriptor;
|
|
60
61
|
export type Options = {
|
|
61
62
|
log: Logger;
|
|
62
63
|
proxy?: string;
|
package/lib/types.js
CHANGED
package/lib/utils.d.ts
CHANGED
|
@@ -6,6 +6,6 @@ export declare function warn(options: {
|
|
|
6
6
|
warnlogger?: LogMethod;
|
|
7
7
|
logger?: LogMethod;
|
|
8
8
|
}): (...message: unknown[]) => void;
|
|
9
|
-
export declare function pick(p: Record<string, unknown>, keys: string[]): Record<typeof keys[number], unknown>;
|
|
9
|
+
export declare function pick(p: Record<string, unknown>, keys: string[]): Record<(typeof keys)[number], unknown>;
|
|
10
10
|
export declare function flatten<T>(e: T[][]): T[];
|
|
11
11
|
export {};
|
package/lib/utils.js
CHANGED
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"author": "Erlend Oftedal <erlend@oftedal.no>",
|
|
3
3
|
"name": "retire",
|
|
4
4
|
"description": "Retire is a tool for detecting use of vulnerable libraries",
|
|
5
|
-
"version": "4.
|
|
5
|
+
"version": "4.2.0",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"ansi-colors": "^4.1.1",
|
|
17
17
|
"commander": "^10.0.0",
|
|
18
18
|
"proxy-agent": "^5.0.0",
|
|
19
|
-
"uuid": "^
|
|
19
|
+
"uuid": "^9.0.0",
|
|
20
20
|
"walkdir": "0.4.1",
|
|
21
21
|
"zod": "^3.20.6"
|
|
22
22
|
},
|
|
@@ -30,14 +30,15 @@
|
|
|
30
30
|
"eslint-config-prettier": "^8.6.0",
|
|
31
31
|
"jsonschema": "^1.4.1",
|
|
32
32
|
"libxmljs": "^1.0.8",
|
|
33
|
-
"mocha": "^
|
|
33
|
+
"mocha": "^10.2.0",
|
|
34
34
|
"prettier": "^2.8.4",
|
|
35
|
-
"typescript": "^
|
|
35
|
+
"typescript": "^5.0.4"
|
|
36
36
|
},
|
|
37
37
|
"scripts": {
|
|
38
38
|
"test": "./test",
|
|
39
39
|
"build": "tsc && chmod ugo+x lib/cli.js",
|
|
40
40
|
"watch": "tsc --watch ",
|
|
41
|
+
"typecheck": "tsc --noEmit",
|
|
41
42
|
"lint": "eslint . --ext .ts --fix --ignore-path ../.gitignore",
|
|
42
43
|
"check": "npm run lint && npm run typecheck"
|
|
43
44
|
},
|
|
@@ -53,7 +54,7 @@
|
|
|
53
54
|
"software-composition-analysis",
|
|
54
55
|
"sca"
|
|
55
56
|
],
|
|
56
|
-
"files"
|
|
57
|
+
"files": [
|
|
57
58
|
"lib/**/*",
|
|
58
59
|
"CHANGELOG.md"
|
|
59
60
|
]
|