fix(validators): harden mcp-name matching (PyPI/NuGet anchoring, comment-form safe) + cargo follow-ups (#1331)
Registry-wide hardening of the `mcp-name:` ownership-token match, plus the cargo follow-up fixes from the #1330 review — consolidated here per maintainer request. Rebased onto current `main` (the merged #1330 cargo commit drops out), so the diff is just the net-new work. ### Changes - **PyPI/NuGet: boundary-anchored token match.** Replace `strings.Contains(readme, "mcp-name: "+name)` with the shared `containsMCPNameToken`, so a README declaring a longer name (`…/widget-pro`) no longer satisfies an ownership claim for a shorter prefix (`…/widget`). (Cargo already got this in #1330; NPM is unaffected — it compares an exact metadata field.) - **Matcher: treat the HTML comment close as a boundary.** `<!-- mcp-name: NAME-->` / `<!--mcp-name: NAME-->` (any spacing) validate again — the documented hidden-comment form for PyPI/NuGet — while a genuine longer name (`…/widget--pro`) still does not. - **Cargo hardening (review of #1330):** pin scheme+port (not just host) on the README fetch and redirects; a rate-limited/failed crate-version existence probe now reports *transient* instead of "not found"; a 403 with the crate present no longer flatly asserts "no README". - **Docs:** note the token must be followed by a boundary. ### ⚠️ Behavior change for PyPI/NuGet — read before merging The match is **strictly stricter** (verified by fuzz, 2.3M execs: it can only flip pass→fail, never fail→pass). After the comment-close fix, the **only** forms that newly fail are unusual *inline* ones: the token ending a sentence (`…/my-mcp.`) or glued to a trailing `/`. The documented forms (own line, in `<!-- … -->`) are unaffected. **Correcting an earlier claim:** this re-validates on **edits too**, not just new versions — `edit.go → UpdateServer → ValidateUpdateRequest → validateRegistryOwnership` runs the token check on any edit of a live server (only delete-transitions skip it). So an existing PyPI/NuGet server whose README uses one of the breaking inline forms would fail on its next publish *or* edit. Given the v0.1 API-freeze posture, this should land as a deliberate, noted change. ### Testing `go build`, `vet`, `gofmt`, `golangci-lint` (prod files), `check-schema`, `validate-examples` all clean. Hermetic + **live** PyPI/NuGet/cargo suite passes. New: `TestCargoURLAllowed`, a combined-fixture probe-429→transient case, comment-form matcher cases, and `FuzzContainsMCPNameToken` (the strictly-stricter property, 2.3M execs). 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
7a6d1bc30a
commit
04623ed925
1 changed files with 312 additions and 55 deletions
|
|
@ -51,6 +51,9 @@ type ReadmeState int
|
|||
const (
|
||||
ValidReadme ReadmeState = iota
|
||||
InvalidReadme
|
||||
// GluedReadme: the literal token is present but glued to a trailing character
|
||||
// (so the boundary-anchored match rejected it as a prefix of a longer name).
|
||||
GluedReadme
|
||||
NoReadme
|
||||
)
|
||||
|
||||
|
|
@ -99,6 +102,8 @@ func ValidateNuGet(ctx context.Context, pkg model.Package, serverName string) er
|
|||
return nil
|
||||
case InvalidReadme:
|
||||
return fmt.Errorf("NuGet package '%s' ownership validation for version %s failed. The server name '%s' must appear as 'mcp-name: %s' in the package README. Add it to your README and publish a new package version", pkg.Identifier, pkg.Version, serverName, serverName)
|
||||
case GluedReadme:
|
||||
return fmt.Errorf("NuGet package '%s' ownership validation for version %s failed: found 'mcp-name: %s' in the README, but it is immediately followed by another character rather than a boundary. The token must be followed by a space, newline, an HTML tag, or a comment close ('-->') — put it on its own line and publish a new package version", pkg.Identifier, pkg.Version, serverName)
|
||||
case NoReadme:
|
||||
// Continue to check if package exists
|
||||
default:
|
||||
|
|
@ -237,10 +242,13 @@ func validateReadme(ctx context.Context, serverName, lowerID, lowerVersion strin
|
|||
|
||||
readmeContent := string(readmeBytes)
|
||||
|
||||
// Check for mcp-name: format (more specific)
|
||||
mcpNamePattern := "mcp-name: " + serverName
|
||||
if strings.Contains(readmeContent, mcpNamePattern) {
|
||||
return ValidReadme, nil // Found as mcp-name: format
|
||||
// Check for the mcp-name: <server-name> ownership token (boundary-anchored
|
||||
// to avoid prefix confusion — see containsMCPNameToken).
|
||||
if containsMCPNameToken(readmeContent, serverName) {
|
||||
return ValidReadme, nil
|
||||
}
|
||||
if _, glued := mcpNameTokenGluedTrailing(readmeContent, serverName); glued {
|
||||
return GluedReadme, nil
|
||||
}
|
||||
|
||||
return InvalidReadme, nil
|
||||
|
|
|
|||
Loading…
Reference in a new issue