Skip to content

fix(router): prevent protocol-relative serialized URLs#69873

Closed
carrerasdarren-cell wants to merge 1 commit into
angular:mainfrom
carrerasdarren-cell:fix/routerlink-protocol-relative-href
Closed

fix(router): prevent protocol-relative serialized URLs#69873
carrerasdarren-cell wants to merge 1 commit into
angular:mainfrom
carrerasdarren-cell:fix/routerlink-protocol-relative-href

Conversation

@carrerasdarren-cell

Copy link
Copy Markdown

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.dev application / infrastructure changes
  • Other... Please describe:

What is the current behavior?

A UrlTree containing an empty leading path segment serializes with two leading slashes. For
example, RouterLink commands such as ['/', '', 'attacker.example', 'collect'] produce
//attacker.example/collect. Browsers interpret that href as a protocol-relative external URL,
even though the commands describe an internal route. Preserved or merged query parameters are
also appended to that external URL.

Issue Number: #69700

What is the new behavior?

DefaultUrlSerializer removes empty leading path segments while serializing, so the example above
becomes /attacker.example/collect. This mirrors the parser's existing normalization of repeated
leading slashes and keeps the generated URL on the application's origin.

The regression test covers the command-array path and an appended query parameter. A differential
local harness also compared 4,096 ordinary command arrays with the released serializer; their
serialized output remained byte-for-byte identical.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Formatting and whitespace checks pass. The focused source harness covers ordinary paths, query
parameters, fragments, named outlets, multiple empty leading segments, and browser-origin
resolution.

Normalize empty leading path segments when serializing UrlTrees so a RouterLink href cannot be interpreted as a scheme-relative external URL. This matches the URL parser’s existing leading-slash normalization.

Fixes angular#69700
@pullapprove
pullapprove Bot requested a review from kirjs July 21, 2026 14:16
@ngbot ngbot Bot added this to the Backlog milestone Jul 21, 2026
@JeanMeche
JeanMeche requested review from atscott and removed request for kirjs July 21, 2026 14:20
@SkyZeroZx

Copy link
Copy Markdown
Contributor

I was working on this issue a few days ago.
I just have one suggestion: I think we should add some additional unit tests. You can see them here. SkyZeroZx@e45cf01

@JeanMeche

Copy link
Copy Markdown
Member

We'll review #69874 instead.

@JeanMeche JeanMeche closed this Jul 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants