Repository navigation
feat(deps): add SBOM risk report - #71005
Conversation
🔒 Aisle Security AnalysisWe found 3 potential security issue(s) in this PR:
1. 🟡 Unbounded lockfile dependency-graph traversal can cause DoS in sbom-risk-report
DescriptionThe
This can lead to excessive CPU and memory usage (CI job timeouts or runner exhaustion) on large or malicious lockfiles. RecommendationAdd explicit resource limits and avoid quadratic queue operations. 1) Use an index-based queue (O(1) pop) and cap traversal: function collectClosure(lockfile, rootKeys, { maxNodes = 50_000, maxMissing = 5_000 } = {}) {
const seen = new Set();
const missing = new Set();
const queue = [...rootKeys].filter(Boolean);
for (let i = 0; i < queue.length; i++) {
if (seen.size >= maxNodes) break;
const key = queue[i];
if (seen.has(key)) continue;
seen.add(key);
const snapshot = lockfile.snapshots?.[key];
if (!snapshot) {
if (missing.size < maxMissing) missing.add(key);
continue;
}
for (const dep of dependencyEntriesFromSnapshot(snapshot)) {
const depKey = lockKeyForDependency(dep.name, dep.version);
if (depKey && !seen.has(depKey)) queue.push(depKey);
}
}
return {
truncated: seen.size >= maxNodes,
missing: [...missing].toSorted(compareStrings),
packageKeys: [...seen].toSorted(compareStrings),
};
}2) Reduce amplification: compute closure once for all roots, or memoize closures per key (or reuse a single traversal from all roots) rather than running a full traversal for every root dependency. 3) Consider upfront validation: reject/short-circuit processing when lockfile size or snapshot/package counts exceed a safe threshold for your CI environment. 2. 🟡 Unbounded repository file scan and full-file reads can allow CI denial of service
DescriptionThe dependency ownership audit used by If this script is executed in CI for untrusted pull requests, an attacker can cause resource exhaustion by committing:
This can significantly increase runtime and memory usage (the scan is synchronous and single-threaded), potentially causing CI job timeouts or runner instability. Vulnerable behavior:
RecommendationAdd guardrails to make the scan safe for untrusted inputs and large trees:
Example mitigation (size + count caps): const MAX_FILE_BYTES = 512 * 1024; // 512KB
const MAX_FILES = 20_000;
function safeReadUtf8(filePath) {
const st = fs.statSync(filePath, { throwIfNoEntry: false });
if (!st || !st.isFile() || st.size > MAX_FILE_BYTES) return null;
return fs.readFileSync(filePath, "utf8");
}
// when walking
if (files.length >= MAX_FILES) break;
// when reading
const source = safeReadUtf8(filePath);
if (source == null) continue;This limits worst-case CI impact while still providing useful audit output. 3. 🔵 Terminal/CI log escape injection via unsanitized dependency metadata in sbom-risk-report
Description
If this script is executed in CI on untrusted PRs (or locally on untrusted branches), an attacker can modify inputs such as:
to include ANSI escape sequences or other terminal control characters. This can enable terminal escape injection / log spoofing, potentially hiding failures, forging success messages, or misleading reviewers by altering CI log rendering. Vulnerable code examples: console.log(`- ${warning.name}: ${warning.message} (${warning.sourceSections.join(",")})`);
console.log(`- ${dependency.name}: closure=${dependency.closureSize} owner=${owner} class=${dependency.class ?? "-"}`);
console.error(`[sbom-risk] ${error}`);
console.log(`- ${importer.importer}: closure=${importer.closureSize} direct=${importer.directDependencyCount}`);RecommendationNeutralize terminal control characters before writing attacker-influenced strings to stdout/stderr. A simple mitigation is to strip ANSI escape sequences and other control characters from values before interpolating them into log lines: function sanitizeForTerminal(value) {
const s = String(value ?? "");
// Strip ANSI escape sequences
const noAnsi = s.replace(/\u001B\[[0-9;]*[A-Za-z]/g, "");
// Strip other C0 control chars except \n and \t
return noAnsi.replace(/[\u0000-\u0008\u000B\u000C\u000E-\u001F\u007F]/g, "");
}
console.log(`- ${sanitizeForTerminal(dependency.name)}: closure=${dependency.closureSize} owner=${sanitizeForTerminal(owner)} class=${sanitizeForTerminal(dependency.class ?? "-")}`);Alternatively, for machine consumption prefer Analyzed PR: #71005 at commit Last updated on: 2026-04-24T16:00:27Z |
Greptile SummaryThis PR adds a new Confidence Score: 5/5Safe to merge — all findings are minor P2 suggestions that do not affect current runtime correctness. All three findings are P2 style/design improvements (double traversal, hardcoded path in error message, stale records not checked). None affect existing functionality or the default execution path. No files require special attention. Prompt To Fix All With AIThis is a comment left during a code review.
Path: scripts/sbom-risk-report.mjs
Line: 214-219
Comment:
**Double traversal of build-risk packages**
`collectBuildRiskPackages(lockfile)` is called twice in the same return statement — once to get `.length` for the summary, and again to get the `.slice(0, 50)` list. On large lockfiles this traverses all packages entries twice. Compute it once before the `return`.
How can I resolve this? If you propose a fix, please make it concise.
---
This is a comment left during a code review.
Path: scripts/sbom-risk-report.mjs
Line: 233-237
Comment:
**Error message always references default ownership path**
`collectSbomRiskCheckErrors` is a pure function that takes only `report`, but its error text is hard-wired to `DEFAULT_OWNERSHIP_PATH`. When `collectSbomRiskReport` is called with a custom `ownershipPath` parameter (e.g. in tests or future tooling), the reported path will be wrong — pointing to `scripts/lib/dependency-ownership.json` even though a different file was actually used. Consider including the resolved path in the returned report so error messages stay accurate, or accept the path as a parameter.
How can I resolve this? If you propose a fix, please make it concise.
---
This is a comment left during a code review.
Path: scripts/sbom-risk-report.mjs
Line: 188-190
Comment:
**Stale ownership records not surfaced by `--check`**
`staleOwnershipRecords` is computed and included in the JSON output, but `collectSbomRiskCheckErrors` only checks `ownershipGaps`. Over time, entries whose packages have been removed from `package.json` will silently accumulate in `dependency-ownership.json` without causing a `pnpm deps:sbom-risk:check` failure. If the intent is to keep the file tidy, consider surfacing stale records as check errors too.
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "feat(deps): add sbom risk report" | Re-trigger Greptile |
| buildRiskPackageCount: collectBuildRiskPackages(lockfile).length, | ||
| }, | ||
| ownershipGaps, | ||
| staleOwnershipRecords, | ||
| ownershipWarnings, | ||
| buildRiskPackages: collectBuildRiskPackages(lockfile).slice(0, 50), |
There was a problem hiding this comment.
Double traversal of build-risk packages
collectBuildRiskPackages(lockfile) is called twice in the same return statement — once to get .length for the summary, and again to get the .slice(0, 50) list. On large lockfiles this traverses all packages entries twice. Compute it once before the return.
Prompt To Fix With AI
This is a comment left during a code review.
Path: scripts/sbom-risk-report.mjs
Line: 214-219
Comment:
**Double traversal of build-risk packages**
`collectBuildRiskPackages(lockfile)` is called twice in the same return statement — once to get `.length` for the summary, and again to get the `.slice(0, 50)` list. On large lockfiles this traverses all packages entries twice. Compute it once before the `return`.
How can I resolve this? If you propose a fix, please make it concise.| export function collectSbomRiskCheckErrors(report) { | ||
| return report.ownershipGaps.map( | ||
| (name) => `root dependency '${name}' is missing from ${DEFAULT_OWNERSHIP_PATH}`, | ||
| ); | ||
| } |
There was a problem hiding this comment.
Error message always references default ownership path
collectSbomRiskCheckErrors is a pure function that takes only report, but its error text is hard-wired to DEFAULT_OWNERSHIP_PATH. When collectSbomRiskReport is called with a custom ownershipPath parameter (e.g. in tests or future tooling), the reported path will be wrong — pointing to scripts/lib/dependency-ownership.json even though a different file was actually used. Consider including the resolved path in the returned report so error messages stay accurate, or accept the path as a parameter.
Prompt To Fix With AI
This is a comment left during a code review.
Path: scripts/sbom-risk-report.mjs
Line: 233-237
Comment:
**Error message always references default ownership path**
`collectSbomRiskCheckErrors` is a pure function that takes only `report`, but its error text is hard-wired to `DEFAULT_OWNERSHIP_PATH`. When `collectSbomRiskReport` is called with a custom `ownershipPath` parameter (e.g. in tests or future tooling), the reported path will be wrong — pointing to `scripts/lib/dependency-ownership.json` even though a different file was actually used. Consider including the resolved path in the returned report so error messages stay accurate, or accept the path as a parameter.
How can I resolve this? If you propose a fix, please make it concise.| const staleOwnershipRecords = Object.keys(dependencyOwnership.dependencies ?? {}) | ||
| .filter((name) => !rootDependencyNames.has(name)) | ||
| .toSorted(); |
There was a problem hiding this comment.
Stale ownership records not surfaced by
--check
staleOwnershipRecords is computed and included in the JSON output, but collectSbomRiskCheckErrors only checks ownershipGaps. Over time, entries whose packages have been removed from package.json will silently accumulate in dependency-ownership.json without causing a pnpm deps:sbom-risk:check failure. If the intent is to keep the file tidy, consider surfacing stale records as check errors too.
Prompt To Fix With AI
This is a comment left during a code review.
Path: scripts/sbom-risk-report.mjs
Line: 188-190
Comment:
**Stale ownership records not surfaced by `--check`**
`staleOwnershipRecords` is computed and included in the JSON output, but `collectSbomRiskCheckErrors` only checks `ownershipGaps`. Over time, entries whose packages have been removed from `package.json` will silently accumulate in `dependency-ownership.json` without causing a `pnpm deps:sbom-risk:check` failure. If the intent is to keep the file tidy, consider surfacing stale records as check errors too.
How can I resolve this? If you propose a fix, please make it concise.3666c2a to
202648c
Compare
Summary
pnpm deps:sbom-riskandpnpm deps:sbom-risk:checkscripts/lib/dependency-ownership.jsonwith current root dependency owners/classes/risksValidation
pnpm test test/scripts/sbom-risk-report.test.ts test/scripts/root-dependency-ownership-audit.test.tspnpm deps:sbom-risk:checkpnpm deps:root-ownership:checkpnpm exec oxlint scripts/sbom-risk-report.mjs test/scripts/sbom-risk-report.test.tspnpm format:check scripts/lib/dependency-ownership.json scripts/sbom-risk-report.mjs test/scripts/sbom-risk-report.test.ts package.json CHANGELOG.mdpnpm check:changedcurrently fails intsgo:allon existing model compat type errors aroundsupportsLongCacheRetention/@mariozechner/pi-aiexports and sparse-worktree missing UI/package test imports; the focused dependency/tooling gates above pass.