Repository navigation
fix(id): create_pairing_code supersedes earlier codes for the same challenge (#4871) - #5223
Conversation
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 47 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b1d92bb5d5
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| self.pairing_codes | ||
| .retain(|_, existing| existing.challenge_id != challenge.challenge_id); |
There was a problem hiding this comment.
Exclude the superseded code when generating its replacement
When a user refreshes a code because it went to the wrong place, removing it before generating the replacement allows the RNG to select that same six-digit string again. The subsequent contains_key check no longer excludes it, so the supposedly revoked credential still exchanges successfully (approximately a one-in-a-million chance with an otherwise empty map). Previously, the existing entry prevented this immediate reuse. Generate the replacement while the old code is still excluded, then remove the superseded entry; the regression test should assert rejection rather than skip it when code_a == code_b.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 3c72277 — agreed, the ordering was wrong. The replacement code is now generated while the superseded codes are still in the map (so the collision loop excludes the just-revoked string), and only then does the retain supersede them, followed by the insert. The regression test now asserts code_a != code_b and rejects the superseded code unconditionally. Re-ran cargo test -p id --lib hosted_binding: 22 passed.
Fixes #4871 (queue task 7529).
What
create_pairing_codeinpkgs/id/src/hosted_binding.rsnow supersedes every previously minted, unexchanged pairing code for the same challenge before minting the new one (pairing_codes.retain(...)after rate-limit accounting, before code generation):challenge_id: codes for other challenges are untouched.RateLimitedbefore any supersede, so a failed mint never revokes a live code.create_pairing_codeandPairingCodestate the one-live-code contract.Test
New regression test
minting_a_pairing_code_supersedes_earlier_codes_for_the_challenge: code A minted, code B minted for the same challenge → exchanging A fails withUnknownChallenge, exchanging B succeeds and returns the challenge, B is still single-use, and a code for a different challenge still exchanges.Verified on the laptop worktree:
cargo test -p id --lib hosted_binding— 22 passed, 0 failed (including the new test and the preserved expiry/rate-limit testpairing_codes_expire_with_the_challenge_and_rate_limit).Acceptance mapping: supersede behaviour ✅ · regression test (A fails / B succeeds) ✅ · single-code single-use + rate limit + expiry preserved (existing tests pass) ✅ · no production behaviour change beyond the pairing-code invalidation ✅
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.