Harden nuget per-request index rewrite #149
Reference in New Issue
Block a user
Delete Branch "benvin/nuget-followups"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
NuGet index rewrites embed the client Host and X-Forwarded-Proto into per-request JSON, so a shared cache could store one host's URLs, a forged header could inject content, HEAD skipped the rewrite, and immutable flat-container blobs were re-validated as mutable.
no-store,Vary: Host, X-Forwarded-Protoand the rewritten Content-Length on GET and HEADv1.Scheme()(first X-Forwarded-Proto value,http/httpsonly) across nuget, cargo, virtual redirects and the terraform registry.snupkg,readmeandiconflat-container blobs as immutablerequires unkin/artifactapi#148 merged first
/remoteHEAD route; oncebenvin/remote-head-routelands, HEAD on a rewritten mutable path reports the raw cached Content-Length, not the rewritten size GET now sends, and skips the host check/no-store/Vary → either land after remote-head-route and route HEAD throughrewriteServed/the same size logic, or drop "HEAD" from the scope. The two branches both rewrite handleProxy (no textual conflict today, semantic gap).scheme()now maps a multi-hopX-Forwarded-Proto: https, http(orHTTPS) tohttp, silently downgrading cargo, github_rpm and virtual URLs behind chained proxies; PR body does not mention these callers → split thescheme()change into its own PR with tests for those handlers, or take the first token and lowercase it (strings.EqualFold).X-Forwarded-Protohandling still trusts any value → reuse the validated helper or note it as follow-up.validHostacceptshost:(empty port) becauseSplitHostPortreturns port "", producinghttp://host:/api/...in the index → reject empty port after a colon.[fe80::1%eth0]) is rejected with 400; unlikely from clients but ParseIP-based check cannot accept it.rewriteServed, no-store/Vary, validHost, JSON escaping, tests)scheme()strictness (affects cargo/github_rpm/virtual).snupkg/readme/icon (nuget.goClassify/ContentType/isPackage)View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.