loadwise 0.7.0 → 0.8.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/README.md +23 -15
- package/dist/bin/loadwise.js +12 -24
- package/dist/lib/accessibility/analyze.js +5 -3
- package/dist/lib/accessibility/angular-inline.js +9 -11
- package/dist/lib/accessibility/angular-literal.js +39 -0
- package/dist/lib/accessibility/form-context.js +36 -0
- package/dist/lib/accessibility/frame-head.js +92 -0
- package/dist/lib/accessibility/frame-viewport.js +149 -0
- package/dist/lib/accessibility/jsx-elements.js +13 -3
- package/dist/lib/accessibility/markup-files.js +7 -2
- package/dist/lib/accessibility/rule-ids.js +3 -0
- package/dist/lib/accessibility/rules.js +128 -41
- package/dist/lib/accessibility/site-fixes/buttons.js +5 -1
- package/dist/lib/accessibility/template-attributes.js +5 -3
- package/dist/lib/accessibility/template-elements.js +25 -6
- package/dist/lib/accessibility/template-file.js +40 -25
- package/dist/lib/editor/accessibility-examples.js +6 -1
- package/dist/lib/editor/actions.js +46 -7
- package/dist/lib/editor/apply-fix.js +69 -4
- package/dist/lib/editor/configured-setup.js +5 -3
- package/dist/lib/editor/diagnostics.js +206 -17
- package/dist/lib/editor/dismissals.js +85 -26
- package/dist/lib/editor/editor-document.js +5 -2
- package/dist/lib/editor/editor-launcher.js +7 -2
- package/dist/lib/editor/language-server.js +64 -25
- package/dist/lib/editor/native-setup.js +3 -2
- package/dist/lib/editor/perf-watch.js +8 -6
- package/dist/lib/editor/reliability-examples.js +15 -0
- package/dist/lib/editor/scan-session.js +29 -8
- package/dist/lib/editor/server-commands.js +36 -9
- package/dist/lib/editor/setup-server.js +1 -1
- package/dist/lib/editor/setup-vim.js +6 -4
- package/dist/lib/editor/workspace-files.js +61 -7
- package/dist/lib/editor/workspace-paths.js +41 -1
- package/dist/lib/maintainability/analysis/analyze-source.js +1 -1
- package/dist/lib/maintainability/architecture/architecture.js +4 -4
- package/dist/lib/maintainability/cli/changed-lines.js +20 -2
- package/dist/lib/maintainability/cli/inputs.js +9 -1
- package/dist/lib/maintainability/cli.js +4 -0
- package/dist/lib/maintainability/entry-points/entry-points.js +44 -15
- package/dist/lib/maintainability/entry-points/html-entry-points.js +5 -1
- package/dist/lib/maintainability/quality/functions.js +9 -6
- package/dist/lib/maintainability/quality/limits.js +19 -0
- package/dist/lib/maintainability/quality/size-limits.js +8 -2
- package/dist/lib/maintainability/quality/stray-console.js +62 -1
- package/dist/lib/maintainability/quality/tsconfig-strict.js +2 -0
- package/dist/lib/maintainability/scan-changed.js +4 -1
- package/dist/lib/maintainability/scan-worker.js +6 -2
- package/dist/lib/maintainability/scan.js +21 -8
- package/dist/lib/maintainability/unused/module-usage.js +43 -21
- package/dist/lib/maintainability/unused/unused-modules.js +5 -10
- package/dist/lib/performance/analysis/source-inputs.js +7 -2
- package/dist/lib/performance/analysis/source-options.js +7 -6
- package/dist/lib/performance/analyze.js +16 -3
- package/dist/lib/performance/cli/cli-output.js +1 -0
- package/dist/lib/performance/cli/cli-scan.js +21 -2
- package/dist/lib/performance/cli.js +8 -3
- package/dist/lib/performance/collections/memory-growth.js +55 -12
- package/dist/lib/performance/contracts/openapi.js +13 -4
- package/dist/lib/performance/datastores/pg-integrity.js +61 -22
- package/dist/lib/performance/datastores/pg-session-release.js +114 -0
- package/dist/lib/performance/datastores/pg-session-sql.js +144 -0
- package/dist/lib/performance/datastores/pooling.js +56 -2
- package/dist/lib/performance/datastores/redis.js +94 -18
- package/dist/lib/performance/datastores/session-store.js +2 -1
- package/dist/lib/performance/db/checks.js +19 -8
- package/dist/lib/performance/db/gateway.js +3 -1
- package/dist/lib/performance/db/plan-estimates.js +4 -4
- package/dist/lib/performance/engine/native.js +11 -7
- package/dist/lib/performance/evidence/plans.js +7 -5
- package/dist/lib/performance/evidence/traces.js +21 -1
- package/dist/lib/performance/frontend/angular-teardown.js +96 -0
- package/dist/lib/performance/frontend/effect-cleanup.js +148 -0
- package/dist/lib/performance/frontend/frontend-dom-perf.js +14 -2
- package/dist/lib/performance/frontend/frontend-helpers.js +1 -9
- package/dist/lib/performance/frontend/frontend-perf.js +72 -57
- package/dist/lib/performance/migrations/extract-code-sql.js +16 -4
- package/dist/lib/performance/migrations/extract-code.js +13 -5
- package/dist/lib/performance/migrations/extract-sql.js +82 -38
- package/dist/lib/performance/migrations/operations.js +56 -13
- package/dist/lib/performance/migrations/postgres-lock-timeout.js +52 -0
- package/dist/lib/performance/migrations/postgres-registry.js +127 -26
- package/dist/lib/performance/migrations/postgres-settings.js +78 -0
- package/dist/lib/performance/migrations/rules-postgres-add-column.js +3 -3
- package/dist/lib/performance/migrations/rules-postgres-shared.js +9 -0
- package/dist/lib/performance/migrations/rules-postgres.js +88 -39
- package/dist/lib/performance/orm/offset-pagination.js +6 -4
- package/dist/lib/performance/orm/prisma-aggregates.js +69 -18
- package/dist/lib/performance/orm/unbounded-list-chain.js +29 -0
- package/dist/lib/performance/orm/unbounded-list-queries.js +18 -13
- package/dist/lib/performance/polyglot.js +111 -14
- package/dist/lib/performance/projects.js +3 -3
- package/dist/lib/performance/query-loops/sequential-loops.js +1 -0
- package/dist/lib/performance/request/backend-mastery.js +151 -42
- package/dist/lib/performance/request/mongoose-lean.js +175 -10
- package/dist/lib/performance/request/phase5-rules.js +74 -13
- package/dist/lib/performance/request/sql-select-star.js +150 -0
- package/dist/lib/performance/request/unbounded-promise-all.js +54 -29
- package/dist/lib/performance/request/upload-limits.js +5 -1
- package/dist/lib/performance/site-fix.js +4 -4
- package/dist/lib/performance/site-fixes/backend-mastery-fixes.js +298 -16
- package/dist/lib/performance/site-fixes/frontend-fixes.js +350 -10
- package/dist/lib/performance/site-fixes/migration-context.js +8 -1
- package/dist/lib/performance/site-fixes/migration-lock-rules.js +66 -30
- package/dist/lib/performance/site-fixes/prisma-aggregates.js +29 -9
- package/dist/lib/performance/site-fixes/small-rewrites.js +168 -10
- package/dist/lib/performance/site-fixes/sync-calls.js +14 -12
- package/dist/lib/performance/site-fixes/upload-limits.js +13 -7
- package/dist/lib/performance/sql/mysql-tokens.js +38 -12
- package/dist/lib/reliability/boundary-access.js +114 -57
- package/dist/lib/reliability/react-bugs.js +18 -4
- package/dist/lib/reliability/resource-leak-intervals.js +258 -0
- package/dist/lib/reliability/resource-leaks.js +209 -195
- package/dist/lib/reliability/rule-ids.js +10 -1
- package/dist/lib/reliability/site-fixes/resource-leaks.js +16 -1
- package/dist/lib/reliability/swallowed-errors.js +107 -21
- package/dist/lib/reliability/test-cleanup-after-await.js +92 -18
- package/dist/lib/reliability/walk.js +3 -2
- package/dist/lib/security/auth-crypto/hashing.js +24 -8
- package/dist/lib/security/auth-crypto/jwt.js +21 -6
- package/dist/lib/security/auth-crypto/secrets.js +44 -1
- package/dist/lib/security/auth-crypto/shared.js +3 -1
- package/dist/lib/security/auth-crypto/signing-algorithm.js +79 -0
- package/dist/lib/security/auth-crypto/transport-and-ciphers.js +85 -1
- package/dist/lib/security/cli.js +6 -2
- package/dist/lib/security/cookie-credentials.js +115 -0
- package/dist/lib/security/cookie-csrf.js +241 -0
- package/dist/lib/security/deps/advisory.js +50 -109
- package/dist/lib/security/deps/cli.js +1 -1
- package/dist/lib/security/deps/cvss-score.js +14 -0
- package/dist/lib/security/deps/fixed-version.js +97 -0
- package/dist/lib/security/deps/lockfiles.js +135 -74
- package/dist/lib/security/deps/osv.js +11 -3
- package/dist/lib/security/deps/scan.js +47 -20
- package/dist/lib/security/deps/yarn-lock.js +158 -0
- package/dist/lib/security/examples/injection.cjs +4 -0
- package/dist/lib/security/exposure/cookies.js +17 -2
- package/dist/lib/security/exposure/cors-origin-regex.js +2 -3
- package/dist/lib/security/exposure/frontend-security.js +21 -14
- package/dist/lib/security/exposure/jsx-url.js +18 -33
- package/dist/lib/security/exposure/logging.js +49 -10
- package/dist/lib/security/exposure/prototype-pollution.js +126 -56
- package/dist/lib/security/exposure/react-html.js +26 -0
- package/dist/lib/security/exposure/reflected-xss.js +34 -5
- package/dist/lib/security/files/compose.js +126 -1
- package/dist/lib/security/files/dockerfile.js +62 -4
- package/dist/lib/security/files/index.js +1 -1
- package/dist/lib/security/injection/command.js +46 -18
- package/dist/lib/security/injection/index.js +2 -0
- package/dist/lib/security/injection/ldap.js +86 -0
- package/dist/lib/security/injection/nosql.js +28 -4
- package/dist/lib/security/injection/redos.js +1 -1
- package/dist/lib/security/injection/rule-ids.js +1 -0
- package/dist/lib/security/injection/shared.js +5 -1
- package/dist/lib/security/injection/sql.js +28 -13
- package/dist/lib/security/lexical-declaration.js +113 -0
- package/dist/lib/security/pg-dynamic-query.js +28 -1
- package/dist/lib/security/pg-identifier-guards.js +107 -3
- package/dist/lib/security/phase5-rules.js +26 -135
- package/dist/lib/security/polyglot.js +2 -2
- package/dist/lib/security/redirect-settings.js +98 -0
- package/dist/lib/security/request-forgery/open-redirect.js +18 -5
- package/dist/lib/security/request-forgery/path-traversal.js +84 -6
- package/dist/lib/security/request-forgery/shared.js +1 -7
- package/dist/lib/security/request-forgery/ssrf.js +176 -14
- package/dist/lib/security/rule-descriptions.js +5 -1
- package/dist/lib/security/rule-ids.js +7 -0
- package/dist/lib/security/site-fixes/auth-crypto.js +5 -78
- package/dist/lib/security/site-fixes/exposure.js +21 -3
- package/dist/lib/security/site-fixes/files.js +11 -13
- package/dist/lib/security/site-fixes/frontend-security-fixes.js +2 -2
- package/dist/lib/security/site-fixes/injection.js +17 -4
- package/dist/lib/security/site-fixes/jwt.js +1 -20
- package/dist/lib/security/site-fixes/request-forgery.js +37 -29
- package/dist/lib/security/taint/binding-inputs.js +236 -0
- package/dist/lib/security/taint/filename-guard.js +45 -45
- package/dist/lib/security/taint/guards.js +14 -8
- package/dist/lib/security/taint/index.js +126 -154
- package/dist/lib/security/taint/propagate.js +43 -9
- package/dist/lib/security/taint/record-writes.js +161 -0
- package/dist/lib/security/taint/resolution-cache.js +13 -7
- package/dist/lib/security/taint/sanitizers.js +89 -5
- package/dist/lib/security/taint/trace-nodes.js +61 -0
- package/dist/lib/security/taint/validators.js +89 -9
- package/dist/lib/shared/agent/agent-init.js +2 -1
- package/dist/lib/shared/agent/agent-verify.js +4 -1
- package/dist/lib/shared/agent/git-hook.js +17 -6
- package/dist/lib/shared/agent/review-mcp.js +8 -2
- package/dist/lib/shared/analysis/ast-semantics.js +2 -2
- package/dist/lib/shared/analysis/scan-cache.js +96 -12
- package/dist/lib/shared/cli-dispatch.js +17 -0
- package/dist/lib/shared/config.js +27 -10
- package/dist/lib/shared/explain.js +1 -1
- package/dist/lib/shared/fix/fix-convergence.js +5 -3
- package/dist/lib/shared/fix/fix-imports.js +4 -171
- package/dist/lib/shared/fix/fix-presentation-comments.js +23 -9
- package/dist/lib/shared/fix/fix-presentation.js +5 -3
- package/dist/lib/shared/fix/fix-safety.js +7 -1
- package/dist/lib/shared/fix/fix-typecheck.js +8 -4
- package/dist/lib/shared/fix/import-text-edits.js +148 -0
- package/dist/lib/shared/fix.js +31 -7
- package/dist/lib/shared/formats/finding-location.js +4 -1
- package/dist/lib/shared/formats/github.js +3 -3
- package/dist/lib/shared/formats/sarif.js +9 -3
- package/dist/lib/shared/report-fp.js +6 -2
- package/dist/lib/shared/reporting/baseline.js +7 -5
- package/dist/lib/shared/reporting/pillars.js +9 -3
- package/dist/lib/shared/reporting/source-report.js +1 -0
- package/dist/lib/shared/system/glob.js +34 -8
- package/dist/lib/shared/system/sentry.js +26 -7
- package/dist/lib/shared/workspaces.js +15 -3
- package/package.json +5 -1
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin/hooks/check-edited-file.mjs +27 -5
- package/polyglot/performance/rules/csharp.yml +34 -5
- package/polyglot/performance/rules/java.yml +24 -1
- package/polyglot/performance/rules/python.yml +74 -2
- package/polyglot/performance/sgconfig.yml +1 -0
- package/polyglot/reliability/rules/csharp.yml +12 -6
- package/polyglot/reliability/rules/go.yml +86 -6
- package/polyglot/reliability/rules/java.yml +22 -1
- package/polyglot/reliability/sgconfig.yml +1 -0
- package/polyglot/security/rules/go.yml +100 -22
- package/polyglot/security/rules/python.yml +74 -6
- package/polyglot/security/rules/rust.yml +65 -0
- package/polyglot/security/sgconfig.yml +1 -0
- package/schema/loadwise.config.schema.json +554 -76
- /package/polyglot/{performance/rules → shared-rules}/input.yml +0 -0
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
// Resolves the severity and aliases of OSV advisory records.
|
|
2
|
+
import { fixedVersion } from './fixed-version.js';
|
|
3
|
+
import { cvssScore } from './cvss-score.js';
|
|
1
4
|
const databaseSeverityLevels = {
|
|
2
5
|
CRITICAL: 'critical',
|
|
3
6
|
HIGH: 'high',
|
|
@@ -13,58 +16,6 @@ const cvssBands = [
|
|
|
13
16
|
[4, 'medium'],
|
|
14
17
|
[0.1, 'low'],
|
|
15
18
|
];
|
|
16
|
-
const unknownSeverity = 'medium';
|
|
17
|
-
const attackVector = { N: 0.85, A: 0.62, L: 0.55, P: 0.2 };
|
|
18
|
-
const attackComplexity = { L: 0.77, H: 0.44 };
|
|
19
|
-
const userInteraction = { N: 0.85, R: 0.62 };
|
|
20
|
-
const impactMetric = { H: 0.56, L: 0.22, N: 0 };
|
|
21
|
-
const privilegesUnchanged = { N: 0.85, L: 0.62, H: 0.27 };
|
|
22
|
-
const privilegesChanged = { N: 0.85, L: 0.68, H: 0.5 };
|
|
23
|
-
// The weight of a metric letter, or undefined when the vector lacks the metric or uses an unknown
|
|
24
|
-
// letter.
|
|
25
|
-
function weightOf(weights, letter) {
|
|
26
|
-
return letter === undefined ? undefined : weights[letter];
|
|
27
|
-
}
|
|
28
|
-
function isComplete(weights) {
|
|
29
|
-
return weights.every((weight) => weight !== undefined);
|
|
30
|
-
}
|
|
31
|
-
function roundUp(value) {
|
|
32
|
-
const scaled = Math.round(value * 100000);
|
|
33
|
-
return scaled % 10000 === 0 ? scaled / 100000 : (Math.floor(scaled / 10000) + 1) / 10;
|
|
34
|
-
}
|
|
35
|
-
// CVSS v3.x base score from a vector such as 'CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H'.
|
|
36
|
-
function cvssV3BaseScore(vector) {
|
|
37
|
-
const metrics = Object.fromEntries(vector
|
|
38
|
-
.split('/')
|
|
39
|
-
.slice(1)
|
|
40
|
-
.map((part) => {
|
|
41
|
-
const [metric, value] = part.split(':');
|
|
42
|
-
return [metric, value];
|
|
43
|
-
}));
|
|
44
|
-
const scopeChanged = metrics.S === 'C';
|
|
45
|
-
const privileges = weightOf(scopeChanged ? privilegesChanged : privilegesUnchanged, metrics.PR);
|
|
46
|
-
const parts = [
|
|
47
|
-
weightOf(attackVector, metrics.AV),
|
|
48
|
-
weightOf(attackComplexity, metrics.AC),
|
|
49
|
-
privileges,
|
|
50
|
-
weightOf(userInteraction, metrics.UI),
|
|
51
|
-
];
|
|
52
|
-
const impacts = [
|
|
53
|
-
weightOf(impactMetric, metrics.C),
|
|
54
|
-
weightOf(impactMetric, metrics.I),
|
|
55
|
-
weightOf(impactMetric, metrics.A),
|
|
56
|
-
];
|
|
57
|
-
if (!isComplete(parts) || !isComplete(impacts))
|
|
58
|
-
return undefined;
|
|
59
|
-
const impactSubScore = 1 - impacts.reduce((product, value) => product * (1 - value), 1);
|
|
60
|
-
const impact = scopeChanged
|
|
61
|
-
? 7.52 * (impactSubScore - 0.029) - 3.25 * (impactSubScore - 0.02) ** 15
|
|
62
|
-
: 6.42 * impactSubScore;
|
|
63
|
-
if (impact <= 0)
|
|
64
|
-
return 0;
|
|
65
|
-
const exploitability = 8.22 * parts.reduce((product, value) => product * value, 1);
|
|
66
|
-
return roundUp(Math.min(scopeChanged ? 1.08 * (impact + exploitability) : impact + exploitability, 10));
|
|
67
|
-
}
|
|
68
19
|
function levelForScore(score) {
|
|
69
20
|
return cvssBands.find(([minimum]) => score >= minimum)?.[1];
|
|
70
21
|
}
|
|
@@ -72,71 +23,61 @@ function severityLevel(vulnerability) {
|
|
|
72
23
|
const fromDatabase = databaseSeverityLevels[String(vulnerability.databaseSeverity).toUpperCase()];
|
|
73
24
|
if (fromDatabase)
|
|
74
25
|
return fromDatabase;
|
|
75
|
-
|
|
76
|
-
|
|
26
|
+
if (!Array.isArray(vulnerability.severity))
|
|
27
|
+
return undefined;
|
|
28
|
+
const levels = [];
|
|
29
|
+
for (const entry of vulnerability.severity) {
|
|
30
|
+
if (typeof entry?.score !== 'string' || typeof entry.type !== 'string')
|
|
77
31
|
continue;
|
|
78
|
-
const
|
|
79
|
-
if (
|
|
80
|
-
|
|
32
|
+
const value = cvssScore(entry.type, entry.score);
|
|
33
|
+
if (value !== undefined)
|
|
34
|
+
levels.push(levelForScore(value) ?? 'low');
|
|
81
35
|
}
|
|
82
|
-
return
|
|
36
|
+
return highestSeverity(levels);
|
|
83
37
|
}
|
|
84
38
|
const severityRank = { critical: 3, high: 2, medium: 1, low: 0 };
|
|
85
39
|
function highestSeverity(levels) {
|
|
86
|
-
|
|
87
|
-
return unknownSeverity;
|
|
88
|
-
return levels.reduce((highest, level) => (severityRank[level] > severityRank[highest] ? level : highest));
|
|
40
|
+
return levels.reduce((highest, level) => (level && (!highest || severityRank[level] > severityRank[highest]) ? level : highest), undefined);
|
|
89
41
|
}
|
|
90
|
-
function
|
|
91
|
-
|
|
92
|
-
|
|
42
|
+
function advisoryIds({ id, aliases }) {
|
|
43
|
+
if (!Array.isArray(aliases))
|
|
44
|
+
return [id];
|
|
45
|
+
return [id, ...aliases.filter((alias) => typeof alias === 'string' && alias.trim().length > 0)];
|
|
93
46
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
const
|
|
97
|
-
for (
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
|
|
47
|
+
// Two returned records can share an alias without that alias having its own returned record.
|
|
48
|
+
function advisoryGroups(vulnerabilities) {
|
|
49
|
+
const byId = new Map();
|
|
50
|
+
for (const record of vulnerabilities) {
|
|
51
|
+
for (const id of advisoryIds(record)) {
|
|
52
|
+
const matches = byId.get(id);
|
|
53
|
+
if (matches)
|
|
54
|
+
matches.push(record);
|
|
55
|
+
else
|
|
56
|
+
byId.set(id, [record]);
|
|
57
|
+
}
|
|
101
58
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
function fixedVersion(vulnerabilities, name, version) {
|
|
120
|
-
const fixes = vulnerabilities.map((vulnerability) => lowestFixedVersionOf(vulnerability, name, version));
|
|
121
|
-
const known = fixes.filter((fix) => fix !== undefined);
|
|
122
|
-
if (!known.length || known.length < fixes.length)
|
|
123
|
-
return undefined;
|
|
124
|
-
return known.reduce((highest, fix) => (compareVersions(fix, highest) > 0 ? fix : highest));
|
|
125
|
-
}
|
|
126
|
-
// When one advisory lists another's id as an alias (a GHSA and its CVE), only one is reported.
|
|
127
|
-
function withoutAliasDuplicates(vulnerabilities) {
|
|
128
|
-
const ids = new Set(vulnerabilities.map(({ id }) => id));
|
|
129
|
-
const sorted = [...vulnerabilities].sort((left, right) => Number(right.id.startsWith('GHSA-')) - Number(left.id.startsWith('GHSA-')));
|
|
130
|
-
const kept = [];
|
|
131
|
-
const covered = new Set();
|
|
132
|
-
for (const vulnerability of sorted) {
|
|
133
|
-
if (covered.has(vulnerability.id))
|
|
59
|
+
function takeGroup(first) {
|
|
60
|
+
const members = new Set([first]);
|
|
61
|
+
for (const member of members) {
|
|
62
|
+
for (const id of advisoryIds(member)) {
|
|
63
|
+
const matches = byId.get(id);
|
|
64
|
+
if (!matches)
|
|
65
|
+
continue;
|
|
66
|
+
byId.delete(id);
|
|
67
|
+
for (const match of matches)
|
|
68
|
+
members.add(match);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return [...members];
|
|
72
|
+
}
|
|
73
|
+
const groups = [];
|
|
74
|
+
for (const record of vulnerabilities) {
|
|
75
|
+
if (!byId.has(record.id))
|
|
134
76
|
continue;
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
covered.add(alias);
|
|
77
|
+
const group = takeGroup(record);
|
|
78
|
+
group.sort((left, right) => Number(right.id.startsWith('GHSA-')) - Number(left.id.startsWith('GHSA-')) || left.id.localeCompare(right.id));
|
|
79
|
+
groups.push(group);
|
|
139
80
|
}
|
|
140
|
-
return
|
|
81
|
+
return groups.sort((left, right) => left[0].id.localeCompare(right[0].id));
|
|
141
82
|
}
|
|
142
|
-
export { severityLevel, highestSeverity, fixedVersion,
|
|
83
|
+
export { severityLevel, highestSeverity, fixedVersion, advisoryGroups };
|
|
@@ -11,7 +11,7 @@ import { printResult } from '../../shared/reporting/source-report.js';
|
|
|
11
11
|
const usage = `Usage:
|
|
12
12
|
loadwise sec deps --online [directory] [--format text|json] [--json] [--include-contextual] [--ignore rule-id] [--fail-on all|contract] [--min-impact low|medium|high|critical] [--baseline [file] | --write-baseline [file]]
|
|
13
13
|
|
|
14
|
-
Reads package-lock.json, pnpm-lock.yaml or yarn.lock from the directory (default: the current folder) or the nearest parent that has one.
|
|
14
|
+
Reads npm-shrinkwrap.json, package-lock.json, pnpm-lock.yaml or yarn.lock from the directory (default: the current folder) or the nearest parent that has one.
|
|
15
15
|
--online is required: it sends the package names and versions in the lockfile, and nothing else, to the OSV vulnerability database (api.osv.dev, which includes the GitHub Advisory Database). Answers are cached for 24 hours in the loadwise folder of the OS cache directory.
|
|
16
16
|
Development-only dependencies are contextual and reported with --include-contextual.
|
|
17
17
|
A network failure exits 2; it is never reported as a pass.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { CVSS } from '@turingpointde/cvss.js';
|
|
2
|
+
// OSV's declared severity type and the vector must describe the same CVSS version.
|
|
3
|
+
export function cvssScore(type, vector) {
|
|
4
|
+
const v3 = type === 'CVSS_V3' && /^CVSS:3\.[01]\//.test(vector);
|
|
5
|
+
const v4 = type === 'CVSS_V4' && vector.startsWith('CVSS:4.0/');
|
|
6
|
+
if (!v3 && !v4)
|
|
7
|
+
return undefined;
|
|
8
|
+
try {
|
|
9
|
+
return CVSS(vector).getScore();
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import semver from 'semver';
|
|
2
|
+
function readTimeline(range) {
|
|
3
|
+
if (!range || !['SEMVER', 'ECOSYSTEM'].includes(range.type) || !Array.isArray(range.events))
|
|
4
|
+
return;
|
|
5
|
+
const boundaries = [];
|
|
6
|
+
const limits = [];
|
|
7
|
+
for (const event of range.events) {
|
|
8
|
+
if (!event || Object.keys(event).length !== 1)
|
|
9
|
+
return;
|
|
10
|
+
if (event.limit !== undefined) {
|
|
11
|
+
if (event.limit !== '*' && !semver.valid(event.limit))
|
|
12
|
+
return;
|
|
13
|
+
limits.push(event.limit);
|
|
14
|
+
continue;
|
|
15
|
+
}
|
|
16
|
+
const kind = ['introduced', 'fixed', 'last_affected'].find((key) => event[key] !== undefined);
|
|
17
|
+
if (!kind)
|
|
18
|
+
return;
|
|
19
|
+
const version = event[kind];
|
|
20
|
+
if (typeof version !== 'string' || (!(kind === 'introduced' && version === '0') && !semver.valid(version)))
|
|
21
|
+
return;
|
|
22
|
+
boundaries.push({ kind, version });
|
|
23
|
+
}
|
|
24
|
+
if (!boundaries.some(({ kind }) => kind === 'introduced'))
|
|
25
|
+
return;
|
|
26
|
+
if (boundaries.some(({ kind }) => kind === 'fixed') && boundaries.some(({ kind }) => kind === 'last_affected'))
|
|
27
|
+
return;
|
|
28
|
+
boundaries.sort((left, right) => {
|
|
29
|
+
if (left.version === '0' || right.version === '0')
|
|
30
|
+
return Number(right.version === '0') - Number(left.version === '0');
|
|
31
|
+
// A reintroduction at the same boundary keeps that release affected.
|
|
32
|
+
return (semver.compare(left.version, right.version) ||
|
|
33
|
+
Number(left.kind === 'introduced') - Number(right.kind === 'introduced'));
|
|
34
|
+
});
|
|
35
|
+
return { boundaries, limits };
|
|
36
|
+
}
|
|
37
|
+
// OSV's limit events bound the entire timeline; last_affected includes its endpoint, fixed excludes it.
|
|
38
|
+
function affectsVersion({ boundaries, limits }, candidate) {
|
|
39
|
+
if (limits.length && !limits.some((limit) => limit === '*' || semver.lt(candidate, limit)))
|
|
40
|
+
return false;
|
|
41
|
+
let affected = false;
|
|
42
|
+
for (const { kind, version } of boundaries) {
|
|
43
|
+
const order = version === '0' ? 1 : semver.compare(candidate, version);
|
|
44
|
+
if (order < 0)
|
|
45
|
+
break;
|
|
46
|
+
if (kind !== 'last_affected' || order > 0)
|
|
47
|
+
affected = kind === 'introduced';
|
|
48
|
+
}
|
|
49
|
+
return affected;
|
|
50
|
+
}
|
|
51
|
+
function upgradeBoundaries(timeline, installed) {
|
|
52
|
+
return timeline.boundaries
|
|
53
|
+
.filter(({ kind, version }) => kind === 'fixed' && semver.gt(version, installed))
|
|
54
|
+
.map(({ version }) => version.trim());
|
|
55
|
+
}
|
|
56
|
+
function fixedVersion(vulnerabilities, name, installed) {
|
|
57
|
+
if (!semver.valid(installed))
|
|
58
|
+
return;
|
|
59
|
+
const candidates = new Set();
|
|
60
|
+
const timelines = [];
|
|
61
|
+
const affectedVersions = new Set();
|
|
62
|
+
const affectedPackages = [];
|
|
63
|
+
for (const advisory of vulnerabilities) {
|
|
64
|
+
if (!Array.isArray(advisory.affected))
|
|
65
|
+
return;
|
|
66
|
+
const entries = advisory.affected.filter((entry) => entry?.name === name);
|
|
67
|
+
if (!entries.length)
|
|
68
|
+
return;
|
|
69
|
+
affectedPackages.push(...entries);
|
|
70
|
+
}
|
|
71
|
+
for (const { ranges, versions } of affectedPackages) {
|
|
72
|
+
// Older cached records did not retain explicit affected versions. Keep reporting the advisory until refresh.
|
|
73
|
+
if (!Array.isArray(versions) || !Array.isArray(ranges))
|
|
74
|
+
return;
|
|
75
|
+
if (!ranges.length && !versions.length)
|
|
76
|
+
return;
|
|
77
|
+
for (const version of versions) {
|
|
78
|
+
const normalized = semver.valid(version);
|
|
79
|
+
if (!normalized)
|
|
80
|
+
return;
|
|
81
|
+
affectedVersions.add(normalized);
|
|
82
|
+
}
|
|
83
|
+
for (const range of ranges) {
|
|
84
|
+
const timeline = readTimeline(range);
|
|
85
|
+
if (!timeline)
|
|
86
|
+
return;
|
|
87
|
+
timelines.push(timeline);
|
|
88
|
+
for (const candidate of upgradeBoundaries(timeline, installed))
|
|
89
|
+
candidates.add(candidate);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return [...candidates]
|
|
93
|
+
.sort(semver.compare)
|
|
94
|
+
.find((candidate) => !affectedVersions.has(new semver.SemVer(candidate).version) &&
|
|
95
|
+
!timelines.some((timeline) => affectsVersion(timeline, candidate)));
|
|
96
|
+
}
|
|
97
|
+
export { fixedVersion };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Reads the packages a lockfile pins: [{ name, version, direct, dev, line,
|
|
1
|
+
// Reads the packages a lockfile pins: [{ name, version, direct, dev, line, declarations }]
|
|
2
2
|
// with one entry per name@version. `dev` is true only when every occurrence is development-only, as
|
|
3
3
|
// far as the lockfile says.
|
|
4
4
|
import fs from 'node:fs';
|
|
@@ -6,7 +6,9 @@ import os from 'node:os';
|
|
|
6
6
|
import path from 'node:path';
|
|
7
7
|
import { noteUnreadable } from '../../shared/reporting/coverage-notes.js';
|
|
8
8
|
import { isTempRoot, safeExists } from '../../shared/project-root.js';
|
|
9
|
+
import { yarnPackages } from './yarn-lock.js';
|
|
9
10
|
const lockfileKinds = [
|
|
11
|
+
{ file: 'npm-shrinkwrap.json', manager: 'npm', parse: parsePackageLock },
|
|
10
12
|
{ file: 'package-lock.json', manager: 'npm', parse: parsePackageLock },
|
|
11
13
|
{ file: 'pnpm-lock.yaml', manager: 'pnpm', parse: parsePnpmLock },
|
|
12
14
|
{ file: 'yarn.lock', manager: 'yarn', parse: parseYarnLock },
|
|
@@ -17,7 +19,6 @@ const manifestDependencyFields = [
|
|
|
17
19
|
'optionalDependencies',
|
|
18
20
|
'peerDependencies',
|
|
19
21
|
];
|
|
20
|
-
const productionFields = ['dependencies', 'optionalDependencies', 'peerDependencies'];
|
|
21
22
|
// Versions that are not registry releases cannot be looked up in the advisory database.
|
|
22
23
|
const nonRegistryVersion = /^(?:link|file|workspace|portal|patch|git|github|https?):/;
|
|
23
24
|
// The nearest folder at or above `directory` that holds a lockfile, so a package inside a monorepo
|
|
@@ -70,16 +71,20 @@ function readManifest(directory) {
|
|
|
70
71
|
function manifestNames(manifest, fields) {
|
|
71
72
|
return new Set(fields.flatMap((field) => Object.keys(manifest?.[field] ?? {})));
|
|
72
73
|
}
|
|
73
|
-
function addPackage(packages,
|
|
74
|
+
function addPackage(packages, entry) {
|
|
75
|
+
const { name, version, direct, dev } = entry;
|
|
74
76
|
const key = `${name}@${version}`;
|
|
75
77
|
const known = packages.get(key);
|
|
76
78
|
if (!known) {
|
|
77
|
-
packages.set(key,
|
|
79
|
+
packages.set(key, entry);
|
|
78
80
|
return;
|
|
79
81
|
}
|
|
80
82
|
known.dev = known.dev && dev;
|
|
81
|
-
if (
|
|
82
|
-
known.
|
|
83
|
+
if (known.patched || entry.patched)
|
|
84
|
+
known.patched = Boolean(known.patched && entry.patched);
|
|
85
|
+
// Peer variants in a pnpm lockfile share one importer declaration list.
|
|
86
|
+
if (known.declarations !== entry.declarations)
|
|
87
|
+
known.declarations = known.declarations.concat(entry.declarations);
|
|
83
88
|
known.direct = known.direct || direct;
|
|
84
89
|
}
|
|
85
90
|
function lineIndex(text, pattern) {
|
|
@@ -91,34 +96,117 @@ function lineIndex(text, pattern) {
|
|
|
91
96
|
});
|
|
92
97
|
return lines;
|
|
93
98
|
}
|
|
94
|
-
function
|
|
99
|
+
function npmDependencyLocation(entries, directory, name) {
|
|
100
|
+
for (let parent = directory || '.';; parent = path.posix.dirname(parent)) {
|
|
101
|
+
const location = path.posix.join(parent, 'node_modules', name);
|
|
102
|
+
if (Object.hasOwn(entries, location))
|
|
103
|
+
return location;
|
|
104
|
+
if (parent === '.' || parent === path.posix.dirname(parent))
|
|
105
|
+
return undefined;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
// Resolve declarations from each project manifest to the nearest installed copy, including hoists.
|
|
109
|
+
function npmManifestOwners(entries, root) {
|
|
110
|
+
const owners = new Map();
|
|
111
|
+
for (const [directory, manifest] of Object.entries(entries)) {
|
|
112
|
+
if (directory && directory.split('/').some((part) => !part || part === '..' || part === 'node_modules'))
|
|
113
|
+
continue;
|
|
114
|
+
const absolute = path.resolve(root, directory);
|
|
115
|
+
const relative = path.relative(root, absolute);
|
|
116
|
+
if (relative.startsWith('..' + path.sep) || relative === '..' || path.isAbsolute(relative))
|
|
117
|
+
continue;
|
|
118
|
+
for (const name of manifestNames(manifest, manifestDependencyFields)) {
|
|
119
|
+
const location = npmDependencyLocation(entries, directory, name);
|
|
120
|
+
if (!location)
|
|
121
|
+
continue;
|
|
122
|
+
const directories = owners.get(location) ?? [];
|
|
123
|
+
directories.push(absolute);
|
|
124
|
+
owners.set(location, directories);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return owners;
|
|
128
|
+
}
|
|
129
|
+
function parsePackageLock(text, { root, filename }) {
|
|
95
130
|
const lock = JSON.parse(text);
|
|
96
|
-
if (!lock.packages)
|
|
97
|
-
throw new Error(
|
|
98
|
-
const lines = lineIndex(text, /^\s*"(node_modules\/[^"]+)":\s*\{/);
|
|
99
|
-
const
|
|
100
|
-
const directNames = manifestNames(rootManifest, manifestDependencyFields);
|
|
131
|
+
if (!lock.packages || ![2, 3].includes(lock.lockfileVersion ?? 0))
|
|
132
|
+
throw new Error(`${path.basename(filename)} lockfileVersion ${lock.lockfileVersion ?? 'unknown'} is not supported; use npm lockfile version 2 or 3.`);
|
|
133
|
+
const lines = lineIndex(text, /^\s*"((?:[^"]+\/)?node_modules\/[^"]+)":\s*\{/);
|
|
134
|
+
const owners = npmManifestOwners(lock.packages, root);
|
|
101
135
|
const packages = new Map();
|
|
102
136
|
for (const [location, entry] of Object.entries(lock.packages)) {
|
|
103
|
-
const
|
|
104
|
-
if (!
|
|
137
|
+
const installed = /(?:^|\/)node_modules\/((?:@[^/]+\/)?[^/]+)$/.exec(location);
|
|
138
|
+
if (!installed || entry.link || !entry.version)
|
|
105
139
|
continue;
|
|
106
|
-
const name = entry.name ??
|
|
107
|
-
const
|
|
140
|
+
const name = entry.name ?? installed[1];
|
|
141
|
+
const manifestDirectories = owners.get(location) ?? [];
|
|
108
142
|
addPackage(packages, {
|
|
109
143
|
name,
|
|
110
144
|
version: entry.version,
|
|
111
|
-
direct,
|
|
145
|
+
direct: manifestDirectories.length > 0,
|
|
112
146
|
dev: entry.dev === true,
|
|
113
147
|
line: lines.get(location) ?? 1,
|
|
114
|
-
manifestDirectories: [
|
|
148
|
+
declarations: manifestDirectories.map((directory) => ({ directory, name: installed[1] })),
|
|
115
149
|
});
|
|
116
150
|
}
|
|
117
151
|
return [...packages.values()];
|
|
118
152
|
}
|
|
153
|
+
function splitFlowEntries(text) {
|
|
154
|
+
const entries = [];
|
|
155
|
+
let start = 0;
|
|
156
|
+
let depth = 0;
|
|
157
|
+
let quote;
|
|
158
|
+
for (let index = 0; index < text.length; index++) {
|
|
159
|
+
const ch = text[index];
|
|
160
|
+
if (quote) {
|
|
161
|
+
if (ch === '\\' && quote === '"')
|
|
162
|
+
index++;
|
|
163
|
+
else if (ch === quote)
|
|
164
|
+
quote = undefined;
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
if (ch === "'" || ch === '"') {
|
|
168
|
+
quote = ch;
|
|
169
|
+
}
|
|
170
|
+
else if (ch === '{' || ch === '[') {
|
|
171
|
+
depth++;
|
|
172
|
+
}
|
|
173
|
+
else if (ch === '}' || ch === ']') {
|
|
174
|
+
depth = Math.max(0, depth - 1);
|
|
175
|
+
}
|
|
176
|
+
else if (ch === ',' && depth === 0) {
|
|
177
|
+
entries.push(text.slice(start, index));
|
|
178
|
+
start = index + 1;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
entries.push(text.slice(start));
|
|
182
|
+
return entries;
|
|
183
|
+
}
|
|
184
|
+
function populateFlowMap(node, rawValue, indent, line) {
|
|
185
|
+
const inner = rawValue.slice(1, -1).trim();
|
|
186
|
+
if (!inner)
|
|
187
|
+
return;
|
|
188
|
+
for (const part of splitFlowEntries(inner)) {
|
|
189
|
+
const colon = part.indexOf(':');
|
|
190
|
+
if (colon === -1)
|
|
191
|
+
continue;
|
|
192
|
+
const rawKey = part.slice(0, colon).trim();
|
|
193
|
+
const key = unquote(rawKey);
|
|
194
|
+
const val = part.slice(colon + 1).trim();
|
|
195
|
+
if (!key)
|
|
196
|
+
continue;
|
|
197
|
+
const child = {
|
|
198
|
+
children: new Map(),
|
|
199
|
+
indent: indent + 2,
|
|
200
|
+
line,
|
|
201
|
+
value: val ? unquote(val) : undefined,
|
|
202
|
+
};
|
|
203
|
+
if (val.startsWith('{') && val.endsWith('}'))
|
|
204
|
+
populateFlowMap(child, val, indent + 2, line);
|
|
205
|
+
node.children.set(key, child);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
119
208
|
// A minimal reader for the block-style YAML of a pnpm lockfile: nested maps with plain or quoted
|
|
120
|
-
// keys
|
|
121
|
-
// since only the structure is needed.
|
|
209
|
+
// keys, plus inline YAML flow maps (`{ k: v }`).
|
|
122
210
|
function parseYamlMaps(text) {
|
|
123
211
|
const rootNode = { children: new Map(), indent: -1, line: 0, value: undefined };
|
|
124
212
|
const stack = [rootNode];
|
|
@@ -141,6 +229,9 @@ function parseYamlMaps(text) {
|
|
|
141
229
|
line: index + 1,
|
|
142
230
|
value: rawValue ? unquote(rawValue) : undefined,
|
|
143
231
|
};
|
|
232
|
+
if (rawValue && rawValue.startsWith('{') && rawValue.endsWith('}')) {
|
|
233
|
+
populateFlowMap(node, rawValue, indent, index + 1);
|
|
234
|
+
}
|
|
144
235
|
stack.at(-1)?.children.set(key, node);
|
|
145
236
|
stack.push(node);
|
|
146
237
|
});
|
|
@@ -188,7 +279,7 @@ function pnpmProductionKeys(lock, importers) {
|
|
|
188
279
|
for (const { node } of importers) {
|
|
189
280
|
for (const { name, version, field } of importerDependencies(node)) {
|
|
190
281
|
if (field !== 'devDependencies')
|
|
191
|
-
pending.push(
|
|
282
|
+
pending.push(pnpmReference(name, version));
|
|
192
283
|
}
|
|
193
284
|
}
|
|
194
285
|
for (let key = pending.pop(); key !== undefined; key = pending.pop()) {
|
|
@@ -205,18 +296,26 @@ function pnpmProductionKeys(lock, importers) {
|
|
|
205
296
|
function queuePnpmDependencies(snapshot, field, pending) {
|
|
206
297
|
for (const [name, node] of snapshot?.children.get(field)?.children ?? []) {
|
|
207
298
|
if (node.value)
|
|
208
|
-
pending.push(
|
|
299
|
+
pending.push(pnpmReference(name, node.value));
|
|
209
300
|
}
|
|
210
301
|
}
|
|
302
|
+
function pnpmReference(name, version) {
|
|
303
|
+
const reference = version.replace(/^npm:/, '');
|
|
304
|
+
return splitPnpmKey(reference) ? reference.replace(/^\//, '') : `${name}@${reference}`;
|
|
305
|
+
}
|
|
211
306
|
function parsePnpmLock(text, { root }) {
|
|
212
307
|
const lock = parseYamlMaps(text);
|
|
213
308
|
const importers = pnpmImporters(lock);
|
|
214
|
-
const
|
|
309
|
+
const declarations = new Map();
|
|
215
310
|
for (const { importer, node } of importers) {
|
|
216
|
-
for (const { name } of importerDependencies(node)) {
|
|
217
|
-
const
|
|
218
|
-
|
|
219
|
-
|
|
311
|
+
for (const { name, version } of importerDependencies(node)) {
|
|
312
|
+
const parsed = splitPnpmKey(pnpmReference(name, version));
|
|
313
|
+
if (!parsed)
|
|
314
|
+
continue;
|
|
315
|
+
const key = `${parsed.name}@${parsed.version}`;
|
|
316
|
+
const declaration = declarations.get(key) ?? [];
|
|
317
|
+
declaration.push({ directory: path.join(root, importer), name });
|
|
318
|
+
declarations.set(key, declaration);
|
|
220
319
|
}
|
|
221
320
|
}
|
|
222
321
|
const productionKeys = pnpmProductionKeys(lock, importers);
|
|
@@ -229,70 +328,32 @@ function parsePnpmLock(text, { root }) {
|
|
|
229
328
|
const dev = productionKeys
|
|
230
329
|
? !productionVersions.has(`${parsed.name}@${parsed.version}`)
|
|
231
330
|
: node.children.get('dev')?.value === 'true';
|
|
331
|
+
const declaration = declarations.get(`${parsed.name}@${parsed.version}`);
|
|
232
332
|
addPackage(packages, {
|
|
233
333
|
...parsed,
|
|
234
|
-
direct:
|
|
334
|
+
direct: Boolean(declaration),
|
|
235
335
|
dev,
|
|
236
336
|
line: node.line,
|
|
237
|
-
|
|
337
|
+
declarations: declaration ?? [],
|
|
238
338
|
});
|
|
239
339
|
}
|
|
240
340
|
return [...packages.values()];
|
|
241
341
|
}
|
|
242
|
-
// yarn v1 headers read `name@^1.0.0", name@^1.2.0:`; berry's read `"name@npm:^1.0.0":`. Both give
|
|
243
|
-
// the resolved version on a `version` line inside the block.
|
|
244
342
|
function parseYarnLock(text, { root }) {
|
|
245
|
-
const manifest = readManifest(root);
|
|
246
|
-
const directNames = manifestNames(manifest, manifestDependencyFields);
|
|
247
|
-
const productionNames = manifestNames(manifest, productionFields);
|
|
248
343
|
const packages = new Map();
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
if (/^\S.*:$/.test(lineText) && !lineText.startsWith('#')) {
|
|
252
|
-
header = {
|
|
253
|
-
specifiers: lineText
|
|
254
|
-
.slice(0, -1)
|
|
255
|
-
.split(',')
|
|
256
|
-
.map((part) => unquote(part.trim())),
|
|
257
|
-
line: index + 1,
|
|
258
|
-
};
|
|
259
|
-
return;
|
|
260
|
-
}
|
|
261
|
-
if (!header)
|
|
262
|
-
return;
|
|
263
|
-
const versionMatch = /^ {2}version:? "?([^"\s]+)"?$/.exec(lineText);
|
|
264
|
-
if (!versionMatch)
|
|
265
|
-
return;
|
|
266
|
-
const [firstSpecifier] = header.specifiers;
|
|
267
|
-
const { line: headerLine } = header;
|
|
268
|
-
const nameEnd = firstSpecifier.indexOf('@', 1);
|
|
269
|
-
if (nameEnd < 0)
|
|
270
|
-
return;
|
|
271
|
-
const name = firstSpecifier.slice(0, nameEnd);
|
|
272
|
-
const specifierRange = firstSpecifier.slice(name.length + 1);
|
|
273
|
-
header = undefined;
|
|
274
|
-
if (nonRegistryVersion.test(specifierRange.replace(/^npm:/, '')))
|
|
275
|
-
return;
|
|
276
|
-
addPackage(packages, {
|
|
277
|
-
name,
|
|
278
|
-
version: versionMatch[1],
|
|
279
|
-
direct: directNames.has(name),
|
|
280
|
-
dev: directNames.has(name) && !productionNames.has(name),
|
|
281
|
-
line: headerLine,
|
|
282
|
-
manifestDirectories: [root],
|
|
283
|
-
});
|
|
284
|
-
});
|
|
344
|
+
for (const entry of yarnPackages(text, root, readManifest(root)))
|
|
345
|
+
addPackage(packages, entry);
|
|
285
346
|
return [...packages.values()];
|
|
286
347
|
}
|
|
287
348
|
function readLockfilePackages(lockfile) {
|
|
288
349
|
const text = fs.readFileSync(lockfile.filename, 'utf8');
|
|
289
|
-
return lockfile.parse(text, { root: lockfile.root });
|
|
350
|
+
return lockfile.parse(text, { root: lockfile.root, filename: lockfile.filename });
|
|
290
351
|
}
|
|
291
352
|
// The 1-based line of `"name":` in the package.json files that declare the dependency, or
|
|
292
353
|
// undefined.
|
|
293
|
-
function manifestLocation(
|
|
294
|
-
const
|
|
295
|
-
|
|
354
|
+
function manifestLocation(declarations) {
|
|
355
|
+
for (const { name, directory } of declarations) {
|
|
356
|
+
const needle = JSON.stringify(name);
|
|
296
357
|
const filename = path.join(directory, 'package.json');
|
|
297
358
|
let lines;
|
|
298
359
|
try {
|
|
@@ -32,10 +32,10 @@ function configuredOrigin() {
|
|
|
32
32
|
function defaultCacheDirectory() {
|
|
33
33
|
const home = os.homedir();
|
|
34
34
|
const base = process.platform === 'win32'
|
|
35
|
-
?
|
|
35
|
+
? process.env.LOCALAPPDATA || path.join(home, 'AppData', 'Local')
|
|
36
36
|
: process.platform === 'darwin'
|
|
37
37
|
? path.join(home, 'Library', 'Caches')
|
|
38
|
-
:
|
|
38
|
+
: process.env.XDG_CACHE_HOME || path.join(home, '.cache');
|
|
39
39
|
return path.join(base, 'loadwise');
|
|
40
40
|
}
|
|
41
41
|
function readCache(cacheDirectory, now) {
|
|
@@ -122,7 +122,15 @@ function summarizeVulnerability(vulnerability) {
|
|
|
122
122
|
withdrawn: Boolean(vulnerability.withdrawn),
|
|
123
123
|
severity: vulnerability.severity ?? [],
|
|
124
124
|
databaseSeverity: vulnerability.database_specific?.severity,
|
|
125
|
-
affected: (vulnerability.affected ?? []).flatMap(({ package: affectedPackage, ranges }) => affectedPackage?.ecosystem === 'npm'
|
|
125
|
+
affected: (vulnerability.affected ?? []).flatMap(({ package: affectedPackage, ranges, versions }) => affectedPackage?.ecosystem === 'npm'
|
|
126
|
+
? [
|
|
127
|
+
{
|
|
128
|
+
name: affectedPackage.name,
|
|
129
|
+
ranges: ranges === undefined ? [] : ranges,
|
|
130
|
+
versions: versions === undefined ? [] : versions,
|
|
131
|
+
},
|
|
132
|
+
]
|
|
133
|
+
: []),
|
|
126
134
|
};
|
|
127
135
|
}
|
|
128
136
|
async function requestBatch(fetchImpl, origin, queries) {
|