interceptors: enforce cache-after-redirect composition order #6220
All Vouch review confidence checks passed
Residual risk 0.14 = Change Risk (0.50) × (1 − Review Confidence (0.71)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.50 · 213 lines diff across 11 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.53 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.321
Real PR Conversation Timeline
4 items
Codecov Report
:white_check_mark: All modified and coverable lines are covered by tests.
:white_check_mark: Project coverage is 91.68%. Comparing base (
02c4f8c) to head (cefb273).:warning: Report is 5 commits behind head on main.
<details><summary>Additional details and impacted files</summary>
@@ Coverage Diff @@
## main #6220 +/- ##
=======================================
Coverage 91.68% 91.68%
=======================================
Files 113 113
Lines 44462 44520 +58
=======================================
+ Hits 40763 40820 +57
- Misses 3699 3700 +1
</details>
:umbrella: View full report in Codecov by Harness.
:loudspeaker: Have feedback on the report? Share it here.
<details><summary> :rocket: New features to boost your workflow: </summary>
</details>
Approved
Approved these changes.
Approved
Approved these changes.
ronag
mcollina
This relates to...
Rationale
All of the above were fixed in the cache handler's redirect guards. Those guards
depend on
CacheHandlerobserving the redirect history threaded throughcontext.historyby the redirect handler. That only happens when the cachehandler is composed below the redirect handler.
When
cache()is composed beforeredirect(), the cache handler is wrappedabove the redirect handler and never receives the history, so every
history-based guard is silently disabled. The result is reproducible against the
current tree:
response under the trusted key and replays it to a later caller without
contacting either origin (
substituted: true,trustedHits: 1,attackerHits: 1)./me -> /profile/{user}leaks Alice'sresponse to Bob (
bob == ALICE ssn=...,me:1 profile:1).The existing reverse-order regression test only "passes" because its 302 is not
explicitly cacheable, so it never exercises the vulnerable storage path.
Changes
Interceptors are opaque functions, so
Dispatcher.compose()cannot tell whichones are order-sensitive without metadata. This change:
cache,redirect, anddeduplicateinterceptors with akInterceptorKindsymbol.Dispatcher.compose()throw anInvalidArgumentErrorwhencacheiscomposed before
redirect, with a message naming the affected CVEs.docs/docs/api/Dispatcher.mdanddocs/docs/api/Interceptors.md.deduplicateis in the same set (it participates in the redirect-historycontract and copies request options), but it has no positional constraint of its
own: cache must follow redirect regardless of where
deduplicatesits. Verifiedempirically across all 8 orderings of
cache/redirect/deduplicate.Features
N/A
Bug Fixes
that silently disables the cache's cross-origin and credential redirect
guards.
Breaking Changes and Deprecations
compose(cache(), redirect())now throwsInvalidArgumentErrorinstead ofsilently producing an unsafe shared cache. This is a semver-major change
(the previous order did work, just unsafely); I propose backporting it to v7.
Note: the relative order of interceptors is fundamentally the end-user's
responsibility (they wrap each other). This is a fail-fast guard against the one
order we know to be dangerous, not a reordering of interceptors.
Status
[cert]: https://github.com/nodejs/undici/blob/main/CONTRIBUTING.md#developers-certificate-of-origin