🔒 Fix Cache Poisoning via Cache Key Collision - #29
Conversation
- Update `cache: cache::TtlCache<String, SearchResponse>` to `cache: cache::TtlCache<(bool, SearchMode, String), SearchResponse>` in `SearchClient` - Derived `Hash` for `SearchMode` - Switched to tuple cache key from string formatter to mitigate cache poisonings Co-authored-by: undivisible <136312656+undivisible@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
- Update `cache: cache::TtlCache<String, SearchResponse>` to `cache: cache::TtlCache<(bool, SearchMode, String), SearchResponse>` in `SearchClient` - Derived `Hash` for `SearchMode` - Switched to tuple cache key from string formatter to mitigate cache poisonings
🎯 What: This PR fixes a cache poisoning vulnerability caused by a cache key collision due to string interpolation that an attacker could easily bypass. The
cache_keywas previously constructed usingformat!("{}:{}:{}", self.embedded, query.mode().as_str(), query.to_query_string()), which meant an attacker could exploit strings with user input containing delimiters to cause a cache collision and overwrite results for a victim's search query.🛡️ Solution: The solution avoids string interpolation and strictly uses the type system to enforce caching logic. We convert the
SearchClient's cache key to a(bool, SearchMode, String)tuple, asTtlCachesupports keys that implementEq + Hash. We've addedHashtoSearchModeto support this fix.PR created automatically by Jules for task 17952989123137737949 started by @undivisible
Note
Low Risk
Localized cache-key change with no API or search behavior changes beyond fixing incorrect cache hits.
Overview
SearchClient no longer builds cache keys with
format!and colon-separated fields. Keys are now(embedded, SearchMode, query_string)so embedded flag, mode, and serialized query are hashed as separate fields instead of one ambiguous string.SearchModederivesHashso it can participate in that tuple key forTtlCache.Reviewed by Cursor Bugbot for commit 60c2c65. Configure here.