An Open Redirect vulnerability exists in @angular/ssr due to an incomplete fix for CVE-2026-27738. While the original fix successfully blocked multiple leading slashes (e.g., ///), the internal validation logic fails to account for a single backslash (\) bypass.
When an Angular SSR application is deployed behind a proxy that passes the X-Forwarded-Prefix header:
- An attacker provides a value starting with a single backslash (e.g., \evil.com). - The internal validation failed to flag the single backslash as invalid. - The application prepends a leading forward slash, resulting in a Location header containing /\evil.com. - Modern browsers interpret the /\ sequence as //, treating it as a protocol-relative URL and redirecting the user to the attacker-controlled domain.
Furthermore, the response lacks the Vary: X-Forwarded-Prefix header, allowing the malicious redirect to be stored in intermediate caches (Web Cache Poisoning).
Impact This vulnerability allows attackers to conduct large-scale phishing and SEO hijacking:
- Scale: A single request can poison a high-traffic route, impacting all users until the cache expires. - SEO Poisoning: Search engine crawlers may follow and index these malicious redirects, causing the legitimate site to be delisted or associated with malicious domains. - Trust: Because the initial URL belongs to the trusted domain, users and security tools are less likely to flag the redirect as malicious.
Patches
- 22.0.0-next.2 - 21.2.3 - 20.3.21
Workarounds Until the patch is applied, developers should sanitize the X-Forwarded-Prefix header in their server.ts before the Angular engine processes the request:
ts app.use((req, res, next) => { const prefix = req.headers['x-forwarded-prefix']; if (typeof prefix === 'string') { // Sanitize by removing all leading forward and backward slashes req.headers['x-forwarded-prefix'] = prefix.trim().replace(/^[/\\]+/, '/'); } next(); });
References
- Fix: https://github.com/angular/angular-cli/pull/32771 - Original CVE: CVE-2026-27738
Description A vulnerability exists in the X-Forwarded-Prefix header processing logic within Angular SSR. The internal validation mechanism fails to properly account for URL-encoded characters, specifically dots (%2e%2e). This allows an attacker to bypass security filters by injecting encoded path traversal sequences that are later decoded and utilized by the application logic. When an Angular SSR application is configured to trust proxy headers and is deployed behind a proxy that forwards the X-Forwarded-Prefix header without prior sanitization, an attacker can provide a payload such as /%2e%2e/evil.
The vulnerability manifests in two ways: - Open Redirect: The application processes a redirect (e.g., router redirectTo). The decoded traversal payload manipulates the Location header, forcing the browser to an unintended path or external domain. - Server-Side Request Steering: The manipulated prefix is used as the base path for server-side HttpClient requests. This causes the server to make requests to unintended internal paths or external endpoints.
Attack Preconditions - The application must use Angular SSR. - The application must perform internal redirects or use relative URLs in server-side HttpClient requests. - The upstream infrastructure (Reverse Proxy/CDN) must pass the X-Forwarded-Prefix header to the SSR process without stripping or sanitizing it.
Workarounds Until the patch is applied, developers should manually sanitize the X-Forwarded-Prefix header in their server.ts. The workaround involves decoding the component to catch encoded traversal attempts before normalization:
ts app.use((req, res, next) => { let prefix = req.headers['x-forwarded-prefix']; if (Array.isArray(prefix)) prefix = prefix[0];
if (prefix) { try { // Decode the prefix to catch encoded characters like %2e (dots) const decodedPrefix = decodeURIComponent(prefix); // Sanitize: remove traversal attempts and ensure a safe leading slash req.headers['x-forwarded-prefix'] = decodedPrefix .replace(/\.\./g, '') // Remove any dot-dot sequences .replace(/^[/\\]+/, '/'); // Ensure it starts with exactly one slash } catch (e) { // If decoding fails, remove the potentially malicious header entirely delete req.headers['x-forwarded-prefix']; } } next(); }); Configuring Trusted Proxy Headers By default, Angular ignores all X-Forwarded- headers. If your application is behind a trusted reverse proxy (like a load balancer) that sets these headers, you can configure Angular to trust them. You can configure trustProxyHeaders when initializing the application engine:
ts const appEngine = new AngularAppEngine({ // Trust specific headers trustProxyHeaders: ['x-forwarded-host', 'x-forwarded-proto', 'x-forwarded-prefix'], });
const nodeAppEngine = new AngularNodeAppEngine({ // Trust all X-Forwarded- headers trustProxyHeaders: true, });
Patches - 22.0.0-next.7 - 21.2.9 - 20.3.25 - 19.2.25
Resources
- https://github.com/angular/angular-cli/pull/33031 - https://angular.dev/best-practices/security#configuring-trusted-proxy-headers