Repository navigation
Conversation
Handlers check the path decoded once and append the same string to the upstream URL, where the upstream decodes it again. rails-7.0.%2530.gem was checked as version 7.0.%30 and fetched as 7.0.0, past the denylist and cooldown. Such paths now get 400 before any handler runs.
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Problem
Most handlers parse the request path decoded once and append that same string to the upstream URL. A path escaped twice is decoded once more by the upstream, so the proxy checks one name and fetches another:
GET /gem/gems/rails-7.0.%2530.gemis checked as version7.0.%30, which no denylist entry names and no index lists, and is fetched asrails-7.0.0.gem.GET /pypi/packages/…/requests-2.31.0.tar.g%257ahas no known extension, so no name is parsed and the checks are skipped.That gets a denied version past the denylist, and for the ecosystems that allow a version their index doesn't list, a version in cooldown too. The file is cached under the made-up version, so no real cache entry is overwritten.
rejectQueryInPathandrejectDotSegmentsalready close the same gap for?,#,;and dot segments.Change
rejectDoubleEscapedPathreturns 400 when the decoded path still holds a percent-escape (%and two hex digits). It runs on the same routes asrejectQueryInPath, with the same Composer archive exemption. The generic handler is not included: it forwards the escaped path as sent.A path escaped once is unaffected (
%40types%2Fnode,libstdc%2B%2B6), and so is a%that doesn't start an escape. A file whose real name contains an escape could not be fetched before either, since the upstream URL decoded it.Tests
TestProtocolHandlersRejectDoubleEscapedPathsends such a path to gem, hex, pypi, maven, go, cran, conda, nuget, conan, debian, rpm, apk, npm, cargo, helm and the container routes through the mounted router: 400, and no upstream request. It fails without the guard.TestDoubleEscapeGuardKeepsSingleEscapeskeeps single escapes, a bare%and Composer archives passing.go test ./internal/server/ ./internal/handler/andgolangci-lint run ./internal/server/pass.Summary by CodeRabbit