fix(ctx): drop unsafe URLs in Redirect#46
Merged
Conversation
Ctx.Redirect previously forwarded any string to the client, so an attacker-controlled value (typical ?next= flows) could yield javascript:, data:, vbscript:, or protocol-relative // open-redirect / XSS frames. Only http, https, and same-origin relative paths are now honoured; everything else is dropped and logged. Leading whitespace and control bytes are trimmed first to match browser scheme parsing.
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
Ctx.Redirectnow validates the URL before queueing a navigation frame: onlyhttp,https, and same-origin relative paths are honoured.javascript:,data:,vbscript:, protocol-relative//…,\\…, and whitespace/case variants are dropped and logged viaapp.logErr.<= ' 'are trimmed before the scheme check to match how browsers parse schemes (javascript:…collapses tojavascript:…).Test plan
go test ./.../tmp/via-verifyapp + curl + Brave): dangerous URLs produced nowindow.location.hrefframe and no browser navigation/alert; safe URLs emitted the expected redirect frame; server log showsRedirect: rejected unsafe URL "…"for every dropped case.