fix: Profile Share-Card Cache Collision: Incomplete Cache Key Causes Stale Card Served After Avatar/Bio Change#510
Open
prince-shakyaa wants to merge 2 commits into
Conversation
added 2 commits
May 23, 2026 00:29
…elds The cache key previously only included username, total_points, badges, and challenge counts. This caused stale PNG cards to be served after a user updated their avatar URL/emoji or bio without changing their score. - Add avatar_type, avatar_url, avatar_emoji, and bio to the cache key - Upgrade hash algorithm from MD5 to SHA-256 Fixes GenAI-Security-Project#508
…rity-Project#508) 9 tests covering: - BUG-508-001: Confirms original MD5 collision defect - BUG-508-002: Key changes on avatar_url update - BUG-508-003: Key changes on avatar_emoji update - BUG-508-004: Key changes on avatar_type update - BUG-508-005: Key changes on bio update - BUG-508-006: Key is stable when profile is unchanged - BUG-508-007: Key still changes on score update - BUG-508-008: Key uses SHA-256 (guards against MD5 regression) - BUG-508-009: None/empty fields handled gracefully
Author
|
Hii @saikishu , @e2hln |
Contributor
|
didn't test the unit test, but the bug fix lgtm |
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.
Fix: Profile Share-Card Cache Collision (Fixes #508)
What This PR Does
Fixes an incomplete cache key in the profile share-card endpoint (
/share/profile/{username}/card.png) that caused stale PNG cards to be served indefinitely after a user updated their avatar or bio — as long as their points, badges, and challenge counts remained unchanged.Problem
The cache key was computed from only four fields:
The fields
avatar_type,avatar_url,avatar_emoji, andbio— all of which are visually prominent on the card — were excluded. This meant:Fix
Include all visual identity fields in the cache key so that any profile change triggers a fresh render:
Files Changed
finbot/apps/ctf/routes/share.pyavatar_type,avatar_url,avatar_emoji,bio; switch from MD5 to SHA-256tests/unit/apps/ctf/test_share_card_cache_key.pyHow to Test
alice).avatar_type = "url"with any image URL and add a bio.GET /share/profile/alice/card.png— card is rendered and cached.GET /share/profile/alice/card.pngagain.Tests
9 unit tests added in
tests/unit/apps/ctf/test_share_card_cache_key.py:BUG-508-001BUG-508-002avatar_urlis updatedBUG-508-003avatar_emojiis updatedBUG-508-004avatar_typechanges (e.g.url→gravatar)BUG-508-005biois updatedBUG-508-006BUG-508-007BUG-508-008BUG-508-009None/ empty optional fields handled gracefully — no crashType of Change
Checklist
Related