Security rules

NGB020: Sensitive SSR transfer cache

Reports Angular SSR state transfer that may serialize per-user or credential data into the rendered HTML: TransferState.set() with values or keys that carry credentials or personal data (user, profile, session, account, …) or that come from authenticated-looking HTTP endpoints, and withHttpTransferCacheOptions() configured to cache requests with auth headers or to include sensitive response headers..

Property Value
Rule ID NGB020
Category Angular SSR security
Default severity high
CWE CWE-524, CWE-200
Built-in presets recommended: error, strict: error

Confidence is reported per finding (high, medium, low) and is independent of severity. See Reading findings.

What it checks

Reports Angular SSR state transfer that may serialize per-user or credential data into the rendered HTML: TransferState.set() with values or keys that carry credentials or personal data (user, profile, session, account, …) or that come from authenticated-looking HTTP endpoints, and withHttpTransferCacheOptions() configured to cache requests with auth headers or to include sensitive response headers.

Why it matters

Transferred state is embedded as JSON in the server-rendered HTML. If that HTML is cached by a CDN or shared cache, or rendered for one user and served to another, the embedded per-user data and tokens leak to other visitors. By default Angular's HTTP transfer cache skips requests with Authorization headers for this reason.

Detection behavior and supported patterns

  • transferState.set(key, value) where transferState is TransferState from @angular/core
  • Evidence: credential/payment names on the value (NGB014/NGB016 vocabulary, high confidence); personal-data names on the value or its type, or a traced HttpClient response from /me, /user, /account, /profile, /session, /auth URLs (medium); a personal state-key name only (low)
  • withHttpTransferCacheOptions({ includeRequestsWithAuthHeaders: true }) and includeHeaders containing authorization, cookie, set-cookie, x-api-key (lower confidence when a filter function is present)

Example

TypeScript
this.http.get<User>('/api/me').subscribe(u => this.state.set(USER_KEY, u));

Safer alternative

TypeScript
this.http.get<Product[]>('/api/products').subscribe(p => this.state.set(PRODUCTS_KEY, p));

Remediation

Do not transfer credentials. Transfer only public, shareable state; fetch per-user data on the client after hydration, or ensure SSR responses containing user data are never cached (Cache-Control: private, no-store). Keep the default HTTP transfer cache behaviour of skipping authenticated requests.

False-positive considerations

  • Pages rendered per request with Cache-Control: private, no-store limit exposure to the requesting user; such findings can be documented as exceptions.
  • Public data with personal-sounding names (e.g. a public author profile) may be reported with medium confidence.

Known limitations

  • Whether the SSR response is actually cached or shared between users depends on deployment (CDN rules, Cache-Control) and cannot be determined statically.
  • Cookie-authenticated requests cached by the HTTP transfer cache are not detected: whether a request carries cookies is decided at runtime.
  • The body of a custom filter function is not evaluated.

References

Run it

Shell
ngbastion explain NGB020