Code Injection in Generated Server Manifests via Unescaped Route Paths in @angular/build
Description
A Code Injection vulnerability exists in the server manifest generation logic (generateAngularServerAppManifest and generateAngularServerAppEngineManifest) of @angular/build. When prerendering (SSG) is used alongside server-side rendering (outputMode: "server"), route-derived asset paths and configuration values were interpolated directly into single-quoted string literals inside the generated executable ECMAScript modules (angular-app-manifest.mjs and angular-app-engine-manifest.mjs) without escaping.
The vulnerability occurs during build-time manifest generation:
- A parameterized prerendered route (e.g.,
product/:slug) resolves its parameter values viagetPrerenderParams(), which commonly fetches dynamic identifiers or slugs from an external API, CMS, or database. - The resolved route path is used to derive the prerendered output file path (
file.path) and chunk path (jsChunkFilePath). generateAngularServerAppManifestinterpolatesfile.pathandjsChunkFilePathdirectly intoangular-app-manifest.mjsusing template literals ('${key}': ${value}andimport('./${jsChunkFilePath}')) instead of serializing them as valid JavaScript string literals.- If an external data source returns a parameter value containing a single quote (
') and crafted JavaScript syntax, it breaks out of the string literal inangular-app-manifest.mjs. - When the Node.js SSR server loads
angular-app-manifest.mjsto handle incoming requests, the injected JavaScript code is executed in the server process.
Impact
- Remote Code Execution (RCE): If
getPrerenderParams()(orroutesFile) incorporates untrusted or externally controlled route parameters (such as slugs from a CMS or third-party API) during the build of an application withoutputMode: "server", an attacker who can control a route parameter value can inject arbitrary JavaScript intoangular-app-manifest.mjs, resulting in arbitrary code execution on the Node.js SSR server when the manifest is imported. - Denial of Service (DoS): Benign route parameters containing apostrophes (e.g.,
customer's-choice) produce syntactically invalid JavaScript inangular-app-manifest.mjs, causing SSR requests to fail with HTTP 500.
Attack Preconditions
- The application uses
@angular/build:applicationwith server output enabled (outputMode: "server"). - The application prerenders parameterized routes via
getPrerenderParams()(orroutesFile). - The parameter values returned during the build originate from an untrusted or externally modifiable source (such as a CMS, database, or external API) and are not sanitized or restricted before being returned from
getPrerenderParams().
Affected Versions
>= 22.0.0, < 22.2.5>= 21.0.0, < 21.2.29>= 20.0.0, < 20.3.42<= 19.2.27
Patches
22.2.521.2.2920.3.42
Versions
<= 19.2.27have reached End of Support / LTS expiration and will not be patched.
Workarounds
Until a patch is applied, validate or URL-encode dynamic route parameters returned by getPrerenderParams() so that they cannot contain single quotes ('), backslashes (\), or line terminators:
getPrerenderParams: async () => {
const items = await fetchItemsFromApi();
return items
.filter((item) => /^[a-zA-Z0-9-_]+$/.test(item.slug))
.map((item) => ({ slug: item.slug }));
}