Repository navigation
fix(desktop): ask before a connect link pairs this computer - #2780
Conversation
An openadapt://connect link used to redeem its pairing code as soon as the operating system delivered it. Anyone can create a pairing code and put it in a link, so one click could move a Desktop to another Cloud workspace. A connect link now only stages the request in the engine. The window shows the target host, says when the link would replace the current pairing (also on the same host, since that can still be another workspace), and redeems nothing until the person clicks Allow. Allow carries the request id the window showed, so a second link that arrives before the click can't be allowed by it. The staged code stays in engine memory, expires after ten minutes, and is used at most once. Cloud has no way to look up a code without redeeming it, so the dialog says the workspace isn't known yet. The engine now refuses connect links for a Cloud server on this computer unless the developer setting allow_local_pairing is on (env OPENADAPT_ALLOW_LOCAL_PAIRING or config.toml). Links for app.openadapt.ai are unchanged; every other host was already refused. The main window no longer has shell execute or spawn permission on the engine sidecar. Rust starts the sidecar itself and no frontend code used the shell plugin.
Test the dialog for a link that arrives while the app is open, that the loopback socket can't send Allow, and that the window can't turn on local pairing. Drop an unused countdown field from the prompt and update the installer doc.
Allow on a connect link no longer makes the new connection active. An attacker's code for their own workspace also names app.openadapt.ai, so the host alone can't tell the person anything. Allow now claims the code and checks the new credential without writing it to the keychain or changing the Cloud host. The window then names the workspace and account Cloud reported and the current workspace, with "Switch to <workspace>" and "Keep <current>". Only Switch stages and commits the credential (the existing rollback path). Keep, a 90-second timeout, a new link or a restart revokes or drops it; Cloud also revokes a claim nobody confirms within two minutes. Workspaces are compared by id, since whoever makes the code chooses the name. If Cloud's answer names no workspace, Desktop revokes the claim, keeps its current connection and shows an error. Desktop asks for the names with include_identity in the claim request; Cloud doesn't send them yet, so until it does every connect link ends with that error. Signing in from Desktop is unaffected.
The Allow and Switch/Keep steps for openadapt:// connect links now live in openadapt_desktop/pairing_confirm.py, one class that holds the staged link and the reviewed claim. dispatch.py registers its handlers in one line, as it does for Chrome profiles, and drops to 6502 lines; its size budget drops to match.
Independent adversarial review: REQUEST CHANGESFrom: Grok I started on
One gap defeats the stated defense, though: a code's creator chooses the workspace name, and the Switch dialog shows only names. Blocking1. A same-name workspace looks the same in the Switch dialog. The id comparison barely reaches the person.
2. The silent swap from my first pass still exists at the Allow step, and it chains with finding 1.
Needs another agent (Cloud)
Non-blocking
Checked and OK
Generality gate
Tests at this head (box, Linux)
Not run
CI at this headAt review time, the main To the PR author: please surface the id mismatch for same-name workspaces, refuse conflicting pending links, and request a re-review on the new head. The Cloud response shape needs its owner. I didn't push to this branch. |
Whoever creates a pairing code picks its workspace name, so the Switch question could read the same for the person's own workspace and for a different one named like it. - When the link's workspace has a different id but the current workspace's name (NFKC, case and whitespace folded), say "This is a different workspace that is also named <name>". - Both buttons carry a short workspace id, and Switch carries the account email, so the two can't read alike. - A second, different connect link no longer replaces the question on screen. Desktop drops both requests, revokes any reviewed claim and says "Two different connect links arrived. Nothing changed." - Sign-in and sign-out forget the workspace a connect link recorded, so a later dialog can't offer to keep a stale workspace.
… test config A link that arrives after two conflicting links asks a fresh question, and nothing can tell it from the person's own. Mark that question and the Switch question after it, and say so plainly in the module docs. Point OPENADAPT_CONFIG_TOML at a temporary file for every test, so sign-in and sign-out tests can't write the developer's real ~/.openadapt/config.toml.
Independent adversarial review: REQUEST CHANGESFrom: Grok This head adds two commits on top of Fixed. A different workspace that reuses the current name is now called out ("This is a different workspace that is also named …"), and the Switch / Keep buttons include a short workspace id and the account email when Cloud sent one. A second, different link that arrives while Allow or Switch is open no longer swaps the question: both requests are dropped, the window shows the two-links error, and a later question is marked Still blocking: a required Desktop test is red, and it is caused by this PR. Still true, as the PR already says: Cloud has to return Tests at this head (box, Linux)
Not run
CI at this headThe Desktop Python engine job fails on the approval-mode allowlist test above. Other package jobs were still pending when I posted. gitleaks and the lock-file checks had passed. To the PR author: please fix that allowlist test and request a re-review. I didn't push to this branch. |
…mand The approval-mode inventory counts every command named with "approval" or "switch". pairing_switch switches the Cloud connection after a connect link, so list it as an explicit exception, and add a test that it is the connect-link Switch and can't change approval mode.
Independent adversarial review: APPROVEFrom: Grok This head adds one test-only commit on top of Prior blockers
Bypass probes (temporary edits, reverted)I made each edit, ran the two tests, then reverted it:
The exemption is by exact name, and the handler is pinned by identity. A renamed command or a different binding can't slip through. Tests at this head (box, Linux, Python 3.14,
|
Blocked on Cloud
Cloud ships first; this PR merges after it. Until Cloud answers with the fields below, Desktop revokes every connect-link claim. Browser sign-in from Desktop is unaffected.
With today's Cloud answer, Desktop revokes the claim, keeps its current connection, and shows:
Contract for
POST /api/local-bridge/pairings/claimRequest. Desktop already sends this JSON body. Cloud ignores unknown request fields today, so it is safe now.
pairing_secretoap_…code from the linkdevice_nameinclude_identitytruefrom Desktop 0.35.1Response when
include_identityistrue(status 201 as today, which Desktop requires;Cache-Control: no-storeas today). The existing five keys stay as they are, and two keys are added:workspaceworkspace.id8-4-4-4-12)orgs.idfor the pairing row'sorg_idworkspace.nameorgs.nameaccountnullaccount.email@{ "paired": true, "pairing_id": "…", "ingest_token_id": "…", "ingest_token": "oai_ingest_…", "credential": { "…": "unchanged" }, "workspace": { "id": "6f9d2c1e-0b7a-4c3e-9a51-2d8f4b6e7a10", "name": "Northside Clinic" }, "account": { "email": "pat@example.com" } }Rules Cloud must keep:
include_identity: true, the response keeps exactly the five keyspaired,pairing_id,ingest_token_id,ingest_tokenandcredential. Released Desktops abort a claim with any extra key, andopenadapt loginuses the same route.workspaceandaccount.What Desktop does with it.
idand a non-emptyname. Without one, Desktop revokes the claim as above.id. It removes control and bidi characters from names and caps them at 120 characters.accountmay be missing ornull. The dialog then shows no email.The problem
An
openadapt://connect?pairing=oap_…&host=…link used to redeem its pairing code as soon as the operating system delivered it. Anyone can create a pairing code in their own workspace on app.openadapt.ai and put it in a link. One click could move a Desktop to that workspace, and the host on screen is app.openadapt.ai either way.What changed
Step 1: Allow (link → claim)
connect_urionly stages the request in engine memory. It sends nothing to Cloud, writes nothing to the keychain and leaves the config alone. The staged code expires after 5 minutes, which is Cloud's code lifetime.pairing_allowmust carry the request id the window showed, and works once.Step 2: Switch or Keep (claim → active)
pairing_allowclaims the code and checks the new credential. It asks Cloud for names withinclude_identity: true.hosted_hostdoesn't change, and the review never runs crash recovery, which would otherwise make an unfinished earlier connection active.pairing_switch(with the shown request id) is the only path to the active credential. It runs the existing stage, validate, commit and confirm path with rollback. It then recordspaired_workspace_idandpaired_workspace_name, so the next link can name the current workspace. Pairings made before this change show "a workspace OpenAdapt didn't record".Two different links never swap the question. If a second, different link arrives while a request waits for Allow or Switch, Desktop drops both, revokes any claim, and shows "Two different connect links arrived. Nothing changed. Open the link you created again." (After Allow the first code is spent, so that message asks for a new connection from Cloud settings instead.) The same link delivered twice, which launch and single-instance can both do, keeps the question on screen. A link can still cancel a pending request, but it can't take the place of the one the person is reading.
A link that arrives after that conflict asks a fresh question, and nothing can tell it from the person's own link opened again. So for 5 minutes after a conflict, the Allow and Switch questions add "Two different connect links arrived a moment ago. Continue only if you just opened your own link again." The real check stays at Switch, which names the workspace by id and the account by email.
Stale workspace names. Browser sign-in, token sign-in and sign-out clear
paired_workspace_idandpaired_workspace_name, so a later dialog can't offer to keep a workspace this computer no longer uses. Two paths still don't clear them: crash recovery finishing an interrupted Switch, andopenadapt loginrun outside Desktop. The worst case there is a dialog naming the old workspace, and the ids on the buttons still differ.Where the code lives. The confirmation steps are in a new module,
openadapt_desktop/pairing_confirm.py. ItsPairingConfirmationclass holds the staged link and the reviewed claim.dispatch.pyregisters the handlers in one line, as it does for Chrome profiles. It drops to 6501 lines (main: 6520), and its size budget inDECOMPOSITION.mddrops from 6524 to 6501. The sign-in clearing lives inpairing_confirm.pytoo. The earlierciandsmokefailures were this PR's: the size ratchet runs first in the smoke job, anddispatch.pywas 6792 lines. Smoke passes on other recent PRs (#2782, #2779, #2778).Window only.
pairing_status,pairing_allow,pairing_switch,pairing_keepandpairing_denyare outside the loopback socket's command list, so the tray and local agents can't send them. Neither the code nor the new bearer ever appears in an event.Host allowlist
allow_local_pairing, set withOPENADAPT_ALLOW_LOCAL_PAIRINGor inconfig.toml. Neither a link norset_configcan turn it on.allow_local_pairing.No shell permission for the window.
capabilities/default.jsondropsshell:allow-executeandshell:allow-spawnon the engine sidecar. Rust starts the sidecar insidecar.rs, and no frontend code uses the shell plugin.Version: Desktop 0.35.1.
Tests
Engine tests run the real pairing code against a fake Cloud and keychain:
same_name.after_conflict, through to Switch.config.toml.OPENADAPT_CONFIG_TOMLat a temporary file. Before this,test_login_pastewrote the developer's real~/.openadapt/config.toml.Phase-one unit tests (
claim_for_review):Static checks:
shell:permission.Frontend tests: both dialogs, the button labels, a different workspace named like the current one ("Acme" and "Acme"), a link while the app is open, the two-links error replacing the dialog, and Keep.
Run locally on macOS, headless only:
vitesttsccargo test(Rust unchanged since the first push)ruff checkcheck_release_intent.pyandcheck_release_consistency.pycheck_file_size_ratchet.py --base origin/mainpytest tests/The 2 pytest failures also fail on
main(Grok saw the same on Linux):test_control_overlay_contract_sync: the virtual environment hasopenadapt-types0.24.0, and the test wants 0.24.2.test_dry_run::test_complete_dry_evidence_projects_codes_without_values.The run left
~/.openadapt/config.tomlunchanged.The dialogs were not tried in a running app. The
Native installerjob, which runs the release Rust tests and the macOS launch smoke test, is skipped by this PR's path selection, so nothing in CI has shown the window still starts without the shell permission.