fix: stop treating semicolons as query parameter separators#787
Open
veeceey wants to merge 1 commit intogorilla:mainfrom
Open
fix: stop treating semicolons as query parameter separators#787veeceey wants to merge 1 commit intogorilla:mainfrom
veeceey wants to merge 1 commit intogorilla:mainfrom
Conversation
Since Go 1.17, net/url.ParseQuery no longer splits query parameters on semicolons, in compliance with the URL Living Standard. However, findFirstQueryKey still used bytes.IndexAny(foundKey, "&;") which split on both ampersands and semicolons. This created a parser differential between mux.Vars and net/url that could lead to security vulnerabilities such as broken access control and web cache poisoning. Change bytes.IndexAny(foundKey, "&;") to bytes.IndexByte(foundKey, '&') so that only ampersands are recognized as separators. Fixes gorilla#781 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
Summary
findFirstQueryKeypreviously split query parameters on both∧(bytes.IndexAny(foundKey, "&;")), but Go'snet/urlstopped treating semicolons as separators in Go 1.17, per the URL Living Standard. This created a parser differential betweenmux.Vars(r)andr.URL.Query()that could lead to security vulnerabilities (broken access control, web cache poisoning via query-parameter cloaking).bytes.IndexAny(foundKey, "&;")tobytes.IndexByte(foundKey, '&')so only ampersands are recognized as query-parameter separators.Security context
When
findFirstQueryKeysplits on;, an attacker can craft a URL like?a;id=42&id=1where:r.URL.Query().Get("id")returns"1"(net/url ignores the semicolon-separated part)mux.Vars(r)["id"]returned"42"(mux split on the semicolon)This differential can bypass authorization checks that use
r.URL.Query()while the handler acts onmux.Vars().Test plan
go test ./...)Test_findFirstQueryKey_semicolonIsNotSeparatortest verifies:a=1;b=2-> keyahas value1;b=2)a;id=42&id=1-> keyidresolves to1)go vet ./...passes cleanly🤖 Generated with Claude Code