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.
@@ -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("Z", "+0000"),
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 ? finalResults.messages.push : () => { return; };
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 || "Retire.js github js repo"}</name><timestamp>${finalResults.start}</timestamp></dataSource>
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.filter(d => d.results).map(r => r.results.map((dep, i) => {
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("/").slice(-1);
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 ? dep.vulnerabilities.map(v => {
90
- const references = v.info.map(i => `
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>`).join("");
96
- // const id = [v.identifiers && v.identifiers.CVE && v.identifiers.CVE[0], v.identifiers && v.identifiers.issue, dep.component + '@' + v.info[0]]
97
- // .filter(n => n !== null)[0];
98
- //TODO: Fix CVSS stuff - add to repo? add id to every bug in repo?
99
- return `
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 || "medium"}</severity>
121
+ <severity>${v.severity || 'medium'}</severity>
111
122
  </cvssV2>
112
- <description>${v.identifiers && v.identifiers.summary || "None"}</description>
123
+ <description>${(v.identifiers && v.identifiers.summary) || 'None'}</description>
113
124
  <references>${references}
114
125
  </references>
115
126
  <vulnerableSoftware>
116
- <software>${v.atOrAbove ? "&gt;= " + v.atOrAbove : ""} &lt; ${v.below}</software>
127
+ <software>${v.atOrAbove ? '&gt;= ' + v.atOrAbove : ''} &lt; ${v.below}</software>
117
128
  </vulnerableSoftware>
118
129
  </vulnerability>`;
119
- }).join('') : "";
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
- }).join("\n")).join("\n"));
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
  };
@@ -1,3 +1,3 @@
1
- import { ConfigurableLogger } from "../reporting";
1
+ import { ConfigurableLogger } from '../reporting';
2
2
  declare const _default: ConfigurableLogger;
3
3
  export default _default;
@@ -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 ? finalResults.messages.push : () => { return; };
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 = (config.outputformat === "jsonsimple") ? finalResults.data : finalResults;
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
  };
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import { Finding } from "./types";
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["log"]>) => void;
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) => { console.warn(colorwarn(x)); },
63
- close: () => { return; }
64
+ err: (x) => {
65
+ console.warn(colorwarn(x));
66
+ },
67
+ close: () => {
68
+ return;
69
+ },
64
70
  };
65
71
  const logger = {
66
- info: (x) => { writer.out(x); },
67
- debug: (x) => { if (verbose)
68
- writer.out(x); },
69
- warn: (x) => { writer.err(x); },
70
- error: (x) => { writer.err(x); },
71
- logDependency: () => { return; },
72
- logVulnerableDependency: () => { return; },
73
- close: () => writer.close()
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, "w");
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 || "console";
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 "events";
3
- import { Options } from "./types";
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, { "follow_symlinks": false, "no_return": true });
31
- const ext = (options.ext || "js").split(",").map((e) => `.${e}`);
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.1.0';
7
+ exports.version = '4.2.0';
8
8
 
9
9
  function isDefined(o) {
10
- return typeof o !== 'undefined';
10
+ return typeof o !== 'undefined';
11
11
  }
12
12
 
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
- });
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
- 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);
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
- var re = new RegExp(regex);
41
- var match = re.exec(data);
42
- return match ? match[1] : null;
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
- 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;
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
- var elm = data.split(tokenizer).pop();
59
- return simpleMatch('^' + regex + '$', elm);
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
- for (var component in repo) {
67
- var hashes = repo[component].extractors.hashes;
68
- if (!isDefined(hashes)) continue;
69
- if (hashes.hasOwnProperty(hash)) {
70
- return [{ version: hashes[hash], component: component, detection: 'hash' }];
71
- }
72
- }
73
- return [];
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
- for (var r in results) {
80
- var result = results[r];
81
- if (!isDefined(repo[result.component])) continue;
82
- var vulns = repo[result.component].vulnerabilities;
83
- for (var i in vulns) {
84
- if (!isDefined(vulns[i].below) || !isAtOrAbove(result.version, vulns[i].below)) {
85
- if (isDefined(vulns[i].atOrAbove) && !isAtOrAbove(result.version, vulns[i].atOrAbove)) {
86
- continue;
87
- }
88
- var vulnerability = { info : vulns[i].info, below: vulns[i].below, atOrAbove: vulns[i].atOrAbove };
89
- if (vulns[i].severity) {
90
- vulnerability.severity = vulns[i].severity;
91
- }
92
- if (vulns[i].identifiers) {
93
- vulnerability.identifiers = vulns[i].identifiers;
94
- }
95
- result.vulnerabilities = result.vulnerabilities || [];
96
- result.vulnerabilities.push(vulnerability);
97
- }
98
- }
99
- }
100
- return results;
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
- var v1 = version1.split(/[\.\-]/g);
105
- var v2 = version2.split(/[\.\-]/g);
106
- var l = v1.length > v2.length ? v1.length : v2.length;
107
- for (var i = 0; i < l; i++) {
108
- var v1_c = toComparable(v1[i]);
109
- var v2_c = toComparable(v2[i]);
110
- if (typeof v1_c !== typeof v2_c) return typeof v1_c === 'number';
111
- if (v1_c > v2_c) return true;
112
- if (v1_c < v2_c) return false;
113
- }
114
- return true;
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
- if (!isDefined(n)) return 0;
119
- if (n.match(/^[0-9]+$/)) {
120
- return parseInt(n, 10);
121
- }
122
- return n;
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
- return check([{component: component, version: version}], repo);
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
- return jsRepoJsonAsText.replace(/§§version§§/g, '[0-9][0-9.a-z_\\\\-]+');
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
- for (var r in results) {
138
- if (results[r].hasOwnProperty('vulnerabilities') && results[r].vulnerabilities != undefined && results[r].vulnerabilities.length > 0) return true;
139
- }
140
- return false;
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
- var result = scan(uri, 'uri', repo);
145
- return check(result, repo);
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
- var result = scan(fileName, 'filename', repo, splitAndMatchAll('/'));
150
- return check(result, repo);
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
- 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);
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 "./types";
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;