You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Check packages against OSV malware records on publish and daily - #1889
Adds two checks of the packages that registry entries point at against the malware records (MAL-*) that OSV.dev publishes. npm, PyPI, NuGet and Cargo are covered; OCI images and MCPB bundles are not, because OSV has no ecosystem for them.
A package matches when a record names exactly the version the entry points at, or names no versions at all, which is how OSV records a package that is malware in every release. A record that lists some versions does not match the others, even where it also carries a range covering them.
On publish and edit: the check starts in report mode. A matching package is logged and the request goes through; nothing is refused. Once the mode is set to enforce, a match is refused with a 400 that names the package and links to the OSV record. Ordinary vulnerabilities (CVE, GHSA) are not a match, and status changes such as a takedown are not checked.
Daily sweep: re-checks every listed (not deleted) server version, because OSV usually learns about a malicious release after it was published here. The sweep only reports. It never changes an entry; taking one down stays a maintainer's decision.
npm dist-tags are refused as package versions on publish and edit. This is a new rule for publishers; see below.
How
internal/malware: an OSV client and the sweep, which pages the registry's own listing. The client asks /v1/querybatch (at most 1,000 queries per batch, follows result pages) and reads each matching record, before asking for a further page, to see which versions it names. OSV's query alone is not enough: it also matches a version that only falls inside a record's range, and some records pair a list of versions with a range covering every version. Names and versions are compared the way OSV and the package's registry do: PyPI versions by their PEP 440 components, NuGet versions without regard to case, a fourth zero or build metadata, and crate names in any case and with either separator. A record that does not mention the package is an answer that cannot be used, not a match.
The publish-time check runs alongside the package-ownership lookup and is bounded at 2 seconds, with one attempt. If OSV does not answer in full, the check is skipped and logged, never failed; a match OSV did confirm in that time is still acted on. MCP_REGISTRY_MALWARE_CHECK_MODE sets what a match does: report (the default) logs it as REGISTRY_MALWARE_PUBLISH_MATCH and lets the request through, enforce logs it and refuses, and off does not ask OSV. A mode that is none of the three stops the registry at startup. On the hosted stacks it is set with mcp-registry:malwareCheckMode.
The sweep is a -malware-sweep mode of the registry binary, so its CronJob reuses the registry image. It has no Secret, database role or service account: it reads the listing through the mcp-registry Service and sends package names and versions to api.osv.dev. It retries a listing or OSV request that fails in a way that may pass, including an answer that breaks off while it is being read. A sweep that still cannot finish reports the matches it had confirmed and then fails.
tools/admin/configure-malware-alerts.py provisions private email alerts in Cloud Monitoring for a sweep match, for a publish-time match, and for no completed sweep in 25 hours. It mirrors configure-backup-alerts.py. Matches are deliberately not sent to Discord.
Report mode first
The publish-time check refuses nothing until it is told to. The plan is to run it in report mode for a few days and read what it logs. A match that is wrong shows up as REGISTRY_MALWARE_PUBLISH_MATCH action=allowed without a publisher having been turned away. A match it missed shows up in the daily sweep. To start refusing, set mcp-registry:malwareCheckMode: enforce in the stack file; in production that change is a deployment.
Report mode covers the malware check only. Refusing npm dist-tags is a fixed rule, not a match that could be wrong, and it applies from the start.
npm dist-tags
npm answers a dist-tag such as next on its version endpoint with whichever release the tag points at, so a tag passed the ownership check. A tag can be moved to another release after publishing, and there is no version to ask OSV about. The npm ownership check now refuses a package version that npm resolves to a different version, and the error gives the version to use. latest and ranges were already refused.
Existing entries are unchanged. The sweep lists those that name a tag as REGISTRY_MALWARE_SWEEP_UNCHECKED; it does not alert on them. Production has five such server versions today, all naming latest and published before that was refused.
What merging will do
Merging this deploys to staging. It does not deploy to production.
Staging gets the new registry image, so the publish-time check, in report mode, and the dist-tag rule are on there, and a CronJob registry-malware-sweep in default that runs daily at 03:40 UTC (mcp-registry:malwareSweep: "true" in Pulumi.gcpStaging.yaml).
Production is untouched. It gets the publish-time check, in report mode, and the dist-tag rule with the next release it is promoted to. The sweep needs mcp-registry:malwareSweep: "true" in Pulumi.gcpProd.yaml in the same change as, or after, that release: an older image does not know the flag, so the Job would fail at once rather than start a second registry.
No alerts are created by this PR. The script has to be run by hand once the sweep is on.
Cost
A publish with a covered package takes about 0.3 seconds longer, 2 seconds at most. OSV takes about 0.25–0.3 seconds to answer on a warm connection, against some 15 ms for an npm lookup, so running the two side by side does not hide it. Measured locally; not measured from the cluster.
The sweep makes about 2,800 listing requests a day, one at a time, straight to the registry and past the gateway cache, and about 124 batch calls to OSV.
Checked
golangci-lint v2.14.0 reports no issues, and CI passes.
go test -race ./internal/... ./cmd/... passes against a local Postgres, and go -C deploy test ./... passes.
A locally run registry in enforce mode, against real OSV and real package registries, refused two package versions that OSV records name, including one given under PyPI's alternative spelling of its name and version, and stored nothing. It did not refuse a clean release of a package whose record names one other version but carries a range covering all of them; OSV's query does match that release. With OSV unreachable the publish was not blocked and the skip was logged.
The same registry in report mode, the default, logged the match with action=allowed and did not refuse for malware; in enforce mode it logged action=refused. The alert filter matches both lines. A misspelt mode stopped the registry at startup.
The sweep ran against the production listing and real OSV: 280,519 server versions, 123,936 distinct package versions, no matches, five server versions naming a dist-tag, 12 minutes and 177 MB over the public listing. Against a test listing containing known-malware versions it reported those and not their clean neighbours.
Not checked
The dist-tag refusal has not been exercised end to end against npm. It is covered by a test against a stand-in for npm, and npm's behaviour was confirmed separately.
The CronJob has not run in a cluster. Its duration and memory there are unmeasured; the limits are set from the run over the public listing.
The alert script has only been dry-run. The log filters have not been matched against real pod logs.
The full production sweep was last run before the second round of review fixes. Those were checked with the unit tests and against a test listing with real OSV, not with another full run.
NuGet version comparison is a simple one and has no real NuGet malware record behind it.
Known limits
About 9,500 npm malware records give both a list of versions and a range covering every version. They are read as naming the listed versions only. In a sample of 150 of them, 135 packages were gone from npm or reduced to its security placeholder, and 12 were live with versions the record does not list. Some of those 12 are established packages that were compromised once, where this reading is right; others look like throwaway packages, where a version the record does not list would be missed.
A malware record that gives neither versions nor a range would not be found, because OSV does not return such a record for a query that names a version. None of the roughly 237,000 current malware records for npm, PyPI, NuGet and crates.io has that shape, so no second, package-only query was added.
Refuse to publish or edit a server whose npm, PyPI, NuGet or Cargo
package is listed as malware (a MAL-* record) by OSV.dev at exactly the
version named. The check runs alongside the package-ownership lookup,
is bounded at 2s, and is skipped rather than failed when OSV does not
answer.
Add a daily sweep that re-checks every listed server version, since OSV
usually learns about a malicious release after it was published here.
The sweep is a -malware-sweep mode of the registry binary, so its
CronJob reuses the registry image and needs no credentials. It only
reports; taking an entry down stays a maintainer's decision. Switch it
on in staging.
Add tools/admin/configure-malware-alerts.py, which provisions private
email alerts in Cloud Monitoring for sweep matches and for a missing
sweep.
Co-authored-by: Copilot App <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Unresolved npm tags and discarded confirmed OSV hits can allow known-malicious packages to be published, while fuzzy matching violates the exact-version policy.
Adds OSV malware screening to the registry’s package-validation flow and a report-only daily sweep of existing listings. The deployment changes enable the sweep in staging; production remains unchanged by this PR.
Changes:
Adds publish/edit checks for npm, PyPI, NuGet and Cargo packages, bounded to two seconds and skipped when OSV is unavailable.
Adds batched OSV queries and a registry-binary sweep mode, scheduled through a staging CronJob.
Adds private email alert setup, configuration, tests and operational documentation.
File
Description
tools/admin/configure-malware-alerts.py
Provisions email alerts for matches and missing completed sweeps.
README.md
Adds the malware package to the repository layout.
Address review of the malware checks:
- OSV's query also matches a version that only falls inside a record's
range, and some records pair a list of versions with a range covering
every version. Read each matching record and count it only if it names
the version, or names no versions at all. PyPI and NuGet versions and
names are compared the way those registries do.
- npm answers a dist-tag such as "next" with whichever release it points
at, so a tag passed the ownership check and could not be checked for
malware. Refuse a tag as an npm package version on publish and edit,
and have the sweep list existing entries that name one.
- Keep the matches OSV confirmed when a later request fails: refuse them
on publish, and report them from a sweep that could not finish.
- Retry OSV requests that fail in a way that may pass during the sweep.
The publish-time check still makes one attempt within its 2s bound.
- Runbook: read the newest run's log rather than every retained run, and
confirm the entry still points at the package before a takedown.
Co-authored-by: Copilot App <[email protected]>
A server may list the same package once for each transport. The sweep
wrote a line for each listing, so a sweep of production reported five
server versions pointing at an npm dist-tag as fifteen.
Co-authored-by: Copilot App <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Unresolved critical flaws in PyPI version normalization and paginated result handling can let malware bypass checks and cause clean releases to be rejected.
A connection reset or io.ErrUnexpectedEOF while reading a listing page is returned with retry=false, so one transient body-read failure aborts the sweep instead of using its request retries. Same issue in internal/malware/osv.go:342–344. Retry these failures while the context is active, but keep JSON syntax/type errors non-retryable.
Address the second review of the malware checks:
- Read the matching records after each batch, before asking for a
further page of results, so that a slow later page cannot cost a
match OSV has already given.
- Compare PyPI versions by their PEP 440 components: epoch, release,
pre-, post- and development release, and local version. The earlier
comparison merged 1!2.0 with 1!20 and missed respellings that PyPI
serves as one release, such as 1.0alpha1 and 1.0a1.
- Treat a record that does not mention the package as an answer that
cannot be used, rather than as one covering every version.
- Compare crate names in any case and with either separator, as OSV
does, so that a record's version list is applied to the same crate.
- Retry when a listing page or an OSV answer breaks off while it is
being read. An answer that arrives whole and does not parse is still
not retried.
Co-authored-by: Copilot App <[email protected]>
On the item from the second review that has no thread of its own, "Retry transient listing-page body read failures": fixed in 3c78486. A listing page or an OSV answer is now read in full before it is parsed. A connection that breaks while it is being read is retried, and an answer that arrives whole and does not parse is not. A test covers an answer that breaks off part-way.
Add MCP_REGISTRY_MALWARE_CHECK_MODE with three values. In report mode,
the default, a publish or edit that names a package OSV lists as malware
is logged as REGISTRY_MALWARE_PUBLISH_MATCH and goes through. In enforce
mode it is logged and refused. Off does not ask OSV. A mode that is none
of the three stops the registry at startup.
This lets the check run for a few days without refusing anyone: a wrong
match shows up in the log, and a missed one in the daily sweep. The
hosted stacks set the mode with mcp-registry:malwareCheckMode; staging
is set to report.
The alert script gains a policy for the publish-time match. Refusing npm
dist-tags is a fixed rule and is not affected by the mode.
Co-authored-by: Copilot App <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Versioned OSV queries miss MAL records that omit both ranges and versions, leaving publish checks and daily sweeps unable to detect those affected packages.
No open issues 🎉
4 previously missed issues
In code that hasn't changed since last review
Discover MAL records without ranges or versions
internal/malware/osv.go:139
Versioned OSV queries do not return MAL records that omit both ranges and versions; OSV indexes those for package-only queries (implementation). These records never reach the all-versions fallback, so publish checks and daily sweeps miss them. Add package-only discovery for this record shape while retaining versioned queries for bounded range-only records.
Read logs from every pod in the selected Job
docs/administration/admin-operations.md:232
A failed sweep is retried in a new pod, but kubectl logs for a Job selects only one pod. This can hide confirmed matches from the other attempt, including the one that triggered an alert. Read every pod of the selected Job; the same command needs updating in deploy/README.md:1042.
Avoid copying the unprocessed queue tail on every batch
internal/malware/osv.go:165
Both append calls copy the whole unprocessed tail after every batch, even when no results need another page. This makes queue work quadratic as the registry grows and adds unnecessary allocations to the daily sweep. Reuse the consumed prefix for continuation queries and slice past completed entries instead.
Report packages skipped when ownership validation is disabled
internal/malware/sweep.go:142
A registry with ownership validation disabled can list covered packages without versions, because the schema permits omission. This branch silently drops them while allowing the sweep to report success, leaving operators unaware that those packages were not checked. Report them as unchecked or fail the sweep instead of silently skipping them.
Address the third review of the malware checks:
- The sweep now lists a covered package that names no version as
unchecked, with the reason, instead of passing over it. Such an entry
can exist where a registry runs without registry validation.
- The runbook reads the log of every pod of the newest Job. A sweep
that failed is tried again in a second pod, and the first may hold
the matches.
- Walk the query queue by index rather than copying its tail after
every batch.
Not changed: looking for malware records that give neither versions nor
ranges with package-only queries. None of the roughly 237,000 current
MAL records for npm, PyPI, NuGet and crates.io has that shape.
Co-authored-by: Copilot App <[email protected]>
On the four items in the third review, which have no threads of their own. Three are fixed in 220b551 and one is left as it is.
Read logs from every pod in the selected Job: fixed. The runbook and deploy/README.md now read every pod of the newest Job by its job-name label.
Avoid copying the unprocessed queue tail on every batch: fixed. The queue is walked by index, and the queries that continue on a further page are collected and asked for afterwards.
Report packages skipped when ownership validation is disabled: fixed. A covered package that names no version is now listed as REGISTRY_MALWARE_SWEEP_UNCHECKED with reason="no version", next to reason="dist-tag", and counted in the success line.
Discover MAL records without ranges or versions: not changed. I classified every current MAL-* record in OSV's exports for npm, PyPI, NuGet and crates.io, about 237,000 in all, and none gives neither versions nor a range. A second, package-only query for every package would roughly double the sweep's OSV traffic for a record shape that does not exist today. It is written down as a known limit in the PR description.
#1891)
## What
Three lines in `deploy/Pulumi.gcpProd.yaml`:
- `imageTag` 1.8.11 → 1.8.12, and `registryRolloutCommit` to that
release's commit.
- `mcp-registry:malwareSweep: "true"`.
**Merging this deploys to production.**
## What the deploy will do
1. **Roll the registry to 1.8.12.** Beyond 1.8.11 the registry image
carries two changes:
- #1889: the publish-time malware check and the refusal of npm dist-tags
as package versions.
- #1879: a bump of five Go dependencies.
2. **Move the usage collector to its 1.8.12 image.** It follows
`imageTag`. Its code is unchanged since 1.8.11; it is rebuilt with the
same dependency bump.
3. **Create one CronJob, `registry-malware-sweep`, in `default`.** It
runs the registry's own image with `-malware-sweep` daily at 03:40 UTC.
It has no Secret, database role or service account. It reads the listing
from the `mcp-registry` Service and sends package names and versions to
`api.osv.dev`.
The infrastructure code in between was already applied to production by
hand at cb2710c, so nothing else is pending.
## What changes for publishers
- **Malware matches are logged, not refused.**
`mcp-registry:malwareCheckMode` is not set, so the check runs in report
mode. A publish or edit that names a package OSV lists as malware goes
through, and is logged as `REGISTRY_MALWARE_PUBLISH_MATCH
action=allowed`.
- **npm dist-tags are refused from this deploy on.** A publish whose npm
package `version` is a tag such as `next` gets a `400` naming the
version to use. `latest` was already refused, and no production entry
names any other tag.
- **A publish with an npm, PyPI, NuGet or Cargo package takes about 0.3
seconds longer**, 2 seconds at most, for the OSV call. If OSV does not
answer, the publish goes ahead.
## What the sweep does
It only reports. It never changes an entry. A match is written to its
log as `REGISTRY_MALWARE_SWEEP_HIT`; taking the entry down stays a
maintainer's decision.
## Evidence from staging
Staging has run this build since 02:04 UTC on 2026-11-22.
- **Registry:** no warnings or errors in its log. Its pod was replaced
once, at 06:02 UTC, by the weekly staging database restore.
- **Sweep, twice:** by hand at 02:06 UTC and on schedule at 03:40 UTC.
Each read 255,401 server versions in about 3 minutes, using about 100
MiB. Both reported the one entry in staging's data that pointed at a
known-malware release, which production had already taken down.
- **Load during the scheduled sweep:** the registry pod averaged at most
0.18 CPU in any minute, and Postgres 0.14 CPU, for about two minutes.
Production's two registry pods were at 40% of their CPU request against
a 60% autoscaling target when last read.
- **Publish check in the cluster:** a publish naming the known-malware
release was logged as allowed, and a re-publish of an existing clean
version passed validation. Neither stored anything.
## Not checked
- **No preview of this change.** The production workflow previews `main`
only. What the deploy will do is read from the code and from staging's
deploy of the same code.
- **No organic publish traffic in staging.** Real publishes meet the
check for the first time in production, in report mode.
- **The 1.8.12 release image has not run anywhere.** Staging runs the
`main` build of the same commit.
## After the deploy
1. Create the alerts first. They go to an email address through Cloud
Monitoring and never to Discord. Until they exist, matches are only in
the logs:
```bash
python3 tools/admin/configure-malware-alerts.py \
--project mcp-registry-prod --cluster mcp-registry-prod --email
YOUR_EMAIL --dry-run
# Review, then rerun without --dry-run.
```
2. Then run the sweep once and read its log. It should end with
`REGISTRY_MALWARE_SWEEP_SUCCESS`:
```bash
kubectl -n default create job --from=cronjob/registry-malware-sweep
registry-malware-sweep-manual
kubectl -n default logs -l job-name=registry-malware-sweep-manual
--tail=-1 --prefix
```
The alerts come first because the "sweep missing" alert counts only
sweeps that finish after it was created. It may fire once in the minutes
between the two steps and close when the sweep finishes.
3. Fired alerts can be read without email:
```bash
curl -s -H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://monitoring.googleapis.com/v3/projects/mcp-registry-prod/alerts?pageSize=50"
\
| jq -r '.alerts[]? | select(.policy.displayName | test("malware"; "i"))
| "\(.openTime) \(.state) \(.policy.displayName)"'
```
4. `deploy/README.md` still says the sweep is not on in production and
has not been timed in a cluster. That needs a follow-up.
## To undo
- Sweep: remove `mcp-registry:malwareSweep`. The CronJob is deleted.
- Publish check: set `mcp-registry:malwareCheckMode: off`.
- Everything: set `imageTag` back to 1.8.11.
Co-authored-by: Copilot App <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds two checks of the packages that registry entries point at against the malware records (
MAL-*) that OSV.dev publishes. npm, PyPI, NuGet and Cargo are covered; OCI images and MCPB bundles are not, because OSV has no ecosystem for them.A package matches when a record names exactly the version the entry points at, or names no versions at all, which is how OSV records a package that is malware in every release. A record that lists some versions does not match the others, even where it also carries a range covering them.
400that names the package and links to the OSV record. Ordinary vulnerabilities (CVE, GHSA) are not a match, and status changes such as a takedown are not checked.How
internal/malware: an OSV client and the sweep, which pages the registry's own listing. The client asks/v1/querybatch(at most 1,000 queries per batch, follows result pages) and reads each matching record, before asking for a further page, to see which versions it names. OSV's query alone is not enough: it also matches a version that only falls inside a record's range, and some records pair a list of versions with a range covering every version. Names and versions are compared the way OSV and the package's registry do: PyPI versions by their PEP 440 components, NuGet versions without regard to case, a fourth zero or build metadata, and crate names in any case and with either separator. A record that does not mention the package is an answer that cannot be used, not a match.MCP_REGISTRY_MALWARE_CHECK_MODEsets what a match does:report(the default) logs it asREGISTRY_MALWARE_PUBLISH_MATCHand lets the request through,enforcelogs it and refuses, andoffdoes not ask OSV. A mode that is none of the three stops the registry at startup. On the hosted stacks it is set withmcp-registry:malwareCheckMode.-malware-sweepmode of the registry binary, so its CronJob reuses the registry image. It has no Secret, database role or service account: it reads the listing through themcp-registryService and sends package names and versions toapi.osv.dev. It retries a listing or OSV request that fails in a way that may pass, including an answer that breaks off while it is being read. A sweep that still cannot finish reports the matches it had confirmed and then fails.tools/admin/configure-malware-alerts.pyprovisions private email alerts in Cloud Monitoring for a sweep match, for a publish-time match, and for no completed sweep in 25 hours. It mirrorsconfigure-backup-alerts.py. Matches are deliberately not sent to Discord.Report mode first
The publish-time check refuses nothing until it is told to. The plan is to run it in report mode for a few days and read what it logs. A match that is wrong shows up as
REGISTRY_MALWARE_PUBLISH_MATCH action=allowedwithout a publisher having been turned away. A match it missed shows up in the daily sweep. To start refusing, setmcp-registry:malwareCheckMode: enforcein the stack file; in production that change is a deployment.Report mode covers the malware check only. Refusing npm dist-tags is a fixed rule, not a match that could be wrong, and it applies from the start.
npm dist-tags
npm answers a dist-tag such as
nexton its version endpoint with whichever release the tag points at, so a tag passed the ownership check. A tag can be moved to another release after publishing, and there is no version to ask OSV about. The npm ownership check now refuses a packageversionthat npm resolves to a different version, and the error gives the version to use.latestand ranges were already refused.Existing entries are unchanged. The sweep lists those that name a tag as
REGISTRY_MALWARE_SWEEP_UNCHECKED; it does not alert on them. Production has five such server versions today, all naminglatestand published before that was refused.What merging will do
Merging this deploys to staging. It does not deploy to production.
registry-malware-sweepindefaultthat runs daily at 03:40 UTC (mcp-registry:malwareSweep: "true"inPulumi.gcpStaging.yaml).mcp-registry:malwareSweep: "true"inPulumi.gcpProd.yamlin the same change as, or after, that release: an older image does not know the flag, so the Job would fail at once rather than start a second registry.Cost
Checked
go test -race ./internal/... ./cmd/...passes against a local Postgres, andgo -C deploy test ./...passes.action=allowedand did not refuse for malware; in enforce mode it loggedaction=refused. The alert filter matches both lines. A misspelt mode stopped the registry at startup.Not checked
Known limits
After merge, in staging
REGISTRY_MALWARE_SWEEP_SUCCESS.deploy/pkg/k8s/malware_sweep.goif needed.