Skip to content

Validate redirect middleware Location URLs - #3219

Open
kevin9327 wants to merge 1 commit into
labstack:masterfrom
kevin9327:fix-redirect-open-redirect
Open

kevin9327 wants to merge 1 commit into
labstack:masterfrom
kevin9327:fix-redirect-open-redirect

Conversation

@kevin9327

Copy link
Copy Markdown

The host and www redirect middlewares built Location by concatenating req.Host and req.RequestURI. A Host of www. plus a path such as /attacker.com/login produced https:///attacker.com/login, which browsers normalize to an off-site URL (CWE-601). The www. prefix check was case-sensitive, absolute-form request URIs were not sanitized the way AddTrailingSlash already does, and a forwarded ws/wss scheme could be copied into the redirect.

The middleware now sanitizes the URI, strips www. case-insensitively, maps ws/wss back to http/https, and rejects a redirect whose host is empty or contains authority delimiters.

Fixes #3217

The host/www redirect middlewares concatenated req.Host and
req.RequestURI into Location without checking the host or sanitizing
the URI. A Host of "www." plus a path such as /attacker.com/login
produced https:///attacker.com/login, which browsers treat as an
open redirect. The www. prefix match was also case-sensitive, and
a forwarded ws/wss scheme could be copied into the Location.

Validate the host after construction, strip www. case-insensitively,
sanitize the URI the same way as the slash middleware, and map ws/wss
back to http/https.

Fixes labstack#3217
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.

middleware/redirect: prevent open redirect (CWE-601) via malformed Host, unsanitized RequestURI, and non-HTTP schemes

1 participant