fix(cache): check Authorization on request headers per RFC 9111 §3.5#4911
Open
metalix2 wants to merge 1 commit intonodejs:mainfrom
Open
fix(cache): check Authorization on request headers per RFC 9111 §3.5#4911metalix2 wants to merge 1 commit intonodejs:mainfrom
metalix2 wants to merge 1 commit intonodejs:mainfrom
Conversation
metalix2
commented
Mar 19, 2026
| @@ -372,8 +373,16 @@ function canCacheResponse (cacheType, statusCode, resHeaders, cacheControlDirect | |||
| } | |||
|
|
|||
| // https://www.rfc-editor.org/rfc/rfc9111.html#name-storing-responses-to-authen | |||
Contributor
Author
There was a problem hiding this comment.
The code now does what is described in the comment.
Sybsw
approved these changes
Mar 19, 2026
feacffc to
b029a95
Compare
metcoder95
approved these changes
Mar 20, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4911 +/- ##
==========================================
+ Coverage 92.92% 92.94% +0.01%
==========================================
Files 112 112
Lines 35646 35655 +9
==========================================
+ Hits 33123 33138 +15
+ Misses 2523 2517 -6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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...
RFC 9111 §3.5 - Storing Responses to Authenticated Requests I believe I've identified a bug within the cacheHandler logic. I was writing some integration tests which were validating the expected RFC 9111 standards when requests with Authorization headers were being incorrectly cached.
Rationale
canCacheResponse()checkedresHeaders.authorization(response headers) for the Authorization guard. SinceAuthorizationis a request header, this check was dead code — shared caches would store responses to authenticated requests regardless ofdirectives, violating RFC 9111 §3.5.
Changes
Thread
reqHeaders(fromCacheKey.headers) intocanCacheResponse()and check request headers instead of response headers for the Authorization guard.Features
N/A
Bug Fixes
reqHeaders.authorizationinstead ofresHeaders.authorizationincanCacheResponse()s-maxageandmust-revalidateas permitting directives alongsidepublic, per RFC 9111 §3.5public→ cacheds-maxage→ cachedmust-revalidate→ cachedmax-ageonly → not cachedBreaking Changes and Deprecations
Responses to requests containing an
Authorizationheader that previously leaked into shared caches (due to the dead-code bug) will now correctly be excluded unless the response carriespublic,s-maxage, ormust-revalidate. This is a correctness fix, not a feature change.Benchmarks
Status