Skip to content

🔒 Fix Cache Poisoning via Cache Key Collision - #29

Merged
undivisible merged 2 commits into
mainfrom
fix-cache-key-collision-vuln-17952989123137737949
Sep 2, 2026
Merged

undivisible merged 2 commits into
mainfrom
fix-cache-key-collision-vuln-17952989123137737949

Conversation

@undivisible

@undivisible undivisible commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

🎯 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_key was previously constructed using format!("{}:{}:{}", 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.

⚠️ Risk: Cache poisoning where an attacker overrides caching by colliding values with specific delimiters, rendering the system to serve unauthorized, incorrect, or malicious cache results to users for standard searches.

🛡️ 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, as TtlCache supports keys that implement Eq + Hash. We've added Hash to SearchMode to 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.

SearchMode derives Hash so it can participate in that tuple key for TtlCache.

Reviewed by Cursor Bugbot for commit 60c2c65. Configure here.

- 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>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@undivisible
undivisible merged commit 49b05d3 into main Sep 2, 2026
1 check failed
undivisible added a commit that referenced this pull request Sep 18, 2026
- 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant