fix(cache): split repeated vary headers on commas#5582
Open
arshsmith1 wants to merge 1 commit into
Open
Conversation
Signed-off-by: arshiya tabasum <arshi@bugqore.com>
mcollina
requested changes
Jul 22, 2026
| function varyHeaderHasWildcard (varyHeader) { | ||
| return typeof varyHeader === 'string' | ||
| ? varyHeader.includes('*') | ||
| : varyHeader.some(value => value.includes('*')) |
Member
There was a problem hiding this comment.
Can you please use a for(;;)/for..in loop? .some is slow
| const varyingHeaders = typeof varyHeader === 'string' | ||
| ? varyHeader.split(',') | ||
| : varyHeader | ||
| : varyHeader.flatMap(value => value.split(',')) |
Member
There was a problem hiding this comment.
please avoid flatMap and actually implement a for(;;) or for..in loop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This relates to...
N/A
Rationale
parseVaryHeaderonly splits on commas when the Vary header arrives as a single string. An origin is free to send the header more than once, andparseHeadersthen hands the cache handler an array, whose entries were used verbatim as field names. A response carryingVary: accept-encoding, x-user-idfollowed by a secondVary: accept-languageline is therefore stored under the field nameaccept-encoding, x-user-id, sox-user-idnever takes part in the cache match and the next request with a different value is served the first client's body. The wildcard guard incanCacheResponsemisses the same shape, sinceresHeaders.vary?.includes('*')on an array only matches an entry that is exactly*. With the default shared cache type both paths hand one caller a response that was stored for another.Repro against
interceptors.cache(), with a server that setsvaryto['accept-encoding, a', 'accept-language']and echoes thearequest header: the request witha: alicereaches the origin, and the following request witha: bobis answered from the cache with alice's body.Changes
Split every element of an array-valued Vary header on commas, and share one wildcard check between the parser and
canCacheResponseso a repeated header carrying*also blocks storage.Features
N/A
Bug Fixes
Vary: *is detected when it arrives in a repeated header alongside other field names.Breaking Changes and Deprecations
N/A
Status