Repository navigation
fix: adapt audit client to npmjs /advisories/bulk endpoint - #11268
Conversation
| const quickAuditUrl = `${registry}-/npm/v1/security/audits/quick` | ||
| const auditUrl = `${registry}-/npm/v1/security/advisories/bulk` | ||
| const authHeaderValue = getAuthHeader(registry) | ||
| const requestBody = JSON.stringify(auditTree) |
There was a problem hiding this comment.
The changes are less trivial than just changing the endpoint. The expected body of the POST request is completely different to what is generated by lockfileToAuditTree and sent as body.
Expected:
{
"@npmcli/arborist": [
"1.0.0",
"2.0.1"
],
"@npmcli/config": [
"10.4.2"
]
}The type of auditTree is:
export interface AuditNode {
version?: string
integrity?: string
requires?: Record<string, string>
dependencies?: { [name: string]: AuditNode }
dev: boolean
}There was a problem hiding this comment.
More complex you mean?
yikes 😬 I meant less trivial!
There was a problem hiding this comment.
Before putting together this PR I hacked into my local pnpm script files, to change the URL, and it seemed to work. But if formats can differ, we should cope...
There was a problem hiding this comment.
Retracing my steps; it seems you're right: even the message body does not conform to the one required by the new endpoint:
ERR_PNPM_AUDIT_BAD_RESPONSE The audit endpoint (at https://registry.npmjs.org/-/npm/v1/security/advisories/bulk) responded with 400: {"statusCode":400,"error":"Bad Request","message":"Invalid request payload input"}
|
What about the people using private registries? |
Good point; we could re-instate the fallback mechanism, with that endpoint fallback. Any opinions? |
The new endpoint expects a flat {name: [versions]} request body and
returns advisories keyed by package name, so simply renaming the URL is
not enough. Flatten the audit tree for the request and map the bulk
response into the existing AuditReport shape, recomputing findings
paths from the lockfile and severity counts locally, since the new
endpoint no longer returns them.
There was a problem hiding this comment.
Pull request overview
Updates pnpm’s audit implementation to use npmjs.org’s replacement /-/npm/v1/security/advisories/bulk endpoint now that the legacy /-/npm/v1/security/audits{,/quick} endpoints are retired, while keeping downstream consumers working by mapping the new response back into AuditReport.
Changes:
- Switch audit client networking from
/audits{,/quick}to/advisories/bulk, including new request/response adaptation logic. - Update audit-related tests/mocks and regenerate
audit --jsonsnapshot for the new report shape (actions: [], locally computed counts/paths). - Fix
AuditAdvisory.findingstyping from a tuple to an array and addsemverto support local vulnerability matching.
Reviewed changes
Copilot reviewed 12 out of 13 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
deps/compliance/audit/src/index.ts |
Implements /advisories/bulk request/response mapping and local findings/count computation. |
deps/compliance/audit/src/types.ts |
Fixes findings typing by introducing AuditFinding and using AuditFinding[]. |
deps/compliance/audit/test/index.ts |
Updates mock endpoint paths/responses for the new bulk endpoint behavior. |
deps/compliance/audit/package.json |
Adds semver (+ types) required for local version range matching. |
deps/compliance/commands/test/audit/utils/responses/index.ts |
Converts legacy captured fixtures into bulk response shape at load time. |
deps/compliance/commands/test/audit/index.ts |
Updates audit command integration tests to intercept the new bulk endpoint and adjusts expectations. |
deps/compliance/commands/test/audit/fix.ts |
Updates audit fix tests to intercept the new bulk endpoint. |
deps/compliance/commands/test/audit/ignore.ts |
Updates ignore tests to intercept the new bulk endpoint. |
deps/compliance/commands/test/audit/fixWithUpdate.ts |
Converts legacy on-disk fixture responses to bulk shape before replying. |
deps/compliance/commands/test/audit/preserveReferenceOverrides.ts |
Updates endpoint interception to bulk. |
deps/compliance/commands/test/audit/__snapshots__/index.ts.snap |
Regenerates snapshot for the new JSON output shape (no actions, new counts). |
pnpm-lock.yaml |
Records semver and @types/semver additions. |
.changeset/fix-npmjs-audit-endpoint.md |
Declares release impacts (major/minor/patch) for the endpoint migration. |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…ures The /advisories/bulk endpoint does not return CVE identifiers or most of the metadata the old /audits endpoint provided. Rename auditConfig.ignoreCves to auditConfig.ignoreGhsas, make --ignore and --ignore-unfixable operate on GitHub advisory IDs, and derive the GHSA from each advisory URL. patched_versions is inferred from vulnerable_versions for simple < and <= ranges so audit --fix still produces useful overrides. Regenerate the top-level fixtures with real bulk responses captured from registry.npmjs.org and convert the synthetic update-* fixtures to the bulk shape. Drop the runtime fixture-shape conversion from the tests.
- Skip importer wrapper nodes in buildBulkRequestBody so only real package names appear in the /advisories/bulk payload. - Compute metadata.dependencies as the non-dev portion so the counts in AuditMetadata stay internally consistent. - Explicitly populate every required AuditAdvisory field in normalizeAdvisory instead of relying on a force cast, so downstream code never sees undefined in required fields. - Add a unit test that drives the locally-computed findings path with a bare bulk response matching what registry.npmjs.org returns today.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 29 out of 32 changed files in this pull request and generated 2 comments.
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- buildFindings no longer emits a placeholder finding when no installed version satisfies the vulnerable range; bulkResponseToAuditReport now skips advisories that end up with zero findings so the CLI does not report false positives for packages the lockfile doesn't use. - Rename advisoryWthNoResolutions to advisoryWithNoResolutions. - Update info-vulnerability fixture to key on a package the lockfile actually uses (axios) so the new skip-empty-findings logic exercises the info-severity path. - Backfill the preserve-reference-overrides lockfile with a snapshots block so lockfileToAuditTree walks its dependencies; without it, the fixture had only importer-level deps and no advisories could match.
The nested AuditTree shape existed to match the legacy /audits request
body. The new /advisories/bulk endpoint needs only a flat
{name: [versions]} map, and finding paths are computed locally from the
lockfile. Walking the lockfile into a deep tree and then traversing it
twice more to flatten it and index paths was wasted work.
Replace lockfileToAuditTree with lockfileToAuditIndex, which walks the
lockfile once and returns both the POST body and a name→version→paths
index. Drop AuditTree/AuditNode, buildBulkRequestBody, buildPathIndex,
and the manifest-read/ramda/workspace.project-manifest-reader deps they
needed.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 38 out of 42 changed files in this pull request and generated 1 comment.
Files not reviewed (2)
- deps/compliance/commands/test/audit/fixtures/preserve-reference-overrides/pnpm-lock.yaml: Language not supported
- pnpm-lock.yaml: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 38 out of 42 changed files in this pull request and generated 3 comments.
Files not reviewed (2)
- deps/compliance/commands/test/audit/fixtures/preserve-reference-overrides/pnpm-lock.yaml: Language not supported
- pnpm-lock.yaml: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
The legacy
/-/npm/v1/security/audits{,/quick}endpoints have been retired by npmjs.org. This PR rewires the audit client to the replacement/-/npm/v1/security/advisories/bulkendpoint.The new endpoint is not a drop-in rename — the request and response contracts are both different:
{ pkgName: [versions] }map.lockfileToAuditRequestwalks the lockfile once and builds the POST body directly; there is no more nestedAuditTree.id,url,title,severity,vulnerable_versions, andcweper advisory. Everything else the old endpoint returned is computed locally:findings[].pathsare walked from the lockfile (skipped entirely when the response is empty; the second walk intentionally avoids@pnpm/lockfile.walker's global dedup so alternate install chains to the same shared dep aren't dropped).metadata.vulnerabilitiescounts advisories per severity.metadata.dependencies/devDependencies/optionalDependencies/totalDependenciescome from a classified lockfile walk; the classifier respects--prod/--devinclude flags when deciding whether a subgraph is reachable non-optionally.patched_versionsis inferred from the vulnerable range for common<X.Y.Z/<=X.Y.Zshapes soaudit --fixcan still produce usable overrides; leftundefinedwhen inference fails.github_advisory_idis parsed from the advisory URL and canonicalized to the github.com form (uppercaseGHSA-prefix, lowercase suffix).infoseverity is now supported end-to-end (severity type,--audit-level, filters, colors).Breaking changes (v11)
/advisories/bulknow fail withAuditEndpointNotExistsError.auditConfig.ignoreCves→auditConfig.ignoreGhsas(the old key is no longer recognized).pnpm audit --ignore <id>and--ignore-unfixablenow read and write GHSAs.CVE-YYYY-NNNNNinauditConfig.ignoreCveswith the matchingGHSA-xxxx-xxxx-xxxx(visible in theMore infocolumn ofpnpm auditoutput) underauditConfig.ignoreGhsas.--ignore-unfixablenow only targets advisories whose patched range couldn't be inferred — the only "no fix available" signal the bulk endpoint provides.AuditReportandAuditAdvisoryare trimmed to just the fields the audit client actually populates:AuditReport:advisories+metadataonly (actionsandmutedremoved).AuditAdvisory:findings,id,title,module_name,vulnerable_versions,patched_versions?,severity,cwe,github_advisory_id,url. Dropped:cves,created,updated,deleted,access,overview,recommendation,references,found_by,reported_by,metadata.AuditAction,AuditResolution,AuditActionRecommendationremoved (no consumers).Hardening
ERR_PNPM_AUDIT_BAD_RESPONSEwith a body excerpt. Advisoryidmust be a finite number andseveritymust be a known value before being indexed.Object.create(null)so a hostile/unusual package name can't trigger prototype pollution.findings[].pathsare deduped and capped per (name, version) to keep pathologically shared graphs from blowing up memory.Internals
AuditTree/AuditNode/lockfileToAuditTreeremoved.lockfileToAuditIndex.tsexportslockfileToAuditRequest(flat POST body + counts) andbuildAuditPathIndex(only invoked when the response has advisories).AuditAdvisory.findingsis nowAuditFinding[](was an unintended 1-tuple).registry.npmjs.orgresponses; syntheticupdate-*fixtures converted in place to bulk shape.