Skip to content

fix(npm): treat an unpublished package tombstone as missing, not version-missing - #1868

Open
lanbass869-cell wants to merge 2 commits into
modelcontextprotocol:mainfrom
lanbass869-cell:fix/npm-unpublished-tombstone
Open

lanbass869-cell wants to merge 2 commits into
modelcontextprotocol:mainfrom
lanbass869-cell:fix/npm-unpublished-tombstone

Conversation

@lanbass869-cell

Copy link
Copy Markdown

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. 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) and stillshipping-mcp (unpublished 2026-10-29) both answer 200 on HEAD and GET with versions: {} and time.unpublished set; a live control package answers 200 with a non-empty versions.

Changes

After a 200 from the HEAD probe the validator 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.

One shape detail worth flagging: npm records time.unpublished as an object ({time, versions}), not a timestamp string. Decoding it as a string fails silently, so the struct models it exactly.

Tests

  • tombstone (time.unpublished object + empty versions) → "not found"
  • empty versions without a timestamp → "not found"
  • live package with a missing version → still "exists, but version"

Verified locally: go build, go vet, the three new tests, and the live call against registry.npmjs.org (which now reports NPM package 'ace-context-mcp' not found (status: 404)).

…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 JosephDoUrden left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@lanbass869-cell

Copy link
Copy Markdown
Author

Done in edd8050: io.LimitReader(resp.Body, 1<<20) inside npmPackageIsTombstoned, the same cap confirmMissingPackage uses in internal/malware/existence.go.

One property worth stating explicitly: a packument over the cap fails to decode, which returns false and keeps the conservative "package exists" answer. So the cap cannot turn a live package into "missing"; it only bounds the cost of learning the boolean.

Verified locally on the branch: go test -run TestValidateNPM ./internal/validators/registries/ passes, including the three new cases (tombstone, empty versions, live package with a missing version) and the live-npm subtests. The rest of that package's tests reach us-docker.pkg.dev and quay.io and time out from this network, so those are for CI.

@JosephDoUrden

Copy link
Copy Markdown
Contributor

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.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants