Skip to content

Angular SSR prerender chunk-name collision desynchronizes Content-Length and contaminates other users' responses behind a proxy #34722

Closed

Description

@SkyZeroZx

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 #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:

const jsChunkFilePath = `assets-chunks/${file.path.replace(/[./]/g, '_')}.mjs`;

So legal/privacy/index.html and legal_privacy/index.html get the same file, and the later one replaces the earlier:

for (const chunk of serverAssetsChunks) {
const idx = additionalOutputFiles.findIndex(({ path }) => path === chunk.path);
if (idx === -1) {
additionalOutputFiles.push(chunk);
} else {
additionalOutputFiles[idx] = chunk;
}
}

The manifest still has both pages, each with its own size and hash, and the server sends those with whatever the shared file holds:

const { text, hash, size } = assets.getServerAsset(assetPath);
const etag = `"${hash}"`;
return request.headers.get('if-none-match') === etag
? new Response(undefined, { status: 304, statusText: 'Not Modified' })
: new Response(await text(), {
headers: {
'Content-Length': size.toString(),
'ETag': etag,
'Content-Type': 'text/html;charset=UTF-8',
...(locale !== undefined ? { 'Content-Language': locale } : {}),
...headers,
},
});

N pages in the manifest, N - 1 files in dist, and ng build exits 0 with no warning.

Those paths come from getPrerenderParams(), which is application data: the docs read it from a service, and 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:

Records created through the app's API Page that is lost Result
account legal_privacy the site's /legal/privacy the URL serves the attacker's profile
account acme, project docs_intro /acme_docs/intro, another account's project the URL serves acme/docs_intro
mallory_dev/tools and mallory/dev_tools /mallory/dev_tools behind nginx with a cache, one request puts their script on every URL

It 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 and PyPI normalizes them, and among the 4,681,490 public npm names 697 groups would still lose a page under :name and :scope/:name.

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:

$ curl -s -D- http://localhost:4000/legal/privacy               stalls 6.06 s, then curl: (18)
content-length: 2647
etag: "85d6085a71e5686e"
<title>Profile of legal_privacy</title>
<h1>legal_privacy</h1><p>Our privacy policy has moved.</p><a href="https://legal-privacy.example.test/">Website</a>

The 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.

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.

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:

{ path: 'archive', component: Archive, title: 'Archive' },
{ path: 'Archive', component: CapitalArchive, title: 'Capital Archive' },
Prerendered 14 static routes.            exit 0, no warning
$ node tools/check-dist.mjs
16 pages, 16 chunks, 0 shared            it reports no collision

server/assets-chunks/   archive_index_html.mjs    one file where the manifest names two
browser/                archive/index.html        one directory, holding the capital page

GET /Archive   200  declared 1000  sent 1000  <title>Capital Archive</title>
GET /archive   200  declared  955  sent 1000  <title>Capital Archive</title>   <-- not the declared length

/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.

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.

With 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:

$ lab tools/traffic.mjs 8 0 10            8 visitors, nobody attacking
visitor requests            47335
  got what they asked for   0
  got the attacker's script 47335  (100.0 %)
  answered from the cache   47335
attacker requests           0

A 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.

Two 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.

The last URL in that list is the site's own main-*.js, which every page loads in a <script>. 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.

Minimal Reproduction

Repository: https://github.com/SkyZeroZx/angular-cli-ssr-chunk-collision-poc

It also reproduces with no external data at all, on a stock app and two routes a developer could write:

npx @angular/cli@22.2.7 new app --ssr --defaults && cd app
export const routes: Routes = [
  { path: 'blog/archive', component: Archive, title: 'Archive' },
  { path: 'blog_archive', component: LegacyArchive, title: 'Legacy archive' },
];
taskset -c 0,1 npx ng build
ls dist/app/server/assets-chunks/
NG_ALLOWED_HOSTS=localhost node dist/app/server/server.mjs &
curl -s -D- http://localhost:4000/blog/archive | grep -oiE 'content-length: [0-9]+|<title>[^<]*</title>'
Prerendered 2 static routes.                 exit 0, no warning
blog_archive_index_html.mjs  index_csr_html.mjs  index_server_html.mjs

content-length: 22107
<title>Legacy archive</title>

Both paths are valid and both come from the repository, so no validation in the application reaches this. 3 of 3 builds.

Exception or Error

There isn't one, which is most of the problem. The build is green and quiet, and `dist` is short one file:


$ taskset -c 0,1 npx ng build                                   exit 0, no warning
Prerendered 15 static routes.

$ node tools/check-dist.mjs
SHARED ./assets-chunks/legal_privacy_index_html.mjs
  legal/privacy/index.html           declares 2647, chunk holds 1375
  legal_privacy/index.html           declares 1375, chunk holds 1375
SHARED ./assets-chunks/acme_docs_intro_index_html.mjs
  acme_docs/intro/index.html         declares 1281, chunk holds 1459
  acme/docs_intro/index.html         declares 1459, chunk holds 1459
17 pages, 15 chunks, 2 shared


Control, the same store without those records: `14 pages, 14 chunks, 0 shared`, and every URL serves its own page.

Your Environment

@angular/build    22.2.7
@angular/ssr      22.2.7
@angular/core     22.2.6
Node.js           24.20.0
nginx             1.30.6 (only version tested, and the only proxy)
Chrome            156.0.8078.79
Build             production, outputMode 'server', pinned to 2 CPUs
Also run on       Windows 11, NTFS, Node 24.16.0 (the case-collision example)

Anything else relevant?

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.

Activity

  1. added this to the needsTriage milestone on Nov 16, 2026
  2. added a commit that references this issue on Nov 16, 2026
    1d1705f
  3. added 2 commits that reference this issue on Nov 16, 2026
    ae22d66
    0ee493e
  4. added a commit that references this issue on Nov 16, 2026
    be9e3a0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions