Repository navigation
fix!: deny percent-encoded request paths (#53) - #59
Merged
Merged
Conversation
The Docker daemon decodes the request path before routing, so an escaped path such as DELETE /containers/%2F or /containers/foo%20bar reached a different endpoint or container than the one the proxy's router checked. The router now denies any request whose path, with the query string removed, contains '%'. It is the first check in Route, ahead of the API-version strip and the GET/HEAD passthrough, and applies to every method. The query string is never inspected, so encoded filters still work. The Go handler routes on r.URL.EscapedPath() instead of the already-decoded r.URL.Path, and logs/audits that same path. BREAKING CHANGE: requests whose path contains '%' are denied with 403 for every method; network names containing spaces or '%' can no longer be inspected or removed through the proxy.
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.
Description
The three implementations disagreed about percent-encoded paths, and in all of them the proxy could read a request differently from the daemon, which percent-decodes before routing:
r.URL.Path.uri.path()) and TypeScript (req.url) routed on the raw path.DELETE /containers/%2Fwas denied in Go (decoded to an empty name, Rust extract_container_name treats empty segment as a container name (DELETE /containers/ is forwarded) #48) but allowed and forwarded by Rust and TS.POST /containers/%2F/startwas allowed by the Rust and TS handlers as an "unknown container" (and by Go's router when given the raw path), while the daemon reads it asPOST /containers///start.Rule: any request whose path contains
%is denied with 403 (percent-encoded path not allowed). This applies to every method, GET and HEAD included. It is the first check inRoutein all three implementations, before the API-version strip and the GET/HEAD passthrough. The query string is not inspected. Go's handler now routes onr.URL.EscapedPath()instead of the decoded path.Closes #53
Why this rule (evidence in #53)
A wire capture of Docker CLI 29.4.0 shows:
%is routine in query strings:ps --filter,cp,tag.%appears only for network names that need escaping. Container and volume names are limited to[a-zA-Z0-9][a-zA-Z0-9_.-], and image references are sent unescaped.Routing on the decoded path (the issue's original proposal) was rejected. It would need every decoding rule to match the daemon's exactly, and no legitimate container or image path needs
%.Breaking change
docker network inspect <name>through the proxy now gets 403 for network names that need percent-encoding (for example a space or%). Inspecting by network ID still works, and other network operations were already denied. Release note: the release pipeline always bumps the patch version and--generate-noteswon't surface theBREAKING CHANGE:footer (#54), so state this change by hand in the release notes. Go also denies paths with raw characters it must re-encode, such as non-ASCII bytes or{; the Docker CLI never sends these. Documented in the README "Endpoint Access" section.Spec first (
spec/router.qnt)route.routerSeesWhatDaemonSees: any path the router does not deny reads the same after the daemon decodes it. It ranges over GET, POST and DELETE, which is why the rule covers GET.router_pre53(Rust/TS before this fix, routing raw paths), wherepre53UnsoundTestasserts that the property fails.percentSlashDeleteDeniedpercentLowerSlashDeleteDeniedpercentReservedDeleteDenied(%6A%73%6F%6E=json)percentNameStartDeniedpercentSubpathStartDenied(a pin)percentGetDeniedrouter,percentSoundTestand 5 of the 6 rows fail.Tests (written first; RED commits
fc17c2e,32aacf6)DELETE /v1.45/containers/foo%25,DELETE /v%31/containers/foo,GET /networks/a%20bandHEAD /containers/%2F, all → Deny.DELETE /containers/foo→ Allow.percent-encoded. So before the fix every deny row failed for the Percent-encoded container names: Go routes on the decoded path, Rust/TS on the raw path #53 reason, including the rows that some other rule already denied.GET /containers/json?filters=%7B%7DandDELETE /containers/foo?force=%31→ Allow. Only TS's router receives the query.DELETE /containers/foo%20bar→ 403, not forwarded. This catches a Go fix that only touches the router while the handler still decodes.DELETE /containers/%2F→ 403, not forwarded.GET /containers/json?filters=…→ forwarded, with the query unchanged.deploy/test.sh, 36 → 39 checks:DELETE /containers/no-such%20x→ 403DELETE /containers/%2F→ 403GET /v1.45/containers/json?filters=…→ 200Docker CLI smoke test (Go proxy → OrbStack daemon)
docker ps --filter status=running→ exit 0.docker network inspect 'a b'→percent-encoded path not allowed.docker version→ exit 0.Follow-ups recorded
urifield differs across languages (pre-existing), and there is no formatter check in lint.Squash-merge required: the RED commits fail by design.
Type of change
Implementation(s) changed
deploy/test.sh,Makefiletest-spec)Testing
make test-all): Go 107, Rust 144, TS 161 (160 pass, 1 skipped)make test-spec(above).make verifyexit 0 locally (Task 1) and runs in CI.make lint-allexits 0Checklist
spec/README.md, AGENTS.md counts)