registry/internal/validators/registries
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Radoslav Dimitrov 7a6d1bc30a
fix(cargo): harden README fetch, clarify status handling, strengthen tests (#1330)
Follow-up to #1207, addressing items from the cargo validator review.
**Scoped to cargo + shared helpers — no behavior change for existing
npm/pypi/nuget/oci/mcpb publishers.** Safe to merge and promote.

### Changes
**SSRF hardening of the two-call README retrieval**
- Pin the step-2 README URL to an allowed host (`static.crates.io` in
prod; the base host under test) *before* fetching, so a metadata
response can't steer the validator at an internal/attacker host.
- `CheckRedirect` policy pins every redirect hop to the same allowlist
(the initial URL being pinned isn't enough if an upstream 3xx is
followed).
- Cap the README body with `io.LimitReader` (5 MiB).

> Not publisher-exploitable today (the URL comes from crates.io), so
this is defense-in-depth — but it makes the "host is pinned" guarantee
hold in code rather than rely on crates.io's behavior.

**Clearer status handling** (previously any non-5xx/non-200 collapsed to
"not found")
- **429** → reported as transient/retryable, at both the metadata and
README steps.
- **403** → disambiguated via the crate-version endpoint:
genuinely-missing stays "not found"; *exists-but-no-README* gets an
actionable "add a README with `mcp-name` and republish" message (mirrors
the NuGet validator). This continues the 5xx-vs-403 diagnostic split
@P4ST4S started in the #1207 review — thanks!

**Shared `containsMCPNameToken` helper**
Boundary-anchored ownership-token match (prevents prefix confusion, e.g.
a README declaring `io.github.acme/widget-pro` satisfying a claim for
`io.github.acme/widget`), used here **by the cargo validator only**.
Adopting it in PyPI/NuGet is a separate follow-up because it's a
behavior change for those already-live registries.

**Tests & docs**
Hermetic positive `ServerNameFormats`; combined fixture gains a
version-existence endpoint + cases for 403-missing vs 403-no-README,
429, and prefix-confusion rejection; new foreign-README-host (SSRF)
test; internal test for the helper. Docs: list `crates.io` in the
registry-requirements list + the `Package` model doc.

### Testing
`go build`, `go vet`, full `./internal/validators/...` suite (incl. live
cargo positive), `make check-schema`, `validate-examples` all pass. No
new `golangci-lint` findings.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-04 17:34:54 -04:00
..
cargo.go fix(cargo): harden README fetch, clarify status handling, strengthen tests (#1330) 2026-06-04 17:34:54 -04:00
cargo_test.go fix(cargo): harden README fetch, clarify status handling, strengthen tests (#1330) 2026-06-04 17:34:54 -04:00
export_test.go feat: add cargo (crates.io) as a package registry type (#1207) 2026-06-03 10:56:43 -04:00
mcpb.go security: fix open redirect and add small hardening (#1227) 2026-04-29 19:14:00 -04:00
mcpb_test.go Make mcpb package version optional and fix schema validation (#686) 2025-10-17 01:35:29 +03:00
mcpname.go fix(cargo): harden README fetch, clarify status handling, strengthen tests (#1330) 2026-06-04 17:34:54 -04:00
mcpname_internal_test.go fix(cargo): harden README fetch, clarify status handling, strengthen tests (#1330) 2026-06-04 17:34:54 -04:00
npm.go Use distribution/reference for parsing OCI references (#651) 2025-10-14 15:27:57 +03:00
npm_test.go Fix NPM package validation for scoped packages (#429) 2025-09-11 09:34:57 -07:00
nuget.go security: fix open redirect and add small hardening (#1227) 2026-04-29 19:14:00 -04:00
nuget_test.go Fix NuGet.org base URL default, improve API integration (#813) 2025-12-09 07:19:38 -08:00
oci.go fix(validators/oci): fail closed on upstream rate limiting (#1281) 2026-05-12 16:59:59 -04:00
oci_test.go feat(oci): add support for Quay.io registry (#1150) 2026-04-24 06:11:46 -04:00
pypi.go security: fix open redirect and add small hardening (#1227) 2026-04-29 19:14:00 -04:00
pypi_test.go Extra validation for registries (#484) 2025-09-23 23:05:10 +01:00
testutils_test.go Fix NuGet.org base URL default, improve API integration (#813) 2025-12-09 07:19:38 -08:00