Title: Angular SSR prerender chunk-name collision desynchronizes Content-Length and contaminates other users' responses behind a proxy · Issue #34722 · angular/angular-cli · GitHub
Open Graph Title: Angular SSR prerender chunk-name collision desynchronizes Content-Length and contaminates other users' responses behind a proxy · Issue #34722 · angular/angular-cli
X Title: Angular SSR prerender chunk-name collision desynchronizes Content-Length and contaminates other users' responses behind a proxy · Issue #34722 · angular/angular-cli
Description: Command build Is this a regression? Yes, this behavior used to work in the previous version The previous version in which this bug was not present was No response Description This is another piece of the prerender path from #34474 and #3...
Open Graph Description: Command build Is this a regression? Yes, this behavior used to work in the previous version The previous version in which this bug was not present was No response Description This is another piece ...
X Description: Command build Is this a regression? Yes, this behavior used to work in the previous version The previous version in which this bug was not present was No response Description This is another piece ...
Opengraph URL: https://github.com/angular/angular-cli/issues/34722
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Angular SSR prerender chunk-name collision desynchronizes Content-Length and contaminates other users' responses behind a proxy","articleBody":"### Command\n\nbuild\n\n### Is this a regression?\n\n- [ ] Yes, this behavior used to work in the previous version\n\n### The previous version in which this bug was not present was\n\n_No response_\n\n### Description\n\n\nThis is another piece of the prerender path from #34474 and #34569, which I reported. #34493 escaped the manifest key and the `import()` specifier, and #34570 validates the parameter values, but the chunk's file name still goes through its own `replace`, and two different pages can end up with the same one:\n\nhttps://github.com/angular/angular-cli/blob/72f44d79cb577821bbfa849f5bb3b41eee87c2ab/packages/angular/build/src/utils/server-rendering/manifest.ts#L173\n\nSo `legal/privacy/index.html` and `legal_privacy/index.html` get the same file, and the later one replaces the earlier:\n\nhttps://github.com/angular/angular-cli/blob/72f44d79cb577821bbfa849f5bb3b41eee87c2ab/packages/angular/build/src/builders/application/execute-post-bundle.ts#L221-L228\n\nThe manifest still has both pages, each with its own `size` and `hash`, and the server sends those with whatever the shared file holds:\n\nhttps://github.com/angular/angular-cli/blob/72f44d79cb577821bbfa849f5bb3b41eee87c2ab/packages/angular/ssr/src/app.ts#L233-L246\n\nN pages in the manifest, N - 1 files in `dist`, and `ng build` exits 0 with no warning.\n\nThose paths come from `getPrerenderParams()`, which is application data: the docs read it from a service, and [GHSA-w34w-96hf-98hj](https://github.com/angular/angular-cli/security/advisories/GHSA-w34w-96hf-98hj) says it \"commonly fetches dynamic identifiers or slugs from an external API, CMS, or database\". Anyone who can create one record can take the chunk of a page that already exists. The app in the repro uses the workaround from that advisory as it is, allowlist `/^[a-zA-Z0-9-_]+$/` included, and its store also caps the length, reserves names and rejects duplicates ignoring case. These records still pass, and so does the #34570 validator, because `legal_privacy` and `legal/privacy` only become equal inside that `replace`:\n\n| Records created through the app's API | Page that is lost | Result |\n| ------------------------------------------- | --------------------------------------------- | ----------------------------------------------------------------------- |\n| account `legal_privacy` | the site's `/legal/privacy` | the URL serves the attacker's profile |\n| account `acme`, project `docs_intro` | `/acme_docs/intro`, another account's project | the URL serves `acme/docs_intro` |\n| `mallory_dev/tools` and `mallory/dev_tools` | `/mallory/dev_tools` | behind nginx with a cache, one request puts their script on every URL |\n\nIt only needs routes that can make a pair: two parameters (`:user/:project`), a root `:user` next to a static page two segments deep, or two parameter routes of different depth under one prefix, like the SSR guide's own `post/:id` and `post/:id/**`, where the id `1_foo_3` takes the chunk of `post/1/foo/3`. Names that differ only in `.`, `_` and `/` aren't rare either: npm has [rejected them since 2017](https://blog.npmjs.org/post/168978377570/new-package-moniker-rules) and PyPI [normalizes](https://packaging.python.org/en/latest/specifications/name-normalization/) them, and among the 4,681,490 public npm names 697 groups would still lose a page under `:name` and `:scope/:name`.\n\n**1. The lost page.** `/legal/privacy` answers 200 with the attacker's profile, under the length and the `ETag` of the page that's gone:\n\n```text\n$ curl -s -D- http://localhost:4000/legal/privacy stalls 6.06 s, then curl: (18)\ncontent-length: 2647\netag: \"85d6085a71e5686e\"\n\u003ctitle>Profile of legal_privacy\u003c/title>\n\u003ch1>legal_privacy\u003c/h1>\u003cp>Our privacy policy has moved.\u003c/p>\u003ca href=\"https://legal-privacy.example.test/\">Website\u003c/a>\n```\n\nThe body is 1,375 bytes, so the document never finishes loading. Chrome 156 keeps the profile on screen and Angular never boots to replace it. `If-None-Match` with that `ETag` gets a 304, and it still does after the record is deleted and the site rebuilt: a Chrome profile that visited during the collision kept the attacker's page on the fixed build until a forced reload. On `/acme_docs/intro` a browser shows the right project once Angular boots, but crawlers and link previews keep the other account's.\n\n**2. Which of the two survives.** The build machine decides, not the content. Prerendering uses `max(availableParallelism() - 1, 1)` workers, so on 2 CPUs there's one worker and nothing races: 10 of 10 builds lost the pages that existed first, and 2 CPUs is the default on hosted CI runners. In a bigger lab the record's page stayed in 56 of 56 builds on 2 CPUs, and 32 of 32 on 4 and 8 for sites of 70 and 610 routes. All 265 exited 0 with no warning. Only a small site on many CPUs races.\n\n**3. On Windows, case alone is enough.** NTFS is case-insensitive, so two chunk names that differ only in case are one file, and the last write wins. The build never notices: the two paths differ as strings, so the duplicate check above doesn't fire, the manifest keeps both entries pointing at what it thinks are two files, and `tools/check-dist.mjs` sees nothing either. No store and no `_` involved, just two routes:\n\n```ts\n{ path: 'archive', component: Archive, title: 'Archive' },\n{ path: 'Archive', component: CapitalArchive, title: 'Capital Archive' },\n```\n\n```text\nPrerendered 14 static routes. exit 0, no warning\n$ node tools/check-dist.mjs\n16 pages, 16 chunks, 0 shared it reports no collision\n\nserver/assets-chunks/ archive_index_html.mjs one file where the manifest names two\nbrowser/ archive/index.html one directory, holding the capital page\n\nGET /Archive 200 declared 1000 sent 1000 \u003ctitle>Capital Archive\u003c/title>\nGET /archive 200 declared 955 sent 1000 \u003ctitle>Capital Archive\u003c/title> \u003c-- not the declared length\n```\n\n`/archive` serves the other route's page under its own length and `ETag`, 45 bytes over what it declared. The copy under `dist/browser` collapsed the same way, so here a static host is affected too. Measured on Windows 11, NTFS, `@angular/build` 22.2.7, Node 24.16.0.\n\n**4. Behind a proxy it reaches other users.** The server writes more bytes than it declared, because the length comes from the lost page and the bytes from the surviving one. A proxy with upstream keep-alive stops at `Content-Length`, calls the response done, and leaves the rest on the pooled connection, where it answers whichever request gets that connection next. Those bytes are the attacker's record, so the attacker writes them: a complete `text/javascript` response in one project description, with the other sized so the declared length ends where it begins. Both go in as plain text.\n\nWith `proxy_cache` in front it is stored under the URL that next request asked for. One request per URL took all five URLs of the lab site, the main bundle included, and from then on the cache served it with no attacker traffic at all:\n\n```text\n$ lab tools/traffic.mjs 8 0 10 8 visitors, nobody attacking\nvisitor requests 47335\n got what they asked for 0\n got the attacker's script 47335 (100.0 %)\n answered from the cache 47335\nattacker requests 0\n```\n\nA second run took 4 of the 5 URLs, 80.0 %. A request that doesn't land stores the real page instead, so it's one try per URL per `proxy_cache_valid` period, and right after a deployment the cache holds none of those URLs yet.\n\nTwo things bound it. The link needs a round trip, because the leftover bytes have to arrive after the proxy has handed the connection over and not while it's idle in the pool: 0 % with netem removed (two containers on one host), 73.3 % at 300 µs, 100 % at 1 ms and above. And the declared length has to land at the end of the server's first write burst: one value in the range I swept worked and the rest landed 0 %. Each pair gets its own chunk, though, so one build can hold several pairs at several lengths. Without a cache, keep-alive alone still delivers the bytes, but only to the one request that follows: 0.4 to 4.6 % of visitor requests while the attacker keeps sending. nginx with nothing but `proxy_pass` talks HTTP/1.0 upstream and nothing lands. The attacker's steps, the sizing and the sweeps are in the repo's `README.md`.\n\nThe last URL in that list is the site's own `main-*.js`, which every page loads in a `\u003cscript>`. A browser running it is the one step I did not test, and it's why this is going privately instead of into an issue.\n\n### Minimal Reproduction\n\nRepository: https://github.com/SkyZeroZx/angular-cli-ssr-chunk-collision-poc\n\nIt also reproduces with no external data at all, on a stock app and two routes a developer could write:\n\n```sh\nnpx @angular/cli@22.2.7 new app --ssr --defaults && cd app\n```\n\n```ts\nexport const routes: Routes = [\n { path: 'blog/archive', component: Archive, title: 'Archive' },\n { path: 'blog_archive', component: LegacyArchive, title: 'Legacy archive' },\n];\n```\n\n```sh\ntaskset -c 0,1 npx ng build\nls dist/app/server/assets-chunks/\nNG_ALLOWED_HOSTS=localhost node dist/app/server/server.mjs &\ncurl -s -D- http://localhost:4000/blog/archive | grep -oiE 'content-length: [0-9]+|\u003ctitle>[^\u003c]*\u003c/title>'\n```\n\n```text\nPrerendered 2 static routes. exit 0, no warning\nblog_archive_index_html.mjs index_csr_html.mjs index_server_html.mjs\n\ncontent-length: 22107\n\u003ctitle>Legacy archive\u003c/title>\n```\n\nBoth paths are valid and both come from the repository, so no validation in the application reaches this. 3 of 3 builds.\n\n### Exception or Error\n\n```text\nThere isn't one, which is most of the problem. The build is green and quiet, and `dist` is short one file:\n\n\n$ taskset -c 0,1 npx ng build exit 0, no warning\nPrerendered 15 static routes.\n\n$ node tools/check-dist.mjs\nSHARED ./assets-chunks/legal_privacy_index_html.mjs\n legal/privacy/index.html declares 2647, chunk holds 1375\n legal_privacy/index.html declares 1375, chunk holds 1375\nSHARED ./assets-chunks/acme_docs_intro_index_html.mjs\n acme_docs/intro/index.html declares 1281, chunk holds 1459\n acme/docs_intro/index.html declares 1459, chunk holds 1459\n17 pages, 15 chunks, 2 shared\n\n\nControl, the same store without those records: `14 pages, 14 chunks, 0 shared`, and every URL serves its own page.\n```\n\n### Your Environment\n\n```text\n@angular/build 22.2.7\n@angular/ssr 22.2.7\n@angular/core 22.2.6\nNode.js 24.20.0\nnginx 1.30.6 (only version tested, and the only proxy)\nChrome 156.0.8078.79\nBuild production, outputMode 'server', pinned to 2 CPUs\nAlso run on Windows 11, NTFS, Node 24.16.0 (the case-collision example)\n```\n\n### Anything else relevant?\n\n`SECURITY.md` leaves validation of build-time route data to the application, so I expect that question to come up. The advisory whose workaround this app uses, GHSA-w34w-96hf-98hj, already names `jsChunkFilePath` in its description, and already counts a benign value, `customer's-choice`, as impact because it breaks the output. Sanitizing is what it asks for, and sanitizing doesn't help here: no rule an app can write sees two names that become equal only inside a `replace` it has no idea exists, and nobody writing an app would guess that a case-insensitive filesystem folds two chunk names into one. The Windows example has no external data in it at all, just two routes from the repository. So I think this is a vulnerability in the build, not a missing check in the application.\n\n","author":{"url":"https://github.com/SkyZeroZx","@type":"Person","name":"SkyZeroZx"},"datePublished":"2026-11-16T05:46:01Z","url":"https://github.com/angular/angular-cli/issues/34722"}
| 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:6b0a22f7-40eb-7ed4-db56-de7fa6835b0d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B194:1F8B56:59030A:7E2CE1:6AFDBDF8 |
| html-safe-nonce | 7e19c792c343d2f5730b86dbc14cd7d8fe660433b11a8d3e7cbc1c5c1f695d70 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMTk0OjFGOEI1Njo1OTAzMEE6N0UyQ0UxOjZBRkRCREY4IiwidmlzaXRvcl9pZCI6Ijg3Mjk4NjE3OTM2MjAyNzg3NzYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 25a1c074140eb64c65078177f965c676655b8a876049709a436aa3a6b2ad3cb6 |
| hovercard-subject-tag | issue:6415060026 |
| 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/34722/issue_layout |
| twitter:image | https://opengraph.githubassets.com/6919c5c6b2eadf78c14c4644854f0f27657324b64766c51cf1785cd49d917480/angular/angular-cli/issues/34722 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/6919c5c6b2eadf78c14c4644854f0f27657324b64766c51cf1785cd49d917480/angular/angular-cli/issues/34722 |
| og:image:alt | Command build Is this a regression? Yes, this behavior used to work in the previous version The previous version in which this bug was not present was No response Description This is another piece ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | SkyZeroZx |
| hostname | github.com |
| expected-hostname | github.com |
| None | 35c6bf57da1370dc64866160540c0ee9f825f291935b3bf6ec5492b00e35f3a6 |
| 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 | ab48c73a2978548773f5f24717ed9e58508befdb |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width