Packages / @angular/ssr / Security
Angular SSR is vulnerable to SSRF and Header Injection via request handling pipeline
Affected releases · @angular/ssr
- 21.x21.0.0 – 21.1.4Fixed in 21.1.5
- 20.x20.0.0 – 20.3.16Fixed in 20.3.17
- 19.x19.0.0 – 19.2.20Fixed in 19.2.21
- 18.x and older17.0.0 – 18.2.21No fix, no longer updated
On 21.x, the newest line:
npm install @angular/ssr@21.1.5Not affected
22.0.0 – 22.2.3
24 releases, latest
Affected
21.0.0 – 21.1.4
12 releases
Fixed
21.1.5 – 21.2.27
29 releases
Affected
20.0.0 – 20.3.16
34 releases
Fixed
20.3.17 – 20.3.40
24 releases
Affected
19.0.0 – 19.2.20
39 releases
Fixed
19.2.21 – 19.2.27
7 releases
Affected
18.0.0 – 18.2.21
35 releases
Affected
17.0.0 – 17.3.17
38 releases
Is your project affected?
Paste your package.json, or type the range you declare for @angular/ssr. It is read in your browser and sent nowhere.
What happens
A Server-Side Request Forgery (SSRF) vulnerability has been identified in the Angular SSR request handling pipeline. The vulnerability exists because Angular’s internal URL reconstruction logic directly trusts and consumes user-controlled HTTP headers specifically the Host and X-Forwarded-* family to determine the application's base origin without any validation of the destination domain.
Specifically, the framework didn't have checks for the following:
Host Domain: The
HostandX-Forwarded-Hostheaders were not checked to belong to a trusted origin. This allows an attacker to redefine the "base" of the application to an arbitrary external domain.Path & Character Sanitization: The
X-Forwarded-Hostheader was not checked for path segments or special characters, allowing manipulation of the base path for all resolved relative URLs.Port Validation: The
X-Forwarded-Portheader was not verified as numeric, leading to malformed URI construction or injection attacks.
This vulnerability manifests in two primary ways:
Implicit Relative URL Resolution: Angular's
HttpClientresolves relative URLs against this unvalidated and potentially malformed base origin. An attacker can "steer" these requests to an external server or internal service.Explicit Manual Construction: Developers injecting the
REQUESTobject to manually construct URLs (for fetch or third-party SDKs) directly inherit these unsanitized values. By accessing theHost/X-Forwarded-*headers, the application logic may perform requests to attacker-controlled destinations or malformed endpoints.
Impact
When successfully exploited, this vulnerability allows for arbitrary internal request steering. This can lead to:
Credential Exfiltration: Stealing sensitive
Authorizationheaders or session cookies by redirecting them to an attacker's server.Internal Network Probing: Accessing and transmitting data from internal services, databases, or cloud metadata endpoints (e.g.,
169.254.169.254) not exposed to the public internet.Confidentiality Breach: Accessing sensitive information processed within the application's server-side context.
Attack Preconditions
The victim application must use Angular SSR (Server-Side Rendering).
The application must perform
HttpClientrequests using relative URLs OR manually construct URLs using the unvalidatedHost/X-Forwarded-*headers using theREQUESTobject.Direct Header Access: The application server is reachable by an attacker who can influence these headers without strict validation from a front-facing proxy.
Lack of Upstream Validation: The infrastructure (Cloud, CDN, or Load Balancer) does not sanitize or validate incoming headers.
Patches
21.2.0-rc.1
21.1.5
20.3.17
19.2.21
Workarounds
Use Absolute URLs: Avoid using
req.headersfor URL construction. Instead, use trusted variables for your base API paths.Implement Strict Header Validation (Middleware): If you cannot upgrade immediately, implement a middleware in your
server.tsto enforce numeric ports and validated hostnames.
const ALLOWED_HOSTS = new Set(['your-domain.com']);
app.use((req, res, next) => {
const hostHeader = (req.headers['x-forwarded-host'] ?? req.headers['host'])?.toString();
const portHeader = req.headers['x-forwarded-port']?.toString();
if (hostHeader) {
const hostname = hostHeader.split(':')[0];
// Reject if hostname contains path separators or is not in allowlist
if (/^[a-z0-9.:-]+$/i.test(hostname) ||
(!ALLOWED_HOSTS.has(hostname) && hostname !== 'localhost')) {
return res.status(400).send('Invalid Hostname');
}
}
// Ensure port is strictly numeric if provided
if (portHeader && !/^\d+$/.test(portHeader)) {
return res.status(400).send('Invalid Port');
}
next();
});References