Repository navigation
Conversation
The `Location` header for a server-side navigation was built by joining the `PlatformLocation` pathname with the search and hash. A pathname may start with `//`, which as a `Location` value is a protocol-relative URL to another origin. The router serializes `/.;/(//example.com)` to `/.//example.com`, dot-segment removal leaves `//example.com`, and a single unauthenticated `GET` returned `302 Location: //example.com`. Any route with a parameter in the first segment and a wildcard child is affected, with no redirect logic in the application. Collapse the leading slashes of the pathname before using it as a location, and normalize the same way in `createRedirectResponse()`, which also prefixes a slash so the value cannot resolve anywhere but the current origin. The collapse consumes tab, line feed and carriage return too: the WHATWG URL parser removes them before parsing, so a client reads `/\t/example.com` as `//example.com`. Tab is a legal header value character and reaches the wire, and prefixing a slash would otherwise turn a leading tab, which the header layer trims, into an inner one that it does not. Fixes #34207
4036867 to
ce252f8
Compare
There was a problem hiding this comment.
Code Review
This pull request introduces a new utility function 'collapseLeadingSlashes' to collapse multiple leading slashes, backslashes, and whitespace characters (like tabs or line feeds) into a single forward slash. This utility is used in Angular SSR's rendering and redirect utilities to prevent open redirect vulnerabilities caused by protocol-relative URLs (e.g., '//example.com'). It also adds comprehensive tests to verify that redirect locations are safely normalized to absolute paths on the current origin. I have no feedback to provide on this pull request.
|
Thanks for investigating this and opening the PR! We’ve reviewed the issue and the proposed changes, and while we want to ensure protocol-relative open redirects cannot occur, we cannot accept this PR in its current form:
Because of this, the underlying issue is being addressed upstream in |
|
This pull request has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
The
Locationheader for a server-side navigation was built by joining thePlatformLocationpathname with the search and hash. A pathname may start with//, which as aLocationvalue is a protocol-relative URL to another origin. The router serializes/.;/(//example.com)to/.//example.com, dot-segment removal leaves//example.com, and a single unauthenticatedGETreturned302 Location: //example.com. Any route with a parameter in the first segment and a wildcard child is affected, with no redirect logic in the application.Collapse the leading slashes of the pathname before using it as a location, and normalize the same way in
createRedirectResponse(), which also prefixes a slash so the value cannot resolve anywhere but the current origin.The collapse consumes tab, line feed and carriage return too: the WHATWG URL parser removes them before parsing, so a client reads
/\t/example.comas//example.com. Tab is a legal header value character and reaches the wire, and prefixing a slash would otherwise turn a leading tab, which the header layer trims, into an inner one that it does not.Fixes angular/angular#71076