Repository navigation
fix(cache): send private to credentialed requests on cache_authorized routes - #373
Merged
Merged
Conversation
… routes cache_authorized=True keys the backend entry on the caller, but its responses kept the decorator's Cache-Control, which a shared cache keyed on the URL may store and replay to other users. They now carry private, like the bypassed ones. Session dependencies also mark the request as having read the session, so the session middlewares add Vary for the token sources as they do for request.session. Fixes #372
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.
Fixes #372
Summary
@cache(cache_authorized=True)still reads and writes the backend for requests withAuthorizationor a session, but every answer to them (miss, hit, 304) now carriesprivatein place ofpublic, with the decorator's other directives kept. The per-caller key only exists in this backend; a CDN in front of the app keys on the URL alone.get_session/get_optional_session(and the dependencies built on them) flag the request as having read the session, soFastAPICacheXSessionMiddlewareand the deprecatedSessionMiddlewareaddVaryfor the token sources, the same as arequest.sessionaccess.Vary: Authorizationby hand.372.security.md;362.security.mdno longer listscache_authorizedas exempt fromprivate.Tests
tests/session/test_cache_authorized_private.py, with two existing expectations updated.cache.pyfails 7 tests, dropping the dependency flag fails 4, and dropping the deprecated middleware change fails 1.--strict.