Repository navigation
fix: say private for every route keyed per caller under scope public - #262
Merged
Merged
Conversation
With `cacheControl.scope: "public"`, routes keyed per caller are downgraded
to private, because a shared cache told their responses are public could
hand one caller's response to another. The check compared
`keys.useAuth === true`, while the key generator puts the caller in the key
for any truthy useAuth. A raw string - `useAuth: env("X")` without
env.bool - therefore keyed entries per caller and still went out public.
The downgrade and its boot warning now use truthiness, as the key generator
does. Only configurations with a truthy non-boolean useAuth under scope
public change, and only from public to private.
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.
What changed and why
With
cacheControl.scope: "public", the plugin downgrades routes whose entries are keyed per caller (keys.useAuth) toprivate. A shared cache told those responses are public could hand one caller's response to another (#113).The downgrade checked
keys.useAuth === true. The key generator (generateCacheKey.ts) puts the caller in the key for any truthyuseAuth. A raw string, which is whatuseAuth: env("X")withoutenv.boolgives, therefore:public, so a CDN or proxy could serve one caller's response to another.Reproduced with category's
useAuthset to the string"true"and scope public: both the MISS and the HIT carriedpublic, max-age=3600on a route keyed per caller.Fix: the downgrade in
buildCacheControl.ts, and its boot warning inresolveUserStrategy.ts, now test truthiness, matching the key generator.Non-breaking:
useAuthunder scopepublicchange, and only frompublictoprivate, which is safer.true/falseconfigs, keys, and what's cached are unchanged.Found by the audit of #259, which aligns the "Shared across callers" badge and warning the same way.
Tests
cacheControl: scope public, useAuth set to a truthy non-booleanblock inshared/tests/flag-cache-control.test.js, using an opt-inCATEGORY_USE_AUTH_RAWfixture switch:main:Expected "private, max-age=3600",Received "public, max-age=3600".test:lintis green.Checklist
pnpm run test:e2e:memorypasses.pnpm run test:lintpasses.main.