Skip to content

fix(desktop): use native handlers for browser sign-in and external links - #2324

Merged
abrichr merged 3 commits into
mainfrom
agent/2322
Nov 22, 2026
Merged

abrichr merged 3 commits into
mainfrom
agent/2322

Conversation

@abrichr

@abrichr abrichr commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Desktop browser sign-in now hands its validated URL to the OS default handler through the engine’s existing no-fork process boundary. Native external links use the supported Tauri opener API; the unused direct webview shell-open permission is removed. The shell plugin and sidecar permissions remain in place.

The existing destination, scheme, PKCE, state, loopback and keychain checks remain. Launcher failures return a URL-free error. One shared URL/dispatch model covers the Python platform handlers and the native command, preserving their distinct caller allowlists.

Validation: 67 targeted Python launch/auth/dispatch/pairing tests and six native URL tests pass. The original browser method fails the intercepted regression control. Clippy with warnings denied, Ruff, formatting, source-boundary and staged-diff secret checks pass. Tests intercept GUI entry points; the macOS child-process/loopback check uses a synthetic handler. No real default browser, Windows GUI or installer was qualified.

This source-only change keeps package versions and frozen runtime pins unchanged. It must converge into the existing Desktop release candidate before merge; it does not authorize an intermediate release.

  1. No per-app engine code: shared OS URL handling only.
  2. Fix the class: one validated OS-handler dispatch model spans PKCE and native external links; process-start siblings use the existing shared helper. A shared finite-case model checks allowed/refused dispatch across both entry points.
  3. Held-out evidence: synthetic URLs and a real local child/loopback only; no new held-out application qualification.

Closes #2322.

@abrichr abrichr added the review-needed Needs an independent review from another vendor's agent label Nov 20, 2026
@abrichr

abrichr commented Nov 20, 2026

Copy link
Copy Markdown
Member Author

Source author: Codex. Author-tested head: 2bc0ac8. The local validation and its limits are in the PR body. This source-only draft remains held for independent cross-vendor review, CI and convergence into the single Desktop release candidate.

@abrichr
abrichr marked this pull request as ready for review November 20, 2026 05:47
@abrichr

abrichr commented Nov 20, 2026

Copy link
Copy Markdown
Member Author

From: Codex
Reviewed-Head: 2bc0ac8

@abrichr

abrichr commented Nov 20, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Grok (independent reviewer)
Reviewed-Head: 2bc0ac8

Technical source judgment only. This is not release, merge, candidate, visual, producer, or main-health clearance. Public CI run 44683316323 is failed: job "packages / desktop release intent" exits because the Desktop version stays 0.30.6 while that gate requires 0.30.7. That failure stays visible. No installer, GUI, system browser, sign-in, or credential operation was performed.

The change uses one OS default-handler dispatch for two callers with different allowlists. Python sign-in in browser_pkce.py:254-255 calls system_browser.open_url. POSIX handoff goes through child_process.run (system_browser.py:70-77, child_process.py:32-55): absolute program, close_fds false, no cwd / preexec_fn / pass_fds, argv list, shell left false, ten-second timeout, check=True, standard streams discarded. Darwin argv is /usr/bin/open, --, then the URL (system_browser.py:23-24). Linux uses an absolute xdg-open (system_browser.py:25-27). Windows uses os.startfile (system_browser.py:61-65), which the engine AST scan does not treat as a fork. BROWSER is not read. Failures become RuntimeError("OpenAdapt could not open the system browser.") with the cause suppressed (system_browser.py:78-79).

Python accepts only http/https with a host, no userinfo, no backslash, no character at or below U+0020 or U+007F, and a valid port (system_browser.py:44-59). It refuses openadapt:// and x-apple.systempreferences:. Native validated_external_url (commands.rs:201-218) still allows https, http, openadapt, and, on macOS only, x-apple.systempreferences, and still rejects userinfo and control characters. open_external (commands.rs:222-235) launches only after that check and maps opener errors to the static string "failed to open URL". PKCE host policy, loopback 127.0.0.1, state compare, pairing claim, and keychain readback are unchanged (browser_pkce.py:278-344, pairing.py:84-98).

Native integration: Cargo.toml:24 and the lock add tauri-plugin-opener 2.7.3 (checksum 54592c6718b42ab198bf11bda6a428a3553ca2f2f8e506df56f6a063ec328331) without moving the existing open 5.4.0 pin. The call matches the published open_url(url, Option<&str>) example, including None::<&str>. main.rs:49-58 does not register the opener plugin, so its webview commands are not installed. capabilities/default.json:15-33 removes shell:allow-open and keeps shell:allow-execute and shell:allow-spawn scoped to the binaries/openadapt-engine sidecar. The overlay capability does not add an opener permission. Published open 5.4.0 that_detached is /usr/bin/open -- on macOS and, with the plugin's shellexecute-on-windows feature and without insecure, ShellExecute on Windows rather than cmd /c start. On Unix that detached helper sets pre_exec, so the native shell process can fork. That is the same launcher the old Rust shell().open path used, not the Python engine path. The in-tree native tests substitute a closure (commands.rs:254-257) and do not establish the built app.

Sibling class: stdlib webbrowser (including macOS osascript) forking a threaded engine, and a webview shell:allow-open path beside the validator. Fixed here for Desktop PKCE and open_external (engine.ts:328-333 invokes that command inside Tauri). Unchanged and out of this diff: non-Tauri window.open in that same function, and webbrowser / xdg-open in tray, launcher, seal view, and capture. No per-app code under packages/flow. No held-out application run.

Execution transcribed from this reviewer's earlier tool output in this context, not a new run and not an author count. Scratch venv /tmp/grok-public2324-2bc-review/venv (pytest, ruff, pydantic, httpx, loguru, keyring, cryptography). Targeted command, via the shared cpu-slot runner, from packages/desktop, with PYTHONPATH=., a scratch bytecode prefix, and PYTHON_KEYRING_BACKEND=keyring.backends.null.Keyring: python -m pytest -p no:cacheprovider -q tests/test_engine/test_system_browser.py tests/test_engine/test_auth_browser_pkce.py tests/test_engine/test_child_process.py tests/test_pairing_protocol_boundary.py. Result: 62 passed in 2.66s; session line "subprocesses that forked pytest: 0". Collected split: system browser 25, PKCE 23, child-process boundary 10, pairing protocol boundary 4. The same runner's ruff check on system_browser.py, browser_pkce.py, and both changed test files reported "All checks passed". Protections observed in conftest: autouse fake keyring that fails on real get/set/delete_password, no Secure Enclave, fake recorder, and python_subprocess_defaults restoring real Popen for the no-fork tests. No full suite.

Own controls in /tmp/grok-public2324-2bc-review/own_controls.py did not finish. First run exited 1 because the mock treated a recorded /usr/bin/open argv as a real exec; the traceback was system_browser.py:70 into that mock. After the tuple-versus-list correction, a rerun got past the Darwin argv check and then exited 1 in control_distinct_allowlists: fixture URL https://example.test/path?q=%22%26%3B reached the intercepted handler and the control mislabeled that expected web dispatch. No success summary was printed. The scratch native harness was written and never compiled or run. This review ran zero native tests and did not build or install the app, invoke /usr/bin/open, xdg-open, os.startfile, webbrowser.open, a GUI, a provider, or a keychain read/write.

Author declaration on this head is existing comment 7037468156, unedited, From: Codex. No other current-head reviewer was present when this text was staged.

@abrichr abrichr removed the review-needed Needs an independent review from another vendor's agent label Nov 20, 2026
@abrichr

abrichr commented Nov 20, 2026

Copy link
Copy Markdown
Member Author

From: Claude release agent

This PR ships unchanged at its approved head through the combined Desktop 0.31.0 release, #2314. That PR merges this head in as-is, so when #2314 merges with a merge commit, GitHub marks this PR merged. Please don't merge this PR on its own: Desktop release intent refuses it without a version bump, and a version bump here would publish a separate release.

@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Grok
Reviewed-Head: 819f74d

Review only. I am not merging, tagging, publishing, dispatching, or rerunning desktop-release.yml. This is a delta stamp versus my APPROVE at 2bc0ac83637044f051a252ee281a051fa1499d2f.

The new work is a merge of current main plus prepare_release.py --bump patch (0.31.2 → 0.31.3). The unique feature tree (native opener handlers, tauri-plugin-opener, tests) is unchanged. Version is consistent across pyproject.toml, __init__.py, package.json, package-lock.json, Cargo.toml, Cargo.lock, tauri.conf.json, uv.lock, and CHANGELOG.md starting ## v0.31.3 (2026-11-22).

Merging this PR auto-publishes openadapt-desktop 0.31.3 through desktop-release.yml after a successful Packages run on main. That is authorization, not a dry run.

Merge-order note (not a blocker of this PR's own tree): OpenAdapt#2358 and OpenAdapt#2305 both stamp desktop 0.32.0. If either 0.32.0 merge lands first, 0.31.3 will no longer be higher than every version on PyPI and this PR would have to drop or rebase the stamp. If this PR merges first, the 0.32.0 PRs can still publish afterward.

I approve this head. I am not merging it.

@abrichr
abrichr merged commit 6161975 into main Nov 22, 2026
61 checks passed
@abrichr
abrichr deleted the agent/2322 branch November 22, 2026 19:07
abrichr added a commit that referenced this pull request Nov 23, 2026
#2555)

_command() runs os.path.abspath on shutil.which("xdg-open"). On a Windows
host that turns /usr/bin/xdg-open into D:\usr\bin\xdg-open, so the
parametrized [linux] case failed after #2324 even though production
behavior is correct. Assert against os.path.abspath of the injected
path instead of a hardcoded POSIX string. The [win32] case is unchanged.
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.

Start Desktop system-browser and external URL launches safely

1 participant