fix(nuget): harden README fetch with body size limit + redirect host-pinning#1398
Open
SaurabhMaydeo wants to merge 1 commit into
Open
fix(nuget): harden README fetch with body size limit + redirect host-pinning#1398SaurabhMaydeo wants to merge 1 commit into
SaurabhMaydeo wants to merge 1 commit into
Conversation
…pinning validateReadme read the package README via io.ReadAll with no size cap, and the shared http.Client had no CheckRedirect. Bound the read with io.LimitReader (5 MiB) and pin every redirect hop to the originating request's host (and, for the real NuGet base, forbid scheme/port downgrades), so an oversized or redirected upstream response can't exhaust validator memory or be steered at an unexpected host. NuGet serves the service index, README, and package index directly without cross-host redirects, so this is behaviour-preserving for real packages. Mirrors the cargo hardening from modelcontextprotocol#1330. Adds tests for README truncation and cross-host redirect refusal.
807b2ee to
d6151d9
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Follow-up to #1330, applying the same README-fetch hardening to the NuGet validator. Scoped to NuGet — no behavior change for existing publishers.
NuGet and cargo are the only validators that read a raw README body (npm/pypi decode JSON metadata directly), so this finishes the pair started in #1330.
Changes
io.LimitReader(5 MiB, matchingmaxCargoReadmeBytes), so an oversized response can't exhaust validator memory.nugetRedirectAllowed) with a table test, mirroring cargo'scargoURLAllowed/TestCargoURLAllowed.NuGet has no separate README CDN host like cargo's
static.crates.io: the README URL is built from the service-indexReadmeUriTemplateand served from the same host. So redirects are pinned to the request's own host rather than a static allowlist. If NuGet ever serves READMEs cross-host, this would need to become an allowlist like cargo's.Test plan
go test ./internal/validators/registries/(incl. existing live-API tests)TestNuGetRedirectAllowed(cross-host, http-downgrade, non-default-port, metadata-IP, userinfo) + httptest tests for README truncation at the cap and cross-host redirect refusalgofmt,go vet, andgolangci-lint v2.11.4(the version CI pins) all clean — 0 issuesDocker/Postgres integration tests run in CI.