Skip to content

security: harden same-site URL check against redirect bypass - #8322

Merged
unknwon merged 6 commits into
mainfrom
ghsa-xxhq-69mf-w8cr
Jun 5, 2026
Merged

unknwon merged 6 commits into
mainfrom
ghsa-xxhq-69mf-w8cr

Conversation

@unknwon

@unknwon unknwon commented Jun 5, 2026

Copy link
Copy Markdown
Member

Summary

Harden the same-site URL validation used by redirect_to flows so it cannot be tricked into approving cross-origin destinations.

Test plan

  • go test ./internal/urlx/...
  • moon run gogs:lint
  • New test cases cover the reported bypass and several variants.

Refs GHSA-xxhq-69mf-w8cr.

unknwon added 6 commits June 5, 2026 09:10
The same-site check used for redirect_to validation only inspected the
first two bytes of the URL. Inputs like "/a/../\example.com" passed,
and browsers normalize backslashes to forward slashes, turning the
result into "//example.com" and producing a cross-origin redirect.

Parse the URL, reject any scheme or host, reject backslashes in both
the raw input and the decoded path, and resolve "." and ".." segments
before approving the path.
Drop the path.Clean and explicit backslash-in-input checks. Normalize
backslashes to forward slashes (matching what browsers do on Location
headers), then require the parsed result to be a relative URL whose path
starts with a single "/" and contains no "//" runs.
A literal substring check suffices once backslashes (raw and
percent-encoded) are normalized to forward slashes. Anything with a
scheme or host either does not start with "/" or starts with "//",
both of which the existing checks already reject.
@unknwon
unknwon merged commit c5da963 into main Jun 5, 2026
8 checks passed
@unknwon
unknwon deleted the ghsa-xxhq-69mf-w8cr branch June 5, 2026 13:59
@unknwon unknwon added this to the 0.14.3 milestone Jun 5, 2026
unknwon added a commit that referenced this pull request Jun 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant