Angular SSR Hardening and Performance Checklist: Hosts, Transfer Cache, Limits and Caching
A practical Angular SSR checklist: allowedHosts and trusted proxy headers, the HTTP transfer cache, response body limits, status codes, hydration checks, CSP nonces and Cache-Control headers for HTML and assets, with the official option names.

Angular SSR is safe and fast when you configure eight things on purpose: allowed hosts, trusted proxy headers, patched packages, the transfer cache, response size limits, status codes, hydration and caching headers. Angular's defaults are reasonable, but several of them protect you only if you know they exist: unknown hostnames get a 400 Bad Request, proxy headers are ignored unless you trust them, HttpClient responses larger than 1 MB fail on the server, and the transfer cache skips anything with credentials. This checklist goes through each setting with the official option name, what the default does, and how to check it from outside. Version-specific upgrade steps are in Upgrading to Angular 22, and the list of fixed versions is in Patching a MEAN Stack. This post does not repeat either, it links to them.
1. Allowed hosts and trusted proxy headers
Angular SSR builds the request URL from the Host header and the forwarding headers. The security guide says the validated headers are Host, Forwarded, X-Forwarded-Host, X-Forwarded-Proto, X-Forwarded-Prefix and X-Forwarded-Port. Host values must match an allowlist, the port must be numeric, the protocol must be http or https, and the prefix may contain only letters, digits, hyphens and underscores. A request with an unrecognised hostname gets 400 Bad Request, and proxy headers are stripped unless you enable them with trustProxyHeaders.
This matters because a missing check was a real vulnerability. CVE-2026-27739 (GHSA-x288-3778-4hhx, Critical, CVSS 4.0 score 9.2) allowed SSRF and header injection through unvalidated Host and X-Forwarded-* headers, affecting relative HttpClient URLs and anything built from the injected REQUEST. It was fixed in 21.1.5, 20.3.17 and 19.2.21.
You can configure the allowlist in angular.json, in the engine constructor, or with NG_ALLOWED_HOSTS (a comma-separated list, for AngularNodeAppEngine only). Wildcards such as *.example.com match subdomains. A bare * allows every hostname, and the docs discourage it, because it enables host header injection and SSRF. Use it only if a proxy in front validates Host and X-Forwarded-Host for you.
"architect": {
"build": {
"builder": "@angular/build:application",
"options": {
"security": {
"allowedHosts": ["example.com", "www.example.com"]
}
}
}
}
The same list in the Node server, using the exact Node API from the Angular docs:
import express from 'express';
import {
AngularNodeAppEngine,
createNodeRequestHandler,
writeResponseToNodeResponse,
} from '@angular/ssr/node';
const app = express();
const angularApp = new AngularNodeAppEngine({
allowedHosts: ['example.com', 'www.example.com'],
});
app.use((req, res, next) => {
angularApp
.handle(req)
.then((response) => (response ? writeResponseToNodeResponse(response, res) : next()))
.catch(next);
});
export const reqHandler = createNodeRequestHandler(app);
Only enable proxy headers when a proxy you control validates or overwrites them, because otherwise an attacker can spoof them. For the Node engine, the environment variable is the simplest way, and you list only the headers you need:
export NG_ALLOWED_HOSTS="example.com,www.example.com"
export NG_TRUST_PROXY_HEADERS="X-FORWARDED-HOST,X-FORWARDED-PROTO"
Check it after every deploy, in staging first. Request the site through the proxy with a host you did not list, and confirm the response is the 400 the docs promise, not a rendered page.
2. Patch the SSR packages, including the dev dependency
Many of the Angular security advisories published in 2026 hit server-side packages. Run npm ls @angular/ssr @angular/build @angular/platform-server @angular/core and compare with the tables in the patch post. @angular/build is usually a devDependency, but it generates code that runs in your production SSR server, so an audit that omits dev dependencies will not report it.
3. Transfer cache: fast, but never for private data
The HTTP transfer cache stops the browser from repeating requests the server already made. By default it caches GET and HEAD requests, except those with Authorization, Proxy-Authorization or Cookie headers or credentials mode, and it skips requests or responses marked no-store, no-cache or private, and responses with Set-Cookie. The options on withHttpTransferCacheOptions are:
| Option | Default | What it does |
|---|---|---|
includeHeaders | none | Response headers to keep in cache entries |
filter | none | Function that decides whether a request is cached |
includePostRequests | false | Also caches POST requests, such as GraphQL reads |
includeRequestsWithAuthHeaders | false | Caches requests that carry auth headers |
includeRequestsWithCredentials | false | Caches credentialed requests |
includeNonCacheableRequests | false | Ignores cache-control restrictions |
Leave the include* options at false. The cache state is serialised into the HTML, so anything cached is visible to whoever receives that page. That is why GHSA-p297-fm68-3q8c (CVE-2026-88059, Moderate) mattered: with withRequestsMadeViaParent(), an anonymous request could be cached even after a parent interceptor added credentials, and a shared HTML cache could then serve one user's data to another. It was fixed in 22.1.1, 21.2.20 and 20.3.28, and its workarounds are worth keeping as policy: attach auth headers on the client that makes the request, exclude sensitive endpoints with filter, and use Cache-Control: no-store or private for personalised HTML.
provideClientHydration(
withHttpTransferCacheOptions({
// Never copy user-specific API responses into the page
filter: (req) => !req.url.includes('/api/me/'),
}),
),
You can also opt out per request with { transferCache: false }, or globally with withNoHttpTransferCache(). To test the cache, load a server-rendered page with the network tab open: calls the server already made should not repeat in the browser.
4. Response body limits
By default, Angular limits each server-side HttpClient response body to 1 MB, and a larger body fails with error NG02825. Raise it with maxResponseBodySize (in bytes) in the provideServerRendering options, only for a page that really needs it. The docs add a caveat: the limit applies after Fetch returns, so it does not cap the buffering that Fetch performs to verify integrity. Keep the underlying fix in mind too: an SSR page that needs megabytes of JSON is usually asking the API for too much, and pagination is the better fix.
providers: [
provideServerRendering({ maxResponseBodySize: 2 * 1024 * 1024 }, withRoutes(serverRoutes)),
],
If the same Node process also serves JSON endpoints through Express, give those their own explicit request body limits as well. body-parser's documented default is '100kb', and its docs advise against very high limits.
5. Status codes and redirects
A "not found" page that returns 200 OK becomes a soft 404 in search results. You can set a static status or headers on a server route (status and headers on the route object), or set them at runtime by injecting RESPONSE_INIT. The docs note that REQUEST, RESPONSE_INIT and REQUEST_CONTEXT are null during builds, client-side rendering, prerendering and dev-time route extraction, so inject them as optional. SSR redirects use real HTTP redirects such as 301 or 302, while prerendered pages can only use a <meta http-equiv="refresh"> soft redirect. Angular SSR and Signals in Practice shows the 404 and 503 pattern in a data-driven page, and the HTTP status codes reference explains which code to pick.
6. Hydration: verify it, do not assume it
- Check the console in development. It prints hydration stats with the number of components and nodes hydrated. Angular DevTools can overlay hydrated regions and flag components that cause mismatches.
- Server and client DOM must match, including whitespace and comment nodes. Direct DOM manipulation (
innerHTML,appendChild), invalid nesting such as adivinside ap, and a table without an explicittbodycause mismatch errors. - Treat
ngSkipHydrationas a temporary workaround. It re-renders that component and its children. Put it on the root component and you disable hydration for the whole app. - i18n: components that use i18n blocks skip hydration unless you add
withI18nSupport()toprovideClientHydration(). - Stability:
NG0506means the app was not stable after 10 seconds. Timers, intervals, unresolved promises and pending microtasks all delay hydration.provideStabilityDebugging()helps you find the cause in development. - Incremental hydration is on by default with
provideClientHydration(), and it turns on event replay. Use@defer (hydrate on viewport)or another hydrate trigger for below-the-fold sections, andwithNoIncrementalHydration()to opt out.
7. Caching headers for HTML and assets
Angular's docs describe how to set headers per route but not what to put in them, so the values below are starting points built from the HTTP caching directives on MDN. They are not benchmarks, and the right numbers depend on how fresh your pages must be.
| Response | Starting point | Why |
|---|---|---|
| Fingerprinted JS, CSS and fonts | public, max-age=31536000, immutable | The file name changes when the content does, so it never needs revalidation |
| Public server-rendered HTML | no-cache, or a short shared-cache window such as public, max-age=0, s-maxage=60, stale-while-revalidate=300 | MDN recommends no-cache for the HTML that references fingerprinted assets. s-maxage applies to shared caches only, and stale-while-revalidate lets a cache reuse a stale copy while it refreshes |
| Personalised or authenticated HTML | private, no-store | no-store stops every cache from storing it, private limits storage to the browser |
| robots.txt, sitemap.xml, favicon | a short max-age | They are not fingerprinted, so a year-long lifetime would leave stale copies |
stale-if-error is another useful directive: it lets a cache reuse a stale response when the origin returns 500, 502, 503 or 504. Set per-route headers on the server route, which accepts a headers object for routes that use RenderMode.Server:
export const serverRoutes: ServerRoute[] = [
{ path: 'account', renderMode: RenderMode.Server, headers: { 'Cache-Control': 'private, no-store' } },
{
path: 'blog/:slug',
renderMode: RenderMode.Server,
headers: { 'Cache-Control': 'public, max-age=0, s-maxage=60, stale-while-revalidate=300' },
},
{ path: '**', renderMode: RenderMode.Server },
];
Check the result from the outside, because a CDN or proxy may add, remove or rewrite headers:
curl -sI https://example.com/ | grep -i -E "^(cache-control|content-security-policy|age)"
curl -s -o /dev/null -w "%{http_code}\n" https://example.com/page-that-does-not-exist # expect 404
8. CSP nonces and CDN caching
The Angular security guide's minimal policy for a new app is default-src 'self'; style-src 'self' 'nonce-<value>'; script-src 'self' 'nonce-<value>';. The nonce must be unique and unpredictable for each response, so you can provide it with ngCspNonce on the root element or the CSP_NONCE injection token. The guide warns that if a CDN caches your HTML, a nonce generated at the origin is the same for every visitor, so generate it at the edge instead. It also says security.autoCsp cannot be used with SSR. In short: if you want both a nonce-based CSP and cached HTML, design the edge logic first.
Frequently asked questions
Do I need allowedHosts if I only have one domain?
Yes. List that domain explicitly, and the www variant if it serves traffic. The docs describe an allowlist with strict matching, and an unlisted hostname gets 400 Bad Request, so a missing entry shows up quickly in staging.
Should I cache SSR HTML at a CDN at all?
Only for pages that are the same for every visitor. For anything personalised, use private, no-store, as the transfer-cache advisory recommends. Measure the effect with your own traffic before relying on a number.
What should I monitor?
Watch the share of 400 responses after you set allowedHosts, redirects to external hosts, and server restarts, because several of this year's Angular SSR advisories were denial-of-service, redirect or request-handling bugs.
If you want a review of an Angular SSR deployment, see my Angular SSR development service.
Sources
- Angular: Security (host header validation, allowedHosts, trustProxyHeaders, CSP and nonces)
- Angular: Server-side and hybrid rendering (render modes, route headers and status, transfer cache options, maxResponseBodySize, NG02825)
- Angular: Hydration and Incremental hydration
- AngularNodeAppEngine API and writeResponseToNodeResponse API
- ServerRouteServer API (headers, status, renderMode)
- GHSA-x288-3778-4hhx (CVE-2026-27739, SSRF and header injection in @angular/ssr)
- GHSA-p297-fm68-3q8c (CVE-2026-88059, transfer cache with withRequestsMadeViaParent)
- MDN: Cache-Control (s-maxage, stale-while-revalidate, stale-if-error, immutable, private, no-store)
- body-parser documentation (default limit)




