Skip to main content
Menu
Advisories

Stored Cross-Site Scripting (XSS) in Prerendered Redirect Pages in @angular/build

GHSA-JP2Q-RH7R-4VJFPublished Updated GitHub

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:

  1. During prerendering (ng build), routes that resolve to a redirect (via redirectTo under a parameterized route using getPrerenderParams(), or via a Location response header during static route rendering) generate a static HTML file using generateRedirectStaticPage(url).
  2. generateRedirectStaticPage interpolates url directly into <meta http-equiv="refresh" content="0; url=${url}"> and <pre>Redirecting to <a href="${url}">${url}</a></pre> without escaping HTML special characters (&, <, >, ", ').
  3. If url contains values derived from an external data source (such as getPrerenderParams() 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 prerendered index.html file.

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:application with 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.5
  • 21.2.29
  • 20.3.42

Versions <= 19.2.27 have 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 (&, <, >, ", ').

Affected versions

References

GitHub · angular/angular-cli