Repository navigation
Vault: keep the card and flag under a stored pairing ID - #360
Conversation
A write that kept a stored entry's device ID and pairing ID but carried another card was treated as an add, so with the pairing authorization it could change the entry's approval flag or swap its approval key, and the Broker kept the pairing's active-approver generation. The stored entry is now the one with the same pairing ID. A flag change for it (same device ID and pairing ID, whatever the card) is refused as approverNotAuthorized, as ADR 0014 words it, and another card under that pairing ID as pairingNotAuthorized, since pairing again derives a new pairing ID. The Broker removal also compares the card. ADR 0014 names the card case in the Vault write rule.
Review fixes for the card and flag rule: - Check each entry against the stored entry with the same device ID and pairing ID first, so a list an earlier build stored with one pairing ID on two devices can still be renamed and emptied; no third device joins that pairing ID. - End the pairing authorization before each unauthorized swap attempt, correct the note on the Mac card swap, and show that a swap refuses a write that also carries an authorized add without using it up. - Doc and comment wording: a write may change anything but the card and flag; the card comparison in the Broker removal is defense in depth.
Round 2 review fixes: - A card swap written with a rename of another entry is one add under the device's authorization, which the card-blind rule accepted; it is now refused. - In a list stored with a shared pairing ID, another approval key for an entry is refused. - The write rule's doc comment names the shared pairing ID case.
Cross review summaryReviewers: GPT-6 Astra (xhigh) and Opus 5.5 (xhigh), read-only, two rounds each (round 2: each ruled on the other's report and reviewed the fixes). Final head Round 1 (
|
| Finding | Severity | Outcome |
|---|---|---|
| A stored list with one pairing ID on two devices (only reachable through the old card-blind rule) got stuck: every write keeping the second entry, including removing the first or processing an unpair notice, was refused, and the flagged entry would come back after a restart | Astra P2, Opus P3 | Fixed in 2df8f65: each entry is checked against the stored entry with the same device ID and pairing ID first; such a list can be renamed and emptied, a third device cannot join the pairing ID, neither entry's flag or card can change |
| The swap test's "without the pairing authorization" cases ran with an authorization left from the previous iteration; the note on the Mac card swap was inaccurate | both P3 | Fixed in 2df8f65 |
| The card comparison in the Broker removal loop can never change the outcome | Opus P3 | Kept as defense in depth; the comment now says so |
The doc comment understated what a write may change (pairedAt) and did not say which error wins |
Opus P3 | Fixed in 2df8f65 |
Round 2 (2df8f65): no P0/P1/P2
Both reviewers confirmed the fallback lookup cannot pass for another device (equal cards imply equal device IDs), no write can create a new shared pairing ID, the removal loop drops a pairing ID whenever any flagged entry under it goes, and the change only refuses more than main. New P3s from Opus:
- The combined-write test also failed on
main(two adds) and so did not test the fix: added a swap written beside a rename of another entry, one add thatmainaccepted, now refused (f8e205a). - The shared-pairing-ID test lacked a card swap: added another approval key for the second entry, refused (
f8e205a). - The write rule's doc comment now names the shared pairing ID case (
f8e205a).
Declined
- Refusing a shared-pairing-ID list at load as
listRefused(Astra round 1, withdrawn in round 2): it forces an identity reset that deletes every pairing for a state no transcript-derived pairing produces. - Making
PairedDeviceList.insertrefuse a pairing ID held by another device (Opus round 1, withdrawn in round 2): it changes the iPhone's shared model; the Vault already refuses it. - App-level tests of the shared-ID removal through the coordinator and messenger hooks and reactivation after a services stop (Opus round 2): those paths are unchanged here; the Vault behavior is covered.
- Replacing the fallback lookup with an explicit refusal (Opus round 2, optional): same behavior.
- Naming the shared-ID tolerance in ADR 0014 (Opus round 2): the ADR describes unique pairing IDs; the doc comment covers lists from earlier builds.
Pre-existing and unchanged, all fail closed: a refused pairing add shows as an expired session rather than a specific error (legitimate pairing cannot hit the new refusal); two flagged entries sharing a pairing ID make activation fail; removing the unflagged entry of a shared list keeps its flagged sibling inactive until the device services restart.
Local results at f8e205a
swift build passes. swift test --filter "AskKeyVaultTests|AskKeyDevicesTests|AskKeyBrokerTests": Vault 582/0 (17 skipped; main 579), Devices 219/0, Broker 271/0. Hygiene and module checks pass. The new card-swap cases fail against main's Vault and the shared-ID test fails against 222b4fe's. CI for 222b4fe was green on all four jobs; CI for f8e205a is running.
Security hardening of the Mac Vault's paired-device write rule, found in the cross review of #357 (review summary). No issue is linked on purpose.
Summary
Vault.savePairedDevicestreated an entry as the stored one only when device ID, pairing ID and card matched. A write that kept the device ID and pairing ID but carried another card was therefore an add: with the management session and that device's pairing authorization it could turn the stored entry's approval flag on or off, or swap the card (and with it the approval key that checks every Allow) under a flag a pairing granted. The Broker removal matched device ID, pairing ID and flag only, so the pairing's active-approver generation survived the swap. ADR 0014 → Approvers refuses any flag change for the same device ID and pairing ID, with no card condition.PairingSessionnever produces such a write (the pairing ID is derived from the transcript, which covers both cards); only a bug in an app-side writer could reach it.approverNotAuthorized, exactly as ADR 0014 words it, and any other card under that pairing ID (a newer card, another approval key, another platform, or another device) is refused aspairingNotAuthorized. Treating a card change as removal plus add was the alternative; it would let a card swap turn the flag on for an existing pairing ID and let a revoked pairing ID re-enter the active-approver set without a suspension, both of which ADR 0014 rules out ("a new pairing always has a new pairing ID"). Refusing matches the ADR text with the smaller change.DeviceStorageError.pairingNotAuthorized,.approverNotAuthorizedandsavePairedDevicesstate the rule. ADR 0014 → Approvers → Vault write rule names the card case in one sentence, because it is a refusal the ADR did not state.Diff stat
Base
1b2ca91(main after #357), headf8e205a(222b4fechange,2df8f65andf8e205areview fixes).Tests
swift build: passes.swift test --filter "AskKeyVaultTests|AskKeyDevicesTests|AskKeyBrokerTests"atf8e205a: Vault 582 passed, 0 failed, 17 skipped (main: 579/0/17; +3 new tests); Devices 219/0 (main 219); Broker 271/0.DeviceApproverFlagTests(19 tests), all passing. Changed and added:testAWriteCannotSwapTheCardOfAFlaggedEntry(updated): a flagged entry's card cannot be replaced under its pairing ID by a card with another approval key, a newer card or a Mac card, with or without the pairing authorization or as a list written directly, nor can another device take that pairing ID; a swap refuses a write that also carries an authorized add (without using up the authorization) and a write that pairs it with a rename of another entry; the stored entry and the Broker generation stay as they were.testACardSwapCannotChangeTheFlag(new): under the device's pairing authorization, a card swap neither turns a stored entry's flag on nor turns it off; the unflagged pairing never joins the active-approver set.testPairingAgainWithANewCardEndsTheOldAuthorityAndFlagsTheNewEntry(new): pairing again with a new card and pairing ID, starting from a flagged or an unflagged entry, drops the old pairing ID from the Broker set (the revocation counter grows) and stores the new entry flagged; it joins the set with a newer generation.testAStoredListWithASharedPairingIDCanStillBeRenamedAndEmptied(new): a list sealed directly with one pairing ID on two devices refuses a third device under it, a flag change and another approval key for the second entry, and still allows a rename and both removals; removing the flagged entry ends the pairing ID's Broker authority.Sources/AskKeyVault/Vault+Devices.swiftat main, the card-swap tests fail (19 failures at222b4fe; the cases added inf8e205afail there too); with it at222b4fe, the shared-pairing-ID test fails (a rename is refused). The pairing-again test passes on every version, as a legitimate flow should.f8e205a: build-and-test, basic-ui-flows, ios-app and release-sdk-window-check all green (the full suite and the desktop flows).Checks
python3 scripts/check_hygiene.py: passed.python3 scripts/check_module_deps.py: passed.Vault+Devices.swift466,DeviceApproverFlagTests.swift518).Deviations and questions
None. The cross review summary is in a comment below.