Repository navigation
fix(npm): treat an unpublished package tombstone as missing, not version-missing - #1868
lanbass869-cell wants to merge 2 commits into
Conversation
…ion-missing probeNPMPackage issues a HEAD to the package endpoint and treats 200 as 'package exists'. For an unpublished unscoped package npm keeps a tombstone and still answers 200, with time.unpublished set and an empty versions map, so the 404 path tells the publisher 'package exists, but version X was not found' - advice that cannot be followed, because the package cannot be republished under that name. Evidence (modelcontextprotocol#1862): ace-context-mcp (unpublished 2026-08-05) and stillshipping-mcp (unpublished 2026-10-29) both answer 200 on HEAD and GET with versions={} and time.unpublished set. After a 200 from the HEAD probe the validator now fetches the packument (full, since the abbreviated form omits time) and returns npmPackageMissing when time.unpublished is present or versions is empty. Inconclusive results keep the previous conservative classification, and the extra request happens only on the 404 error path. Note on shape: npm records time.unpublished as an OBJECT ({time, versions}), not a timestamp string; decoding it as a string silently fails, which is why the struct models it exactly. Tests: tombstone -> 'not found'; empty versions without a timestamp -> 'not found'; live package with a missing version -> still 'exists, but version'.
JosephDoUrden
left a comment
There was a problem hiding this comment.
Tested this locally. go test ./internal/validators/registries/... all green, and against live npm ace-context-mcp and stillshipping-mcp now come back as not found while @asterpay/mcp-server@1.0.1 still gets the version message. One thing: the tombstone GET decodes the whole packument, so a bogus version on next allocates about 97 MB. Wrapping the body in io.LimitReader(resp.Body, 1<<20), the same cap confirmMissingPackage uses in internal/malware/existence.go on main, takes that to about 4 MB and the tests still pass. Looks good otherwise.
Review feedback (JosephDoUrden): the tombstone GET decodes the whole packument, so a bogus version on a package with many versions allocated ~97 MB. Wrapping the body in io.LimitReader(resp.Body, 1<<20) - the same cap confirmMissingPackage uses - takes it to ~4 MB, with the tests unchanged.
|
Done in edd8050: One property worth stating explicitly: a packument over the cap fails to decode, which returns Verified locally on the branch: |
|
Re-ran on edd8050: npm tests green under -race. With an 18 MB packument and a missing version it allocates about 4 MB now instead of about 91 MB, and still says the version is missing. Nothing further from me. |
probeNPMPackageissues a HEAD to the package endpoint and treats200as "package exists". For an unpublished unscoped package npm keeps a tombstone and still answers200, withtime.unpublishedset and an emptyversionsmap. The 404 path therefore tells the publisher "package exists, but version X was not found" - advice that cannot be followed, because the package cannot be republished under that name.Evidence (#1862):
ace-context-mcp(unpublished 2026-08-05) andstillshipping-mcp(unpublished 2026-10-29) both answer200on HEAD and GET withversions: {}andtime.unpublishedset; a live control package answers200with a non-emptyversions.Changes
After a
200from the HEAD probe the validator fetches the packument (full, since the abbreviated form omitstime) and returnsnpmPackageMissingwhentime.unpublishedis present orversionsis empty. Inconclusive results keep the previous conservative classification, and the extra request happens only on the 404 error path.One shape detail worth flagging: npm records
time.unpublishedas an object ({time, versions}), not a timestamp string. Decoding it as a string fails silently, so the struct models it exactly.Tests
time.unpublishedobject + emptyversions) → "not found"versionswithout a timestamp → "not found"Verified locally:
go build,go vet, the three new tests, and the live call againstregistry.npmjs.org(which now reportsNPM package 'ace-context-mcp' not found (status: 404)).