Skip to content

skip transfer cache for credentialed requests and uncacheable request/responses#69017

Closed
SkyZeroZx wants to merge 3 commits into
angular:mainfrom
SkyZeroZx:fix/transfer-credentials
Closed

skip transfer cache for credentialed requests and uncacheable request/responses#69017
SkyZeroZx wants to merge 3 commits into
angular:mainfrom
SkyZeroZx:fix/transfer-credentials

Conversation

@SkyZeroZx

@SkyZeroZx SkyZeroZx commented May 29, 2026

Copy link
Copy Markdown
Contributor

fix(http): skip transfer cache for fetch credentialed requests

Treat HttpClient requests using credentials: 'include' and same-origin as credentialed when deciding whether a response can be stored in the HTTP transfer cache.

The transfer cache already skips requests with withCredentials, Cookie, Authorization, or Proxy-Authorization because those responses may contain user-specific data. Fetch-backed requests can express the same credentialed behavior through the credentials option, so these responses must not be serialized into the SSR HTML.

This keeps credentialed SSR responses out of TransferState and aligns the cache eligibility check with the fetch request options supported by HttpClient.

This can be considered a variant of #67964

fix(http): skip transfer cache for uncacheable HTTP traffic

Do not store HTTP transfer cache entries when either the request or response
uses Cache-Control: no-store, Cache-Control: private, or
Cache-Control: no-cache.

Also skip transfer cache when requests use the Fetch API cache option with
no-store or no-cache.

Because transfer cache serializes SSR HTTP responses into the rendered HTML,
Angular now treats these directives conservatively to avoid exposing sensitive
or explicitly uncacheable data through TransferState.

@SkyZeroZx SkyZeroZx changed the title fix(common): skip transfer cache for fetch credentialed requests fix(http): skip transfer cache for fetch credentialed requests May 29, 2026
Treat HttpClient requests using `credentials: 'include'` and `same-origin` as credentialed
when deciding whether a response can be stored in the HTTP transfer cache.

The transfer cache already skips requests with `withCredentials`, `Cookie`,
`Authorization`, or `Proxy-Authorization` because those responses may contain
user-specific data. Fetch-backed requests can express the same credentialed
behavior through the `credentials` option, so these responses must not be
serialized into the SSR HTML.

This keeps credentialed SSR responses out of TransferState and aligns the
cache eligibility check with the fetch request options supported by HttpClient.
@angular-robot angular-robot Bot added the area: common Issues related to APIs in the @angular/common package label May 29, 2026
@ngbot ngbot Bot added this to the Backlog milestone May 29, 2026
@SkyZeroZx SkyZeroZx force-pushed the fix/transfer-credentials branch from 2bb2168 to 8ec0197 Compare May 29, 2026 16:23
@angular-robot angular-robot Bot added the area: common/http Issues related to HTTP and HTTP Client label May 29, 2026
@SkyZeroZx SkyZeroZx marked this pull request as ready for review May 29, 2026 16:55
@pullapprove pullapprove Bot requested a review from atscott May 29, 2026 16:55
@atscott atscott requested review from JeanMeche and alan-agius4 and removed request for atscott May 29, 2026 16:58
@SkyZeroZx SkyZeroZx force-pushed the fix/transfer-credentials branch 2 times, most recently from b2beb84 to 8d04a64 Compare May 30, 2026 15:47
@SkyZeroZx SkyZeroZx changed the title fix(http): skip transfer cache for fetch credentialed requests skip transfer cache for credentialed requests and uncacheable responses May 30, 2026
@SkyZeroZx SkyZeroZx changed the title skip transfer cache for credentialed requests and uncacheable responses skip transfer cache for credentialed requests and uncacheable request/responses May 30, 2026
@SkyZeroZx SkyZeroZx force-pushed the fix/transfer-credentials branch from 8d04a64 to 3f562bd Compare May 30, 2026 22:25
Do not store HTTP transfer cache entries when either the request or response
uses `Cache-Control: no-store`, `Cache-Control: private`, or
`Cache-Control: no-cache`.

Also skip transfer cache when requests use the Fetch API `cache` option with
`no-store` or `no-cache`.

Because transfer cache serializes SSR HTTP responses into the rendered HTML,
Angular now treats these directives conservatively to avoid exposing sensitive
or explicitly uncacheable data through `TransferState`.
@SkyZeroZx SkyZeroZx force-pushed the fix/transfer-credentials branch from 3f562bd to 4d15015 Compare May 30, 2026 22:30
}

return cacheControl.split(',').some((directive) => {
const directiveName = directive.trim().split('=', 1)[0].trim().toLowerCase();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first trim is redundant.

Suggested change
const directiveName = directive.trim().split('=', 1)[0].trim().toLowerCase();
const directiveName = directive..split('=', 1)[0].trim().toLowerCase();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@SkyZeroZx

Copy link
Copy Markdown
Contributor Author

@JeanMeche I think the PR would be ready to merge? That way I could also generate the corresponding backports.

@atscott

atscott commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

This PR was merged into the repository. The changes were merged into the following branches:

@atscott atscott closed this in c0cbd46 Jun 3, 2026
atscott pushed a commit that referenced this pull request Jun 3, 2026
Do not store HTTP transfer cache entries when either the request or response
uses `Cache-Control: no-store`, `Cache-Control: private`, or
`Cache-Control: no-cache`.

Also skip transfer cache when requests use the Fetch API `cache` option with
`no-store` or `no-cache`.

Because transfer cache serializes SSR HTTP responses into the rendered HTML,
Angular now treats these directives conservatively to avoid exposing sensitive
or explicitly uncacheable data through `TransferState`.

PR Close #69017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: merge The PR is ready for merge by the caretaker area: common/http Issues related to HTTP and HTTP Client area: common Issues related to APIs in the @angular/common package target: minor This PR is targeted for the next minor release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants