Stored Cross-Site Scripting (XSS) in Prerendered Redirect Pages in @angular/build
Description
A Stored Cross-Site Scripting (XSS) vulnerability exists in generateRedirectStaticPage in @angular/build. When generating static HTML redirect pages during prerendering (SSG), the redirect target URL was interpolated directly into the <meta http-equiv="refresh"> attribute and fallback <a> element without HTML escaping.
The vulnerability occurs during static redirect page generation:
- During prerendering (
ng build), routes that resolve to a redirect (viaredirectTounder a parameterized route usinggetPrerenderParams(), or via aLocationresponse header during static route rendering) generate a static HTML file usinggenerateRedirectStaticPage(url). generateRedirectStaticPageinterpolatesurldirectly into<meta http-equiv="refresh" content="0; url=${url}">and<pre>Redirecting to <a href="${url}">${url}</a></pre>without escaping HTML special characters (&,<,>,",').- If
urlcontains values derived from an external data source (such asgetPrerenderParams()fetching slugs from a CMS or API) with characters such as"and<script>, the unescaped value breaks out of the HTML attribute/element and injects arbitrary HTML and JavaScript into the prerenderedindex.htmlfile.
Impact
- Stored Cross-Site Scripting (XSS): If a prerendered redirect URL incorporates untrusted or externally controlled route parameters (e.g., from a CMS or external API via
getPrerenderParams()), an attacker who can control the parameter or redirect target can inject arbitrary HTML and JavaScript into the generated static redirect page, which executes in the browser of users who visit that prerendered route.
Attack Preconditions
- The application uses
@angular/build:applicationwith prerendering (SSG) enabled and static redirect generation (e.g.,outputMode: "static"or static prerendered redirect routes). - A prerendered redirect target URL includes unencoded values from an untrusted or externally modifiable source (such as
getPrerenderParams()fetching slugs from a CMS or API).
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, ensure that any dynamic route parameters returned by getPrerenderParams() or used in prerendered redirects are strictly validated or URL-encoded (e.g., with encodeURIComponent) so that they cannot contain HTML special characters (&, <, >, ", ').