feat(cache)!: store a query over 200 bytes as its SHA-256 digest - #408
Merged
Merged
Conversation
The query component of an HTTP cache key was the full query string, so a client could make keys arbitrarily long. A query longer than 200 bytes as encoded in the key is now stored as `sha256:` and its full hex digest, taken after sorting so `sort_query` still merges reordered long queries. The path stays readable, so `clear_path()` still finds the entry, and the monitoring routes show the digest as `query_params`. A query as sent never starts with `sha256:`, since `:` is encoded as `%3A`. BREAKING CHANGE: keys for requests with a query over 200 bytes change, so those entries are cached afresh once. Closes #269
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.
Fourth of the 0.4.0 cache-key changes, after #405, #406 and #407.
What changes
sha256:plus the full 64-digit hex digest (_QUERY_HASH_THRESHOLD, not configurable), so a client cannot make the query part of a key arbitrarily long.sort_query=Truestill merges reordered long queries.str(QueryParams)/urlencodewrite:as%3A.clear_path()finds such entries withinclude_params=True, and the monitoring routes show the digest asquery_params(no new field).@cache,build_cache_key()andinvalidate()all go throughCacheKey.from_request, so they agree.Docs
HTTP_CACHING.mdandCACHE_FLOW.md(English and zh-TW) describe the rule. They note that Memcached still hashes a whole key over 250 bytes, which a query just under the threshold with a long host or path can reach.MIGRATING_0_4.mdstates the exact threshold.changelog.d/269.changed.md.Tests
tests/test_query_hash.pycovers:clear_pathwith and withoutinclude_params;invalidate(), including a reordered long query withsort_query=True.Closes #269