Skip to content

fix: stop treating semicolons as query parameter separators#787

Open
veeceey wants to merge 1 commit intogorilla:mainfrom
veeceey:fix/remove-semicolon-query-separator
Open

fix: stop treating semicolons as query parameter separators#787
veeceey wants to merge 1 commit intogorilla:mainfrom
veeceey:fix/remove-semicolon-query-separator

Conversation

@veeceey
Copy link

@veeceey veeceey commented Feb 10, 2026

Summary

Security context

When findFirstQueryKey splits on ;, an attacker can craft a URL like ?a;id=42&id=1 where:

  • 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 on mux.Vars().

Test plan

  • All existing tests pass (go test ./...)
  • New Test_findFirstQueryKey_semicolonIsNotSeparator test verifies:
    • Semicolons in values are not treated as separators (a=1;b=2 -> key a has value 1;b=2)
    • No parser differential with net/url (a;id=42&id=1 -> key id resolves to 1)
    • Mixed semicolons and ampersands only split on ampersands
  • go vet ./... passes cleanly

🤖 Generated with Claude Code

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Semicolon unduly acts as separator for query parameters (thereby creating a parser differential)

1 participant