9
2
Fork
You've already forked platform
2

fix(gateway): split QR login requester and requestee tokens #363

Manually merged
ryansquared merged 3 commits from fix/issue-336-split-qr-login-tokens into main 2026年07月09日 16:55:20 +02:00

Summary

  • generate a separate requestee token for the QR login URL while keeping the requester token for status polling
  • store and look up the requestee token for browser-side QR authentication and completion
  • add a focused regression test that ensures the QR URL does not expose the requester token

Fixes #336

Test plan

  • cargo test -p gateway qr_login_url_uses_requestee_token_only -- --nocapture
  • cargo test -p gateway
  • cargo clippy -p gateway --all-targets --all-features (passes with existing warnings)
  • cargo test -p api -p gateway
  • git diff --check
## Summary - generate a separate requestee token for the QR login URL while keeping the requester token for status polling - store and look up the requestee token for browser-side QR authentication and completion - add a focused regression test that ensures the QR URL does not expose the requester token Fixes #336 ## Test plan - `cargo test -p gateway qr_login_url_uses_requestee_token_only -- --nocapture` - `cargo test -p gateway` - `cargo clippy -p gateway --all-targets --all-features` (passes with existing warnings) - `cargo test -p api -p gateway` - `git diff --check`
consume_qr_login_session_id returned the post-update NULL from RETURNING, so every completed poll 500'd and lost the session; return the pre-update value via a CTE. Also fetch the auth session before consuming so a transient failure is retry-safe.

Pushed two follow-up fixes to the consume path, both verified end-to-end against a local stack:

  1. consume_qr_login_session_id was broken — SET session_id = NULL ... RETURNING session_id returns the post-update value (NULL), so it failed to decode and 500'd on every completed poll, while the UPDATE still committed. Net effect: every successful QR login would 500 and permanently lose its session. Fixed by capturing the old value in a FOR UPDATE CTE.
  2. Consume-before-fetch was fragile — reordered so the auth session is fetched before consuming; a transient failure (e.g. get_auth_session error, dropped response) no longer orphans a genuine login — the next poll recovers it.

Verified: gateway unit tests, seeded one-shot/split/retry checks, a begin+authenticate split walk, and a full ceremony with a real signed WebAuthn assertion (Chrome virtual authenticator) — first poll returns the session, second returns none, requestee token can't poll status. Also added the retry-safety/one-shot/split cases to tests/cross-device-qr.md

Pushed two follow-up fixes to the consume path, both verified end-to-end against a local stack: 1. `consume_qr_login_session_id` was broken — `SET session_id = NULL ... RETURNING session_id` returns the post-update value (NULL), so it failed to decode and 500'd on every completed poll, while the UPDATE still committed. Net effect: every successful QR login would 500 and permanently lose its session. Fixed by capturing the old value in a FOR UPDATE CTE. 2. Consume-before-fetch was fragile — reordered so the auth session is fetched before consuming; a transient failure (e.g. get_auth_session error, dropped response) no longer orphans a genuine login — the next poll recovers it. Verified: gateway unit tests, seeded one-shot/split/retry checks, a begin+authenticate split walk, and a full ceremony with a real signed WebAuthn assertion (Chrome virtual authenticator) — first poll returns the session, second returns none, requestee token can't poll status. Also added the retry-safety/one-shot/split cases to `tests/cross-device-qr.md`
Adds tests/e2e/test_qr_login.sh (+ make test-e2e-qr-login) covering the token split, one-shot consumption, and retry-safety. Logs when a completed poll finds the session already consumed.

Addressed the review:

  • Automated test (the main gap): added tests/e2e/test_qr_login.sh + make test-e2e-qr-login, asserting the requester/requestee split, one-shot consumption, requestee-can't-poll-status, and retry-safety (fault-injects a failing get_auth_session and verifies the session id survives). 8/8 pass; it fails on the pre-fix code.
  • Reworded the now-inaccurate runbook comment (consume happens after the session fetch, not after building the response).
  • Added a tracing::debug! when a completed poll finds the session already consumed.

On the concurrent-poll race: the e2e covers one-shot behavior, but a true concurrency test for the FOR UPDATE CTE needs a DB-backed harness this crate doesn't have yet — flagging as a follow-up rather than expanding scope here. Left the lost-race response as completed/session_id: null (no new sub-status) since the requester token is polled by a single client sequentially, so that path is just the expected second poll.

Addressed the review: - Automated test (the main gap): added tests/e2e/test_qr_login.sh + make test-e2e-qr-login, asserting the requester/requestee split, one-shot consumption, requestee-can't-poll-status, and retry-safety (fault-injects a failing get_auth_session and verifies the session id survives). 8/8 pass; it fails on the pre-fix code. - Reworded the now-inaccurate runbook comment (consume happens after the session fetch, not after building the response). - Added a tracing::debug! when a completed poll finds the session already consumed. On the concurrent-poll race: the e2e covers one-shot behavior, but a true concurrency test for the FOR UPDATE CTE needs a DB-backed harness this crate doesn't have yet — flagging as a follow-up rather than expanding scope here. Left the lost-race response as completed/session_id: null (no new sub-status) since the requester token is polled by a single client sequentially, so that path is just the expected second poll.
ryansquared manually merged commit 7850e0e298 into main 2026年07月09日 16:55:20 +02:00
Sign in to join this conversation.
No reviewers
Labels
Clear labels
Compat/Breaking
Breaking change that won't be backward compatible
Component/Enclave-Builder
This issue affects Enclave Builder (git-push and CLI)
Component/Infrastructure
This issue affects generic Caution hosted infra components
Deploy/BYOC
Relates to Caution Bring-your-own-compute
Deploy/Full-managed
Relates to Caution fully managed cloud
Deploy/Self-hosted
Relates to Caution deployed on self-hosted infra
Interface/API
This issue affects the API
Interface/CLI
This issue affects the command line interface
Interface/Git
This issue affects the Git `push` interface
Interface/Web
This issue affects the web dashboard
Kind/Bug
Something is not working
Kind/Documentation
Documentation changes
Kind/Enhancement
Improve existing functionality
Kind/Feature
New functionality
Kind/Security
This is security issue
Kind/Testing
Issue or pull request related to testing
Priority
Critical
The priority is critical
Priority
High
The priority is high
Priority
Low
The priority is low
Priority
Medium
The priority is medium
Reviewed
Confirmed
Issue has been confirmed
Reviewed
Duplicate
This issue or pull request already exists
Reviewed
Invalid
Invalid issue
Reviewed
Won't Fix
This issue won't be fixed
Status
Abandoned
Somebody has started to work on this but abandoned work
Status
Blocked
Something is blocking this issue or pull request
Status
Need More Info
Feedback is required to reproduce issue or to continue work
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
caution/platform!363
Reference in a new issue
caution/platform
No description provided.
Delete branch "fix/issue-336-split-qr-login-tokens"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?