Repository navigation
Verify row ownership in Redis upstream token read - #6876
Merged
ChrisJBurns merged 1 commit intoOct 20, 2026
Merged
Conversation
GetLatestUpstreamTokensForUser trusted the user-upstream index to name only rows belonging to the requested user. parseUserUpstreamEntry rejected a mismatched ProviderID but never compared the stored UserID, so a foreign-owned row named by that set would be decoded and could win the expiry-based selection. No caller can reach that state today: the index is keyed by user and every writer files its row under its own UserID. The check is worth making anyway. The user-upstream set has no TTL and is never garbage collected, so it is the one index where dead members accumulate, and the memory backend already recomputes ownership while scanning. Once session identifiers stop being random per authorize flow, this becomes the main protection rather than a backup. Ownership validation on the DeleteUser cascade is left out; it belongs with the user-keyed storage work. Closes stacklok#6273 Signed-off-by: hellouz818 <[email protected]>
hellouz818
requested review from
ChrisJBurns,
JAORMX,
jhrozek,
rdimitrov and
tgrunnagle
as code owners
October 20, 2026 08:05
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6876 +/- ##
==========================================
- Coverage 79.77% 79.77% -0.01%
==========================================
Files 820 820
Lines 83723 83723
==========================================
- Hits 66791 66787 -4
- Misses 16927 16931 +4
Partials 5 5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
ChrisJBurns
approved these changes
Oct 20, 2026
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.
Summary
GetLatestUpstreamTokensForUseron the Redis backend trusted the user-upstream index to name only rows belonging to the requested user.parseUserUpstreamEntryrejected a mismatchedProviderIDbut never compared the storedUserID, so a foreign-owned row named by that set would be decoded and could win the expiry-based selection.This is hardening, not a reachable bug. Index members are
prefix:upstream:{sessionID}:{providerName},sessionIDis a per-flowrand.Text()value, and every writer files its row under its ownUserID, so no caller can produce a foreign row in another user's set today. It is worth closing anyway:warnOnCleanupErrnamesKeyTypeUserUpstreamas one of the sets awaiting a cleanup job — making it the one index where dead members accumulate.memory.go), so Redis was the asymmetric one: it pushed the user filter into the index key and never re-checked the row.maybeCarryForwardRefreshTokenalready depends on this postcondition, and once session identifiers stop being random per authorize flow, this check becomes the main protection rather than a backup.What changed:
parseUserUpstreamEntrytakes the requesteduserIDand rejects rows whose storedUserIDdiffers, alongside the existingProviderIDcheck.TestRedisStorage_GetLatestUpstreamTokensForUser.Ownership validation on the
DeleteUsercascade is deliberately left out, per the scope agreed on the issue; it belongs with the user-keyed storage work.Closes #6273
Type of change
Test plan
task test)task test-e2e)task lint-fix)task test,task lintandtask docs-verifyall exit 0 on this branch, rebased ontomainat 89b1bd2.The two new subtests plant a foreign-owned member directly with
mr.SAddonredisSetKey(keyPrefix, KeyTypeUserUpstream, "user-A"), following the existing precedent in this file:foreign_owned_member_not_returned— a foreign row alone must yieldErrNotFound.foreign_owned_member_does_not_win_selection— a foreign row with a laterExpiresAtcompeting against the user's legitimate row must not win the tie-break. The first test alone cannot catch that.Mutation-checked: removing the
UserIDcomparison fails exactly these two subtests and no others.Does this introduce a user-facing change?
No.
Special notes for reviewers
Both backends already carry a
different_user_not_matchedsubtest, and the Redis one has a comment saying it passes via the empty-SMEMBERSshort-circuit rather than a per-row check — so the gap was known, and no existing test asserted the postcondition at row level.The comparison is folded into the existing
ProviderIDcondition rather than added as a separate block, since both are the same "row does not match the request" rejection and the rationale lives in the function's doc comment. Happy to split it if you'd prefer the check called out on its own.