Title: @angular/ssr: the route matcher and @angular/router disagree, so per-route headers, status and renderMode come from a different route than the one rendered · Issue #34090 · angular/angular-cli · GitHub
Open Graph Title: @angular/ssr: the route matcher and @angular/router disagree, so per-route headers, status and renderMode come from a different route than the one rendered · Issue #34090 · angular/angular-cli
X Title: @angular/ssr: the route matcher and @angular/router disagree, so per-route headers, status and renderMode come from a different route than the one rendered · Issue #34090 · angular/angular-cli
Description: Command build Is this a regression? No Description @angular/ssr matches every incoming request twice, with two different tokenisers, and lets the two answers disagree. ServerRouter.match() picks the response's headers, status, renderMode...
Open Graph Description: Command build Is this a regression? No Description @angular/ssr matches every incoming request twice, with two different tokenisers, and lets the two answers disagree. ServerRouter.match() picks th...
X Description: Command build Is this a regression? No Description @angular/ssr matches every incoming request twice, with two different tokenisers, and lets the two answers disagree. ServerRouter.match() picks th...
Opengraph URL: https://github.com/angular/angular-cli/issues/34090
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"@angular/ssr: the route matcher and @angular/router disagree, so per-route headers, status and renderMode come from a different route than the one rendered","articleBody":"### Command\n\nbuild\n\n### Is this a regression?\n\nNo\n\n### Description\n\n`@angular/ssr` matches every incoming request **twice, with two different tokenisers**, and lets the two answers disagree.\n\n`ServerRouter.match()` picks the response's `headers`, `status`, `renderMode` and `preload` using `RouteTree.getPathSegments()` (`packages/angular/ssr/src/routes/route-tree.ts`):\n\n```ts\nprivate getPathSegments(route: string): string[] {\n return route.split('/').filter(Boolean).map(decodeURIComponent);\n}\n```\n\n`@angular/router` picks the component that renders into the response **body** using `DefaultUrlSerializer`, a grammar in which `(`, `)`, `;` and `//` are metacharacters and unparseable input is silently discarded.\n\nAppending a single character to a path therefore produces a response whose **body is route A** and whose **cache policy, security headers, status and render mode come from route B**.\n\nThe `@angular/router` side is intentional and is not the bug. `(name:seg)` is the documented secondary-outlet syntax, `;k=v` the documented matrix-parameter syntax, and d4d6c280 (`fix(router): handle parenthesized outlets without a name in DefaultUrlSerializer`, #64507) deliberately made an unnamed `(...)` group mean the primary outlet. `@angular/ssr` implements none of that grammar.\n\nVerified against the published `@angular/router` 22.1.6, `serialize(parse(x))`:\n\n| input | router resolves to |\n|---|---|\n| `/priv)` | `/priv` |\n| `/priv(` | `/priv` |\n| `/priv;` | `/priv` |\n| `/(priv)` | `/priv` |\n| `/priv/1//y` | `/priv/1` |\n| `/a/b)c/d` | `/a/b` |\n\n**This project has already patched one case of this class.** 85c18b4e (`fix(@angular/ssr): correctly handle routes with matrix parameters`, closes #31457) added `stripMatrixParams` because URLs with matrix parameters failed to match their route. That is the same divergence surfacing as a functional bug. Parentheses and interior `//` are the remaining cases, and the general fix is smaller than the third special case would be.\n\n**What is affected:** the per-route `headers`, `status` and `renderMode` declared in `app.routes.server.ts` are taken from a different route than the one that renders. `headers` is also spread last in `handleRendering`, after `Content-Type`, so those are attacker-selected too.\n\n**What is NOT affected, stated plainly:** `canActivate` and the other router guards still run, because `@angular/router` sees an ordinary path. This is not an authorization bypass and I am not claiming one. What is bypassed is the response policy and the render-mode directive.\n\n### Minimal Reproduction\n\n```\nng new ssrlab --ssr --defaults && cd ssrlab\n```\n\n`src/app/app.routes.ts`: client routes `pub`, `priv`, `priv/:id`, `privc`, `priv/:id/share`, each pointing at a component that renders a marker naming its own `routeConfig.path`, plus `{ path: '**', component: NotFound }`.\n\n`src/app/app.routes.server.ts`:\n\n```ts\nconst PRIVATE_HEADERS = {\n 'Cache-Control': 'no-store, private',\n 'X-Frame-Options': 'DENY',\n 'Content-Security-Policy': \"frame-ancestors 'none'\",\n};\n\nexport const serverRoutes: ServerRoute[] = [\n { path: 'pub', renderMode: RenderMode.Server, headers: { 'Cache-Control': 'public, max-age=600' } },\n { path: 'priv', renderMode: RenderMode.Server, headers: PRIVATE_HEADERS },\n { path: 'priv/:id', renderMode: RenderMode.Server, headers: PRIVATE_HEADERS },\n { path: 'privc', renderMode: RenderMode.Client, headers: PRIVATE_HEADERS },\n { path: 'priv/:id/share', renderMode: RenderMode.Server, headers: { 'Cache-Control': 'public, max-age=31536000, immutable' } },\n { path: '**', renderMode: RenderMode.Server, headers: { 'Cache-Control': 'public, max-age=600' } },\n];\n```\n\n```\nng build && PORT=4111 node dist/ssrlab/server/server.mjs\ncurl -sD - --path-as-is 'http://127.0.0.1:4111/priv'\ncurl -sD - --path-as-is 'http://127.0.0.1:4111/priv)'\n```\n\n`policy_from` below is read off the response headers, `rendered` off the response body.\n\n```\n--- canonical spelling of each route ---\n/pub 200 policy_from=public Cache-Control=public, max-age=600 X-Frame-Options=- rendered=pub\n/priv 200 policy_from=private Cache-Control=no-store, private X-Frame-Options=DENY rendered=priv\n/priv/1 200 policy_from=private Cache-Control=no-store, private X-Frame-Options=DENY rendered=priv/:id\n/privc 200 policy_from=private Cache-Control=no-store, private X-Frame-Options=DENY rendered=\u003cnot server-rendered>\n/nope 200 policy_from=wildcard Cache-Control=public, max-age=600 X-Frame-Options=- rendered=\u003cnot server-rendered>\n\n--- same routes, spelled so the two matchers disagree ---\n/priv) 200 policy_from=wildcard Cache-Control=public, max-age=600 X-Frame-Options=- rendered=priv\n/priv( 200 policy_from=wildcard Cache-Control=public, max-age=600 X-Frame-Options=- rendered=priv\n/priv; 200 policy_from=wildcard Cache-Control=public, max-age=600 X-Frame-Options=- rendered=priv\n/(priv) 200 policy_from=wildcard Cache-Control=public, max-age=600 X-Frame-Options=- rendered=priv\n/priv/1//y 200 policy_from=wildcard Cache-Control=public, max-age=600 X-Frame-Options=- rendered=priv/:id\n/privc) 200 policy_from=wildcard Cache-Control=public, max-age=600 X-Frame-Options=- rendered=privc\n```\n\n`GET /priv)` is one appended character. It replaces `no-store, private` with `public, max-age=600`, drops `X-Frame-Options: DENY` and `Content-Security-Policy: frame-ancestors 'none'`, and on `/privc)` server-renders a route whose configuration says `RenderMode.Client`.\n\nThe mangled path is not restricted to falling through to the catch-all. The mangled segment list is matched normally, so any route pattern that fits it is selectable:\n\n```\n/priv/1 policy_from=private Cache-Control=no-store, private rendered=priv/:id\n/priv/1/share policy_from=share Cache-Control=public, max-age=31536000, immutable rendered=priv/:id/share\n/priv/1//share policy_from=share Cache-Control=public, max-age=31536000, immutable rendered=priv/:id\n```\n\nLine three renders the account page under the public sub-route's cache policy.\n\n### Exception or Error\n\nNone. Nothing throws and nothing is logged; both matchers succeed and return different answers. That is what makes it hard to notice in an application's own tests.\n\n### Your Environment\n\n```\n@angular/ssr 22.1.8 (latest on npm at time of testing)\n@angular/router 22.1.6 (latest)\nfiles: packages/angular/ssr/src/routes/route-tree.ts, packages/angular/ssr/src/routes/router.ts\n```\n\n### Anything else relevant?\n\n**Scope.** A differential sweep of 1575 paths against the running server produced 80 divergent paths in two root shapes: parenthesis/semicolon, and interior `//`. Enumerated over printable ASCII, the single-character triggers are `(`, `)` and `;`. All three are legal path characters that proxies and CDNs forward unchanged.\n\n**Suggested fix.** `@angular/ssr` already peer-depends on `@angular/router`, so normalising the pathname through the router's own grammar before tokenising makes the two matchers agree, in `ServerRouter.match`:\n\n```ts\nimport { DefaultUrlSerializer } from '@angular/router';\n\nprivate static readonly serializer = new DefaultUrlSerializer();\n\nprivate static normalize(pathname: string): string {\n try {\n const s = ServerRouter.serializer.serialize(ServerRouter.serializer.parse(pathname));\n const cut = s.search(/[?#]/);\n\n return cut === -1 ? s : s.slice(0, cut);\n } catch {\n return pathname; // malformed percent-encoding keeps today's behaviour\n }\n}\n\nmatch(url: URL): RouteTreeNodeMetadata | undefined {\n let { pathname } = stripIndexHtmlFromURL(url);\n pathname = stripMatrixParams(ServerRouter.normalize(pathname));\n\n return this.routeTree.match(pathname);\n}\n```\n\nChecked against the payload set and a calibration set: the divergent paths collapse onto the canonical route, and `/priv`, `/pub`, `/pub/1`, `/nope`, `/a%2Fb`, `/%zz` and `/priv/./x` tokenise exactly as they do today.\n\n**Known residual of that fix:** an application supplying a custom `UrlSerializer` still diverges, because the normalisation uses `DefaultUrlSerializer`. The durable fix is to build and query the route tree through the serializer the application injects. I am happy to open a PR with either shape.\n\n**Prior art checked.** All six `angular/angular-cli` security advisories; the five SSR ones concern `X-Forwarded-Prefix`, `createRequestUrl` and `CommonEngine` path traversal, none concerns route matching. Open PR #33248 centralises URL normalisation for prerender redirects, `Location` headers and the server manifest, but does not touch `routes/router.ts` or `routes/route-tree.ts`.\n\n**Reporting history.** Submitted to the Google OSS VRP as issue 559764571 on 2026-09-10. It was triaged and assigned, and the Bug Hunter Team invited public disclosure here on 2026-09-14. Filing it publicly at their request.\n\n**Disclosure.** This report and its testing were produced with AI assistance. Every claim in it was executed against a real production build of `@angular/ssr` 22.1.8 and `@angular/router` 22.1.6 rather than reasoned about, and the differential sweep carried a calibration set that showed no divergence.\n","author":{"url":"https://github.com/glivter","@type":"Person","name":"glivter"},"datePublished":"2026-09-14T20:37:26Z","url":"https://github.com/angular/angular-cli/issues/34090"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:f6afa12b-2e17-2e3b-0190-f1cd01b71bfc |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CCF4:20A6C3:808DB:B7F3D:6AFDC69B |
| html-safe-nonce | 87d477d53500913a25a7e8acb7b990320f9eae259d1fa85f28ded2df24ee63c7 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQ0Y0OjIwQTZDMzo4MDhEQjpCN0YzRDo2QUZEQzY5QiIsInZpc2l0b3JfaWQiOiI0Njc3MTc1NDc1MzkzMzgyMDQzIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 8e415bd9367b313f47167948a954c605ae34f7b0dcda9c0fb791b02551e203ed |
| hovercard-subject-tag | issue:5454355591 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/angular/angular-cli/34090/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f14413e9c9b67e67c9c65f85ce9220bb572e098b446475aff5086e0dba026ef6/angular/angular-cli/issues/34090 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f14413e9c9b67e67c9c65f85ce9220bb572e098b446475aff5086e0dba026ef6/angular/angular-cli/issues/34090 |
| og:image:alt | Command build Is this a regression? No Description @angular/ssr matches every incoming request twice, with two different tokenisers, and lets the two answers disagree. ServerRouter.match() picks th... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | glivter |
| hostname | github.com |
| expected-hostname | github.com |
| None | 9ab00cc3b4fa90bbd3da70765dd38efc23cfa9d9b0930e41feea2bf67f60ecaf |
| turbo-cache-control | no-preview |
| go-import | github.com/angular/angular-cli git https://github.com/angular/angular-cli.git |
| octolytics-dimension-user_id | 139426 |
| octolytics-dimension-user_login | angular |
| octolytics-dimension-repository_id | 36891867 |
| octolytics-dimension-repository_nwo | angular/angular-cli |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 36891867 |
| octolytics-dimension-repository_network_root_nwo | angular/angular-cli |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 1b795ba060b92691fc16c5a12cf2bf95e83432b4 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width