Skip to content

fix(id): create_pairing_code supersedes earlier codes for the same challenge (#4871) - #5223

Merged
dezren39 merged 2 commits into
mainfrom
queue/7529-4871-pairing-code-supersede
Nov 4, 2026
Merged

dezren39 merged 2 commits into
mainfrom
queue/7529-4871-pairing-code-supersede

Conversation

@dezren39

@dezren39 dezren39 commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

Fixes #4871 (queue task 7529).

What

create_pairing_code in pkgs/id/src/hosted_binding.rs now 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):

  • At most one live pairing code per ceremony — "that code went to the wrong place, give me a new one" now actually revokes the old code.
  • Supersede is per-challenge_id: codes for other challenges are untouched.
  • A rate-limited mint returns RateLimited before any supersede, so a failed mint never revokes a live code.
  • Docs on create_pairing_code and PairingCode state 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 with UnknownChallenge, 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 test pairing_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 ✅


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

@dezren39
dezren39 requested a review from a team as a code owner November 4, 2026 00:44
@coderabbitai

coderabbitai Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You'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.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 386b0ec6-23de-416b-bc5a-14b19d56c950
Commits

Reviewing files that changed from the base of the PR and between f486f2a and 3c72277.

Files selected for processing: 1
  • pkgs/id/src/hosted_binding.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-04T00:51:07.886739Z 3c72277 New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread pkgs/id/src/hosted_binding.rs Outdated
Comment on lines +1131 to +1132
self.pairing_codes
.retain(|_, existing| existing.challenge_id != challenge.challenge_id);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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.

id(hosted_binding): create_pairing_code does not supersede earlier codes — multiple live pairing codes per challenge, none revocable

1 participant