retire 5.6.0 → 6.0.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/lib/scanner.js CHANGED
@@ -52,19 +52,22 @@ const hash = {
52
52
  return shasum.digest('hex');
53
53
  },
54
54
  };
55
- function emitResults(finding, options, repo) {
55
+ async function emitResults(finding, options, repo) {
56
56
  if (options.includeOsv === true) {
57
- Promise.all(finding.results.map((r) => (0, depsdev_1.checkOSV)(r.component, r.version, options).then((v) => (r.vulnerabilities = (r.vulnerabilities ?? []).concat(v))))).then(() => filterAndEmitResults(finding, options, repo));
58
- }
59
- else {
60
- filterAndEmitResults(finding, options, repo);
57
+ await Promise.all(finding.results.map((r) => (0, depsdev_1.checkOSV)(r.npmname ?? r.component, r.version, options).then((v) => (r.vulnerabilities = (r.vulnerabilities ?? []).concat(v)))));
61
58
  }
59
+ filterAndEmitResults(finding, options, repo);
62
60
  }
63
61
  function getIdentifiers(v) {
64
- return (v.identifiers?.CVE ?? [])
65
- .concat(v.identifiers?.bug ?? [])
66
- .concat(v.identifiers?.issue ?? [])
67
- .concat(v.identifiers?.githubID ?? []);
62
+ const identifiers = v.identifiers ?? {};
63
+ const canonical = (identifiers.CVE ?? []).map((id) => `CVE:${id}`);
64
+ if (identifiers.githubID)
65
+ canonical.push(`githubID:${identifiers.githubID}`);
66
+ if (canonical.length)
67
+ return canonical;
68
+ return Object.entries(identifiers)
69
+ .filter(([key, value]) => key !== 'summary' && value != null)
70
+ .flatMap(([key, value]) => (Array.isArray(value) ? value : [value]).map((id) => `${key}:${id}`));
68
71
  }
69
72
  function uniqueVulnerabilities(vulnerabilities) {
70
73
  if (!vulnerabilities)
@@ -144,7 +147,7 @@ function hasIdentifier(identifiers, key, value) {
144
147
  const identifier = identifiers[key];
145
148
  return Array.isArray(identifier) ? identifier.some((x) => x === value) : identifier === value;
146
149
  }
147
- function scanJsFile(file, repo, options) {
150
+ async function scanJsFile(file, repo, options) {
148
151
  if (options.ignore && shouldIgnorePath([file], options.ignore)) {
149
152
  return;
150
153
  }
@@ -161,22 +164,25 @@ function scanJsFile(file, repo, options) {
161
164
  }
162
165
  }
163
166
  }
164
- emitResults({ file: file, results: results }, options, repo);
167
+ await emitResults({ file: file, results: results }, options, repo);
165
168
  }
166
- function scanBowerFile(file, repo, options) {
169
+ async function scanBowerFile(file, repo, options) {
167
170
  if (options.ignore && shouldIgnorePath([file], options.ignore)) {
168
171
  return;
169
172
  }
173
+ let results;
170
174
  try {
171
175
  const bower = JSON.parse(fs.readFileSync(file, 'utf-8'));
172
176
  if (bower.version) {
173
- const results = retire.check(bower.name, bower.version, repo);
174
- emitResults({ file: file, results: results }, options, repo);
177
+ results = retire.check(bower.name, bower.version, repo);
175
178
  }
176
179
  }
177
- catch (e) {
180
+ catch {
178
181
  options.log.warn(`Could not parse file: ${file}`);
179
182
  }
183
+ if (results) {
184
+ await emitResults({ file: file, results: results }, options, repo);
185
+ }
180
186
  }
181
187
  function on(event, handler) {
182
188
  events.on(event, handler);
package/lib/types.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import z from 'zod';
1
2
  import { Logger } from './reporting';
2
3
  export type Repository = Record<string, {
3
4
  bowername?: string[];
@@ -55,6 +56,7 @@ export declare const severityLevels: {
55
56
  readonly critical: 4;
56
57
  };
57
58
  export type SeverityLevel = keyof typeof severityLevels;
59
+ export declare const severityParser: z.ZodEnum<["none" | "low" | "medium" | "high" | "critical"]>;
58
60
  export type PathDescriptor = {
59
61
  path: string;
60
62
  justification?: string;
@@ -93,4 +95,29 @@ export type Options = {
93
95
  includeOsv?: boolean;
94
96
  deep?: boolean;
95
97
  };
98
+ export declare const ignoreFileParser: z.ZodArray<z.ZodIntersection<z.ZodObject<{
99
+ justification: z.ZodString;
100
+ }, "strip", z.ZodTypeAny, {
101
+ justification: string;
102
+ }, {
103
+ justification: string;
104
+ }>, z.ZodUnion<[z.ZodObject<{
105
+ path: z.ZodString;
106
+ }, "strip", z.ZodTypeAny, {
107
+ path: string;
108
+ }, {
109
+ path: string;
110
+ }>, z.ZodObject<{
111
+ component: z.ZodString;
112
+ version: z.ZodOptional<z.ZodString>;
113
+ identifiers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
114
+ }, "strip", z.ZodTypeAny, {
115
+ component: string;
116
+ version?: string | undefined;
117
+ identifiers?: Record<string, string> | undefined;
118
+ }, {
119
+ component: string;
120
+ version?: string | undefined;
121
+ identifiers?: Record<string, string> | undefined;
122
+ }>]>>, "many">;
96
123
  export {};
package/lib/types.js CHANGED
@@ -1,6 +1,10 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.severityLevels = void 0;
6
+ exports.ignoreFileParser = exports.severityParser = exports.severityLevels = void 0;
7
+ const zod_1 = __importDefault(require("zod"));
4
8
  exports.severityLevels = {
5
9
  none: 0,
6
10
  low: 1,
@@ -8,3 +12,17 @@ exports.severityLevels = {
8
12
  high: 3,
9
13
  critical: 4,
10
14
  };
15
+ exports.severityParser = zod_1.default.enum(Object.keys(exports.severityLevels));
16
+ exports.ignoreFileParser = zod_1.default.array(zod_1.default
17
+ .object({
18
+ justification: zod_1.default.string(),
19
+ })
20
+ .and(zod_1.default
21
+ .object({
22
+ path: zod_1.default.string(),
23
+ })
24
+ .or(zod_1.default.object({
25
+ component: zod_1.default.string(),
26
+ version: zod_1.default.string().optional(),
27
+ identifiers: zod_1.default.record(zod_1.default.string(), zod_1.default.string()).optional(),
28
+ }))));
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": "5.6.0",
5
+ "version": "6.0.0",
6
6
  "license": "Apache-2.0",
7
7
  "repository": {
8
8
  "type": "git",
@@ -13,35 +13,35 @@
13
13
  },
14
14
  "main": "./lib/retire.js",
15
15
  "dependencies": {
16
- "ansi-colors": "^4.1.1",
17
16
  "astronomical": "^3.2.0",
18
17
  "commander": "^10.0.1",
19
- "proxy-agent": "^6.4.0",
20
18
  "walkdir": "0.4.1",
21
19
  "zod": "^3.22.4"
22
20
  },
23
21
  "devDependencies": {
22
+ "@eslint/js": "^10.0.1",
24
23
  "@types/node": "^18.13.0",
25
- "@types/uuid": "^9.0.0",
26
- "@typescript-eslint/eslint-plugin": "^7.1.1",
27
- "@typescript-eslint/parser": "^7.1.1",
28
- "eslint": "^8.34.0",
29
- "eslint-config-prettier": "^9.0.0",
24
+ "@types/uuid": "^10.0.0",
25
+ "eslint": "^10.12.0",
26
+ "eslint-config-prettier": "^10.1.8",
27
+ "globals": "^17.13.0",
30
28
  "jsonschema": "^1.4.1",
31
29
  "prettier": "^3.1.0",
32
30
  "ts-node": "^10.9.2",
33
- "typescript": "^5.0.4"
31
+ "typescript": "^6.0.3",
32
+ "typescript-eslint": "^8.71.1"
34
33
  },
35
34
  "scripts": {
36
35
  "test": "TS_NODE_PROJECT=tsconfig.spec.json node --require ts-node/register --test \"spec/tests/**/*.spec.ts\"",
37
36
  "build": "tsc && chmod ugo+x lib/cli.js && cp src/retire.d.ts lib/retire.d.ts && cp ../LICENSE.md .",
38
37
  "watch": "tsc --watch ",
39
38
  "typecheck": "tsc --noEmit",
40
- "lint": "eslint . --ext .ts --fix --ignore-path ../.gitignore",
39
+ "lint": "eslint . --fix",
40
+ "format": "prettier --write \"src/**/*.ts\" \"spec/**/*.ts\"",
41
41
  "check": "npm run lint && npm run typecheck"
42
42
  },
43
43
  "engines": {
44
- "node": ">= 18.0.0"
44
+ "node": "^20.19.0 || >=22.12.0"
45
45
  },
46
46
  "keywords": [
47
47
  "sbom",