Skip to content

Report entries whose package is gone, and end each sweep with one report - #1895

Merged
rdimitrov merged 4 commits into
mainfrom
rdimitrov-osv-malware-checks
Nov 22, 2026
Merged

rdimitrov merged 4 commits into
mainfrom
rdimitrov-osv-malware-checks

Conversation

@rdimitrov

@rdimitrov rdimitrov commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

What

The daily sweep told a maintainer about malware one log line at a time, and said nothing about an entry whose package has been removed from its own registry. This changes both.

  • Missing packages. After asking OSV, the sweep makes one request for each distinct package to npm, PyPI, NuGet or crates.io, and reports every server version pointing at a package that is gone (REGISTRY_MALWARE_SWEEP_MISSING). An npm package whose every version was unpublished counts as gone: npm still answers 200 at its address, and those are the unscoped names anyone can register again. A package that exists without the version an entry names is not reported.
  • One report. Every sweep ends with one JSON line ("event":"REGISTRY_MALWARE_SWEEP_REPORT") holding the counts, a summary and the entries, malware first. It stays inside one 16 KiB log line; the per-entry lines still hold the whole list. A failed sweep writes it too, with "complete":false, including one that could not read the whole listing.
  • One email a day. tools/admin/configure-malware-alerts.py replaces the per-hit policy with two that read the report: critical if any entry is malware, a warning for anything else to review. Exactly one matches a report with something in it, and the summary is carried into the email. Report and publish alerts now close after 30 minutes, since an open alert sends nothing for a further match.

How npm is asked

PyPI, NuGet and crates.io get a HEAD. npm gets a GET of the first kilobyte (Range) of the package's short record: a fully unpublished package's record is its name and a date, about 60 bytes with no dist-tags; anything a kilobyte long, or with dist-tags, has a release.

Asking for /<name>/latest instead tells the two apart as well, but npm limits that address: after about 530 requests it answered 429 with retry-after: 470. The package's own address took 32 requests at a time for 18,000 packages without one 429.

Safeguards

  • The package registries get 12 minutes of their own. A package not reached, or not answered, is existence_unknown and is not reported; the sweep still succeeds with what OSV said.
  • A registry that answers "not found" for more than a tenth of its packages, and for at least 50, is not believed: none of them is reported.
  • When a registry leaves more than a tenth of its packages unknown, or was not believed, the report says "existence_incomplete":true and the warning email is sent, so a registry that stops answering is not read as one that has lost nothing.
  • A short npm record that is not a package's record (no name) is unknown, not missing.
  • crates.io is asked one request a second, as its crawler policy requires. npm is asked 32 at a time.
  • MCP_REGISTRY_MALWARE_SWEEP_MISSING_PACKAGES=false switches the requests off.
  • The alert script removes the old per-hit policy only once the cluster's sweep has written a report in the last 26 hours, so a cluster still on the old image stays watched.

Measured

Read-only runs against production from outside the cluster on 2026-11-22: 281,000 server versions, 24,000 distinct packages.

npm HEAD, 8 at a time npm HEAD, 32 at a time npm record, 32 at a time (this PR)
Package registries about 16.5 min 4 min 10 s 4 min 16 s
Whole run (public listing) 29 min 16 min 16 min
Packages left unknown 0 0 0
Server versions reported missing 507 433 649

Between the first two runs 74 of those versions were taken down. The last run adds 219 versions pointing at 71 unpublished npm packages, all unscoped; each of the 71 was checked again by hand and has no release.

Not verified yet

These need the staging cluster, after merge:

  • That the report line arrives in Cloud Logging as jsonPayload.
  • That the alert email shows the summary (labelExtractors and ${log.extracted_label.summary}), and at what length.
  • The in-cluster duration and resource use.

Production keeps running the current sweep and alerts until a release is promoted; the new alert script should not be run there before that.

Tests

go test -race ./internal/malware/, golangci-lint v2.14.0, go -C deploy test ./..., and the alert script's --dry-run.

The daily sweep now also asks npm, PyPI, NuGet and crates.io whether each
listed package still exists, and reports the server versions pointing at one
that does not. Every sweep ends with one JSON line holding everything a
maintainer has to look at, malware first, with a summary for the alert email.

The alerts read that line: one email a day when there is something to review,
critical if any of it is malware.

Co-authored-by: Copilot App <[email protected]>

Copilot AI 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.

🟡 Changes recommended

Unresolved existence-check filtering and threshold errors suppress valid missing-package findings and warnings, while listing failures omit the required incomplete report.

4 open issues
What changed in this PR

This PR extends the daily malware sweep to identify missing packages and consolidate findings into a bounded JSON report for maintainer alerts.

Changes:

  • Adds package-existence checks with registry-specific concurrency, timeouts, and safeguards against unreliable responses.
  • Introduces summary reports and report-based alerts, with guarded retirement of the previous per-hit policy.
  • Updates configuration, tests, and operational documentation.
File Description
tools/​admin/​configure-malware-alerts.py Adds report-based policies and guarded removal of obsolete alerts.
internal/​malware/​sweep.go Integrates existence checks, findings, and report emission.
internal/​malware/​sweep_test.go Tests missing packages, safeguards, timeouts, and reports.
internal/​malware/​report.go Defines bounded JSON reports and sanitized summaries.
internal/​malware/​osv.go Adds repository contact information to the user agent.
internal/​malware/​existence.go Implements concurrent package-registry probes and response safeguards.
internal/​config/​config.go Adds the missing-package check toggle.
docs/​administration/​admin-operations.md Documents reports and maintainer response procedures.
deploy/​README.md Describes registry requests, timing, and alert migration.
deploy/​pkg/​k8s/​malware_sweep.go Updates the deployment comment to describe existence checks.
cmd/​registry/​main.go Wires sweep settings, timeout, and additional result counts.
.env.example Documents the missing-package check setting.

Review effort: Balanced

Comment thread internal/malware/existence.go Resolved
Comment thread internal/malware/sweep.go Resolved
Comment thread internal/malware/sweep.go Resolved
Comment thread internal/malware/sweep.go Resolved
rdimitrov and others added 3 commits November 22, 2026 14:57
npm keeps answering 200 at a package's own address after every version
of it has been unpublished, with a record that holds no versions, so the
sweep read such a package as present. Those are the names anyone can
register again. Ask for the package's latest release instead, which is
gone with the package: still one HEAD request per package.

Checked against npm on 1,594 packages the registry lists: both addresses
gave the same answer for every one of them, so nothing that exists is
newly reported.

Co-authored-by: Copilot App <[email protected]>
…eference

- The implausibility floor counts the packages reported missing, not the
  packages asked about, so a few genuine removals in a small registry are
  still reported.
- A sweep that could not read the whole listing writes its report too, with
  what the pages it read held.
- A reference that names no release OSV can be asked about is still checked
  for existence.
- Whether the existence check was incomplete is decided for each package
  registry by share alone, and a registry that was not believed counts.

Co-authored-by: Copilot App <[email protected]>
…atest release

npm turns away a client that asks for /<name>/latest more than a few hundred
times: after about 530 requests it answered 429 with a retry-after of 470
seconds, which would leave most of npm unknown in every sweep. The package's
own address is not limited that way, at 32 requests at a time.

So the sweep fetches the first kilobyte of the package's short record there.
A package whose every version was unpublished has a record of its name and a
date, shorter than that and with no dist-tags; a record that long, or one
with dist-tags, is a package with a release.

Run against production's listing: 23,938 packages in 4m16s, none unknown.
71 unpublished packages are newly reported, and each was confirmed to have
no release.

Co-authored-by: Copilot App <[email protected]>
@rdimitrov
rdimitrov merged commit 57332f3 into main Nov 22, 2026
16 checks passed
@rdimitrov
rdimitrov deleted the rdimitrov-osv-malware-checks branch November 22, 2026 13:33
rdimitrov added a commit that referenced this pull request Nov 22, 2026
Sets `mcp-registry:imageTag` to `1.8.13`. Nothing else in the stack file
changes.

## What production gets

v1.8.13 is `main` at 57332f3. Since v1.8.12:

- **#1895**: the daily malware sweep also asks npm, PyPI, NuGet and
crates.io whether each listed package still exists, and ends with one
JSON report line. The registry server itself is unchanged by it: the new
code runs only in the `registry-malware-sweep` CronJob.
- **#1893**: the three operational Grafana dashboards. This is `deploy/`
code already on `main`, so the production deploy applies it with this
PR.
- #1892 and #1894 touch documentation and the alert script only.

Both images exist: `ghcr.io/modelcontextprotocol/registry:1.8.13` and
`registry-usage-collector:1.8.13`.

## Measured on staging

Two hand-run sweeps of the same build on 2026-11-22, on a copy of
production's data (280,909 server versions, 23,945 distinct packages):

| | v1.8.12 sweep | this build |
|---|---|---|
| Duration | 2 min 54 s | 5 min 58 s and 5 min 51 s |
| Sweep pod, peak | about 120 MiB | 273m CPU, 124 MiB |
| Packages left unknown | n/a | 0 |

The extra three minutes are requests to the package registries; the
registry and Postgres see the same listing read as before. The report
arrived in Cloud Logging as `jsonPayload` (10 KB, inside one log line),
and the new alert fired with the report's summary attached.

## After this deploys

1. Run `tools/admin/configure-malware-alerts.py` for the production
project. Until a production sweep has written a report, it keeps the
current per-hit policy, so production is watched throughout.
2. The first sweep on this build is the next 03:40 UTC run, or one
started by hand.

## What to expect

The first report will list about 650 server versions (206 servers) that
point at a package that is gone, and send the warning email every day
until they are dealt with. That backlog is existing data, not something
this change causes.

## Rollback

Set `imageTag` back to `1.8.12`. The freshness and publish alerts work
with either build. If the alert script has by then removed the per-hit
policy, a v1.8.12 sweep that finds malware would send no email, because
it writes no report: check its log by hand, or roll forward again.

Co-authored-by: Copilot App <[email protected]>
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