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
|
@@ -30,13 +30,17 @@ function configureDepCheckLogger(logger, writer, config, hash) {
|
|
|
30
30
|
let vulnsFound = false;
|
|
31
31
|
const finalResults = {
|
|
32
32
|
version: retire.version,
|
|
33
|
-
start: new Date().toISOString().replace(
|
|
33
|
+
start: new Date().toISOString().replace('Z', '+0000'),
|
|
34
34
|
data: [],
|
|
35
35
|
messages: [],
|
|
36
|
-
errors: []
|
|
36
|
+
errors: [],
|
|
37
37
|
};
|
|
38
38
|
logger.info = finalResults.messages.push;
|
|
39
|
-
logger.debug = config.verbose
|
|
39
|
+
logger.debug = config.verbose
|
|
40
|
+
? finalResults.messages.push
|
|
41
|
+
: () => {
|
|
42
|
+
return;
|
|
43
|
+
};
|
|
40
44
|
logger.warn = logger.error = finalResults.errors.push;
|
|
41
45
|
logger.logVulnerableDependency = (finding) => {
|
|
42
46
|
vulnsFound = true;
|
|
@@ -53,7 +57,7 @@ function configureDepCheckLogger(logger, writer, config, hash) {
|
|
|
53
57
|
<analysis xmlns="https://jeremylong.github.io/DependencyCheck/dependency-check.2.3.xsd">
|
|
54
58
|
<scanInfo>
|
|
55
59
|
<engineVersion>${retire.version}</engineVersion>
|
|
56
|
-
<dataSource><name>${config.jsRepo ||
|
|
60
|
+
<dataSource><name>${config.jsRepo || 'Retire.js github js repo'}</name><timestamp>${finalResults.start}</timestamp></dataSource>
|
|
57
61
|
</scanInfo>
|
|
58
62
|
<projectInfo>
|
|
59
63
|
<name>${config.path}</name>
|
|
@@ -61,11 +65,14 @@ function configureDepCheckLogger(logger, writer, config, hash) {
|
|
|
61
65
|
<credits>retire.js</credits>
|
|
62
66
|
</projectInfo>
|
|
63
67
|
<dependencies>`);
|
|
64
|
-
write(finalResults.data
|
|
68
|
+
write(finalResults.data
|
|
69
|
+
.filter((d) => d.results)
|
|
70
|
+
.map((r) => r.results
|
|
71
|
+
.map((dep, i) => {
|
|
65
72
|
const filepath = r.file;
|
|
66
73
|
if (!filepath)
|
|
67
74
|
return;
|
|
68
|
-
const filename = filepath.split(
|
|
75
|
+
const filename = filepath.split('/').slice(-1);
|
|
69
76
|
const file = fs.readFileSync(filepath);
|
|
70
77
|
const md5 = hash.md5(file);
|
|
71
78
|
const sha1 = hash.sha1(file);
|
|
@@ -86,17 +93,21 @@ function configureDepCheckLogger(logger, writer, config, hash) {
|
|
|
86
93
|
<description>(${dep.component}:${dep.version})</description>
|
|
87
94
|
<id>${i}</id>
|
|
88
95
|
</package>`;
|
|
89
|
-
const vulns = dep.vulnerabilities && dep.vulnerabilities.length > 0
|
|
90
|
-
|
|
96
|
+
const vulns = dep.vulnerabilities && dep.vulnerabilities.length > 0
|
|
97
|
+
? dep.vulnerabilities
|
|
98
|
+
.map((v) => {
|
|
99
|
+
const references = v.info
|
|
100
|
+
.map((i) => `
|
|
91
101
|
<reference>
|
|
92
102
|
<source>Retire.js</source>
|
|
93
103
|
<url>${i}</url>
|
|
94
104
|
<name>${i}</name>
|
|
95
|
-
</reference>`)
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
105
|
+
</reference>`)
|
|
106
|
+
.join('');
|
|
107
|
+
// const id = [v.identifiers && v.identifiers.CVE && v.identifiers.CVE[0], v.identifiers && v.identifiers.issue, dep.component + '@' + v.info[0]]
|
|
108
|
+
// .filter(n => n !== null)[0];
|
|
109
|
+
//TODO: Fix CVSS stuff - add to repo? add id to every bug in repo?
|
|
110
|
+
return `
|
|
100
111
|
<vulnerability source="retire">
|
|
101
112
|
<name>${dep.component}:${dep.version}</name>
|
|
102
113
|
<cvssV2>
|
|
@@ -107,16 +118,18 @@ function configureDepCheckLogger(logger, writer, config, hash) {
|
|
|
107
118
|
<confidentialImpact>PARTIAL</confidentialImpact>
|
|
108
119
|
<integrityImpact>PARTIAL</integrityImpact>
|
|
109
120
|
<availabilityImpact>PARTIAL</availabilityImpact>
|
|
110
|
-
<severity>${v.severity ||
|
|
121
|
+
<severity>${v.severity || 'medium'}</severity>
|
|
111
122
|
</cvssV2>
|
|
112
|
-
<description>${v.identifiers && v.identifiers.summary ||
|
|
123
|
+
<description>${(v.identifiers && v.identifiers.summary) || 'None'}</description>
|
|
113
124
|
<references>${references}
|
|
114
125
|
</references>
|
|
115
126
|
<vulnerableSoftware>
|
|
116
|
-
<software>${v.atOrAbove ?
|
|
127
|
+
<software>${v.atOrAbove ? '>= ' + v.atOrAbove : ''} < ${v.below}</software>
|
|
117
128
|
</vulnerableSoftware>
|
|
118
129
|
</vulnerability>`;
|
|
119
|
-
|
|
130
|
+
})
|
|
131
|
+
.join('')
|
|
132
|
+
: '';
|
|
120
133
|
return ` <dependency>
|
|
121
134
|
<fileName>${filename}</fileName>
|
|
122
135
|
<filePath>${filepath}</filePath>
|
|
@@ -130,12 +143,14 @@ function configureDepCheckLogger(logger, writer, config, hash) {
|
|
|
130
143
|
<vulnerabilities>${vulns}
|
|
131
144
|
</vulnerabilities>
|
|
132
145
|
</dependency>`;
|
|
133
|
-
})
|
|
146
|
+
})
|
|
147
|
+
.join('\n'))
|
|
148
|
+
.join('\n'));
|
|
134
149
|
write(` </dependencies>
|
|
135
150
|
</analysis>`);
|
|
136
151
|
writer.close(callback);
|
|
137
152
|
};
|
|
138
153
|
}
|
|
139
154
|
exports.default = {
|
|
140
|
-
configure: configureDepCheckLogger
|
|
155
|
+
configure: configureDepCheckLogger,
|
|
141
156
|
};
|
package/lib/reporters/json.d.ts
CHANGED
package/lib/reporters/json.js
CHANGED
|
@@ -34,10 +34,14 @@ exports.default = {
|
|
|
34
34
|
data: [],
|
|
35
35
|
messages: [],
|
|
36
36
|
errors: [],
|
|
37
|
-
time: undefined
|
|
37
|
+
time: undefined,
|
|
38
38
|
};
|
|
39
39
|
logger.info = finalResults.messages.push;
|
|
40
|
-
logger.debug = config.verbose
|
|
40
|
+
logger.debug = config.verbose
|
|
41
|
+
? finalResults.messages.push
|
|
42
|
+
: () => {
|
|
43
|
+
return;
|
|
44
|
+
};
|
|
41
45
|
logger.warn = logger.error = (message) => finalResults.errors.push(message);
|
|
42
46
|
logger.logVulnerableDependency = (finding) => {
|
|
43
47
|
finalResults.data.push(finding);
|
|
@@ -49,9 +53,9 @@ exports.default = {
|
|
|
49
53
|
};
|
|
50
54
|
logger.close = function (callback) {
|
|
51
55
|
finalResults.time = (Date.now() - scanStart) / 1000;
|
|
52
|
-
const res =
|
|
56
|
+
const res = config.outputformat === 'jsonsimple' ? finalResults.data : finalResults;
|
|
53
57
|
writer.out(JSON.stringify(res));
|
|
54
58
|
writer.close(callback);
|
|
55
59
|
};
|
|
56
|
-
}
|
|
60
|
+
},
|
|
57
61
|
};
|
package/lib/reporting.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { Finding } from
|
|
2
|
+
import { Finding } from './types';
|
|
3
3
|
export type LoggerOptions = {
|
|
4
4
|
outputpath: string;
|
|
5
5
|
verbose: boolean;
|
|
@@ -17,7 +17,7 @@ export type Hasher = {
|
|
|
17
17
|
};
|
|
18
18
|
export declare const hash: Hasher;
|
|
19
19
|
export type Writer = {
|
|
20
|
-
out: (...args: Parameters<typeof console[
|
|
20
|
+
out: (...args: Parameters<(typeof console)['log']>) => void;
|
|
21
21
|
err: (x: string) => void;
|
|
22
22
|
close: (callback?: () => void) => void;
|
|
23
23
|
};
|
package/lib/reporting.js
CHANGED
|
@@ -42,9 +42,11 @@ const loggers = {
|
|
|
42
42
|
cyclonedx: cyclonedx_1.default,
|
|
43
43
|
cyclonedxJSON: cyclonedx_json_1.default,
|
|
44
44
|
clean: console_1.default,
|
|
45
|
-
jsonsimple: json_1.default
|
|
45
|
+
jsonsimple: json_1.default,
|
|
46
|
+
};
|
|
47
|
+
let colorwarn = (x) => {
|
|
48
|
+
return x;
|
|
46
49
|
};
|
|
47
|
-
let colorwarn = (x) => { return x; };
|
|
48
50
|
let verbose = false;
|
|
49
51
|
function hashContent(hash, content) {
|
|
50
52
|
const h = crypto.createHash(hash);
|
|
@@ -59,31 +61,46 @@ exports.hash = {
|
|
|
59
61
|
};
|
|
60
62
|
const writer = {
|
|
61
63
|
out: console.log,
|
|
62
|
-
err: (x) => {
|
|
63
|
-
|
|
64
|
+
err: (x) => {
|
|
65
|
+
console.warn(colorwarn(x));
|
|
66
|
+
},
|
|
67
|
+
close: () => {
|
|
68
|
+
return;
|
|
69
|
+
},
|
|
64
70
|
};
|
|
65
71
|
const logger = {
|
|
66
|
-
info: (x) => {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
72
|
+
info: (x) => {
|
|
73
|
+
writer.out(x);
|
|
74
|
+
},
|
|
75
|
+
debug: (x) => {
|
|
76
|
+
if (verbose)
|
|
77
|
+
writer.out(x);
|
|
78
|
+
},
|
|
79
|
+
warn: (x) => {
|
|
80
|
+
writer.err(x);
|
|
81
|
+
},
|
|
82
|
+
error: (x) => {
|
|
83
|
+
writer.err(x);
|
|
84
|
+
},
|
|
85
|
+
logDependency: () => {
|
|
86
|
+
return;
|
|
87
|
+
},
|
|
88
|
+
logVulnerableDependency: () => {
|
|
89
|
+
return;
|
|
90
|
+
},
|
|
91
|
+
close: () => writer.close(),
|
|
74
92
|
};
|
|
75
|
-
;
|
|
76
93
|
function configureFileWriter(config) {
|
|
77
94
|
if (!config.outputpath)
|
|
78
95
|
return;
|
|
79
|
-
const fileDescriptor = fs.openSync(config.outputpath,
|
|
96
|
+
const fileDescriptor = fs.openSync(config.outputpath, 'w');
|
|
80
97
|
if (fileDescriptor < 0) {
|
|
81
98
|
console.error(`Could not open ${config.outputpath} for writing`);
|
|
82
99
|
process.exit(9);
|
|
83
100
|
}
|
|
84
101
|
const fileOutput = {
|
|
85
102
|
fileDescriptor,
|
|
86
|
-
stream: fs.createWriteStream('', { fd: fileDescriptor, autoClose: false })
|
|
103
|
+
stream: fs.createWriteStream('', { fd: fileDescriptor, autoClose: false }),
|
|
87
104
|
};
|
|
88
105
|
const writeToFile = (message) => {
|
|
89
106
|
fileOutput.stream.write(message);
|
|
@@ -102,7 +119,7 @@ function open(config) {
|
|
|
102
119
|
verbose = (_a = config.verbose) !== null && _a !== void 0 ? _a : false;
|
|
103
120
|
if (config.colors)
|
|
104
121
|
colorwarn = config.colorwarn;
|
|
105
|
-
const format = config.outputformat ||
|
|
122
|
+
const format = config.outputformat || 'console';
|
|
106
123
|
if (!(format in loggers)) {
|
|
107
124
|
console.warn(`Invalid outputformat: ${format}`);
|
|
108
125
|
process.exit(1);
|
|
@@ -112,4 +129,3 @@ function open(config) {
|
|
|
112
129
|
return logger;
|
|
113
130
|
}
|
|
114
131
|
exports.open = open;
|
|
115
|
-
;
|
package/lib/resolve.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { EventEmitter as Emitter } from
|
|
3
|
-
import { Options } from
|
|
2
|
+
import { EventEmitter as Emitter } from 'events';
|
|
3
|
+
import { Options } from './types';
|
|
4
4
|
export declare function scanJsFiles(path: string, options: Options): Emitter;
|
package/lib/resolve.js
CHANGED
|
@@ -27,8 +27,8 @@ exports.scanJsFiles = void 0;
|
|
|
27
27
|
const fs = __importStar(require("fs"));
|
|
28
28
|
const walkdir = __importStar(require("walkdir"));
|
|
29
29
|
function scanJsFiles(path, options) {
|
|
30
|
-
const finder = walkdir.find(path, {
|
|
31
|
-
const ext = (options.ext ||
|
|
30
|
+
const finder = walkdir.find(path, { follow_symlinks: false, no_return: true });
|
|
31
|
+
const ext = (options.ext || 'js').split(',').map((e) => `.${e}`);
|
|
32
32
|
function onFile(file) {
|
|
33
33
|
if (ext.some((e) => file.endsWith(e))) {
|
|
34
34
|
finder.emit('jsfile', file);
|
package/lib/retire.js
CHANGED
|
@@ -1,166 +1,163 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* This file is used by the browser plugins and the Cli scanner and thus
|
|
3
|
-
* cannot have any external dependencies (no require)
|
|
1
|
+
/*
|
|
2
|
+
* This file is used by the browser plugins and the Cli scanner and thus
|
|
3
|
+
* cannot have any external dependencies (no require)
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
var exports = exports || {};
|
|
7
|
-
exports.version = '4.
|
|
7
|
+
exports.version = '4.2.0';
|
|
8
8
|
|
|
9
9
|
function isDefined(o) {
|
|
10
|
-
|
|
10
|
+
return typeof o !== 'undefined';
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
function uniq(results){
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
13
|
+
function uniq(results) {
|
|
14
|
+
var keys = {};
|
|
15
|
+
return results.filter(function (r) {
|
|
16
|
+
var k = r.component + ' ' + r.version;
|
|
17
|
+
keys[k] = keys[k] || 0;
|
|
18
|
+
return keys[k]++ === 0;
|
|
19
|
+
});
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
function scan(data, extractor, repo, matcher) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
23
|
+
matcher = matcher || simpleMatch;
|
|
24
|
+
var detected = [];
|
|
25
|
+
for (var component in repo) {
|
|
26
|
+
var extractors = repo[component].extractors[extractor];
|
|
27
|
+
if (!isDefined(extractors)) continue;
|
|
28
|
+
for (var i in extractors) {
|
|
29
|
+
var match = matcher(extractors[i], data);
|
|
30
|
+
if (match) {
|
|
31
|
+
match = match.replace(/(\.|-)min$/, '');
|
|
32
|
+
detected.push({ version: match, component: component, detection: extractor });
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return uniq(detected);
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
function simpleMatch(regex, data) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
var re = new RegExp(regex);
|
|
41
|
+
var match = re.exec(data);
|
|
42
|
+
return match ? match[1] : null;
|
|
43
43
|
}
|
|
44
44
|
function replacementMatch(regex, data) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
45
|
+
var ar = /^\/(.*[^\\])\/([^\/]+)\/$/.exec(regex);
|
|
46
|
+
var re = new RegExp(ar[1]);
|
|
47
|
+
var match = re.exec(data);
|
|
48
|
+
var ver = null;
|
|
49
|
+
if (match) {
|
|
50
|
+
ver = match[0].replace(new RegExp(ar[1]), ar[2]);
|
|
51
|
+
return ver;
|
|
52
|
+
}
|
|
53
|
+
return null;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
function splitAndMatchAll(tokenizer) {
|
|
57
|
-
return function(regex, data) {
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
return function (regex, data) {
|
|
58
|
+
var elm = data.split(tokenizer).pop();
|
|
59
|
+
return simpleMatch('^' + regex + '$', elm);
|
|
60
60
|
};
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
|
|
64
|
-
|
|
65
63
|
function scanhash(hash, repo) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
64
|
+
for (var component in repo) {
|
|
65
|
+
var hashes = repo[component].extractors.hashes;
|
|
66
|
+
if (!isDefined(hashes)) continue;
|
|
67
|
+
if (hashes.hasOwnProperty(hash)) {
|
|
68
|
+
return [{ version: hashes[hash], component: component, detection: 'hash' }];
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return [];
|
|
74
72
|
}
|
|
75
73
|
|
|
76
|
-
|
|
77
|
-
|
|
78
74
|
function check(results, repo) {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
75
|
+
for (var r in results) {
|
|
76
|
+
var result = results[r];
|
|
77
|
+
if (!isDefined(repo[result.component])) continue;
|
|
78
|
+
var vulns = repo[result.component].vulnerabilities;
|
|
79
|
+
for (var i in vulns) {
|
|
80
|
+
if (!isDefined(vulns[i].below) || !isAtOrAbove(result.version, vulns[i].below)) {
|
|
81
|
+
if (isDefined(vulns[i].atOrAbove) && !isAtOrAbove(result.version, vulns[i].atOrAbove)) {
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
var vulnerability = { info: vulns[i].info, below: vulns[i].below, atOrAbove: vulns[i].atOrAbove };
|
|
85
|
+
if (vulns[i].severity) {
|
|
86
|
+
vulnerability.severity = vulns[i].severity;
|
|
87
|
+
}
|
|
88
|
+
if (vulns[i].identifiers) {
|
|
89
|
+
vulnerability.identifiers = vulns[i].identifiers;
|
|
90
|
+
}
|
|
91
|
+
result.vulnerabilities = result.vulnerabilities || [];
|
|
92
|
+
result.vulnerabilities.push(vulnerability);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return results;
|
|
101
97
|
}
|
|
102
98
|
|
|
103
99
|
function isAtOrAbove(version1, version2) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
100
|
+
var v1 = version1.split(/[\.\-]/g);
|
|
101
|
+
var v2 = version2.split(/[\.\-]/g);
|
|
102
|
+
var l = v1.length > v2.length ? v1.length : v2.length;
|
|
103
|
+
for (var i = 0; i < l; i++) {
|
|
104
|
+
var v1_c = toComparable(v1[i]);
|
|
105
|
+
var v2_c = toComparable(v2[i]);
|
|
106
|
+
if (typeof v1_c !== typeof v2_c) return typeof v1_c === 'number';
|
|
107
|
+
if (v1_c > v2_c) return true;
|
|
108
|
+
if (v1_c < v2_c) return false;
|
|
109
|
+
}
|
|
110
|
+
return true;
|
|
115
111
|
}
|
|
116
112
|
|
|
117
113
|
function toComparable(n) {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
114
|
+
if (!isDefined(n)) return 0;
|
|
115
|
+
if (n.match(/^[0-9]+$/)) {
|
|
116
|
+
return parseInt(n, 10);
|
|
117
|
+
}
|
|
118
|
+
return n;
|
|
123
119
|
}
|
|
124
120
|
|
|
125
|
-
|
|
126
121
|
//------- External API -------
|
|
127
122
|
|
|
128
|
-
exports.check = function(component, version, repo) {
|
|
129
|
-
|
|
123
|
+
exports.check = function (component, version, repo) {
|
|
124
|
+
return check([{ component: component, version: version }], repo);
|
|
130
125
|
};
|
|
131
126
|
|
|
132
|
-
exports.replaceVersion = function(jsRepoJsonAsText) {
|
|
133
|
-
|
|
127
|
+
exports.replaceVersion = function (jsRepoJsonAsText) {
|
|
128
|
+
return jsRepoJsonAsText.replace(/§§version§§/g, '[0-9][0-9.a-z_\\\\-]+');
|
|
134
129
|
};
|
|
135
130
|
|
|
136
|
-
exports.isVulnerable = function(results) {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
131
|
+
exports.isVulnerable = function (results) {
|
|
132
|
+
for (var r in results) {
|
|
133
|
+
if (
|
|
134
|
+
results[r].hasOwnProperty('vulnerabilities') &&
|
|
135
|
+
results[r].vulnerabilities != undefined &&
|
|
136
|
+
results[r].vulnerabilities.length > 0
|
|
137
|
+
)
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
140
|
+
return false;
|
|
141
141
|
};
|
|
142
142
|
|
|
143
|
-
exports.scanUri = function(uri, repo) {
|
|
144
|
-
|
|
145
|
-
|
|
143
|
+
exports.scanUri = function (uri, repo) {
|
|
144
|
+
var result = scan(uri, 'uri', repo);
|
|
145
|
+
return check(result, repo);
|
|
146
146
|
};
|
|
147
147
|
|
|
148
|
-
exports.scanFileName = function(fileName, repo) {
|
|
149
|
-
|
|
150
|
-
|
|
148
|
+
exports.scanFileName = function (fileName, repo) {
|
|
149
|
+
var result = scan(fileName, 'filename', repo, splitAndMatchAll('/'));
|
|
150
|
+
return check(result, repo);
|
|
151
151
|
};
|
|
152
152
|
|
|
153
|
-
exports.scanFileContent = function(content, repo, hasher) {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
153
|
+
exports.scanFileContent = function (content, repo, hasher) {
|
|
154
|
+
var normalizedContent = content.toString().replace(/(\r\n|\r)/g, '\n');
|
|
155
|
+
var result = scan(normalizedContent, 'filecontent', repo);
|
|
156
|
+
if (result.length === 0) {
|
|
157
|
+
result = scan(normalizedContent, 'filecontentreplace', repo, replacementMatch);
|
|
158
|
+
}
|
|
159
|
+
if (result.length === 0) {
|
|
160
|
+
result = scanhash(hasher.sha1(normalizedContent), repo);
|
|
161
|
+
}
|
|
162
|
+
return check(result, repo);
|
|
163
163
|
};
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
package/lib/scanner.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Finding, Options, Repository } from
|
|
1
|
+
import { Finding, Options, Repository } from './types';
|
|
2
2
|
export declare function scanJsFile(file: string, repo: Repository, options: Options): void;
|
|
3
3
|
export declare function scanBowerFile(file: string, repo: Repository, options: Options): void;
|
|
4
4
|
export declare function on(event: 'vulnerable-dependency-found' | 'dependency-found', handler: (finding: Finding) => void): void;
|