Skip to content

do not cache responses that vary on headers added below the cache - #958

Open
Hsnmohd wants to merge 1 commit into
apache:masterfrom
Hsnmohd:cache-vary-protocol-headers
Open

Hsnmohd wants to merge 1 commit into
apache:masterfrom
Hsnmohd:cache-vary-protocol-headers

Conversation

@Hsnmohd

@Hsnmohd Hsnmohd commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

CachingExec and AsyncCachingExec match Vary against the request they hold, which never carries the Cookie (or Authorization) header ProtocolExec adds from the context, so a Cache-Control: max-age=60 + Vary: Cookie page fetched with one session is stored as the cookie-less variant and served to every other context (reproduced: bob's context got alice's page on the classic client, an anonymous one got bob's on async); the response is now not stored when the Vary-nominated headers actually sent (context.getRequest()) differ from those the cache saw, and the async exec passes a copy down the chain like the classic one.

@arturobernalg

Copy link
Copy Markdown
Member

This does not address the actual problem. The new check only prevents storing certain responses, while cache lookup still happens before the effective Cookie headers are available.

Reproduced with real HTTP clients in both classic and async: a cached anonymous response with Vary: Cookie is incorrectly reused for subsequent requests with different cookies, violating RFC 9111 §4.1. The new guard also prevents legitimate caching of responses varying on context-generated cookies.

I think we need to reconsider the execution chain and ensure cache lookup and storage operate on the effective request headers, rather than adding another guard to the caching layer.

@ok2c

ok2c commented Nov 21, 2026

Copy link
Copy Markdown
Member

I think we need to reconsider the execution chain and ensure cache lookup and storage operate on the effective request headers, rather than adding another guard to the caching layer.

@arturobernalg I will see if I can re-organize the execution pipeline without breaking everything. Please focus on other more pressing issues.

@ok2c

ok2c commented Nov 21, 2026

Copy link
Copy Markdown
Member

@arturobernalg @Hsnmohd It turned out to be surprisingly painless. Please take a look at #959

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants