fix(security): restrict desktop bridge to same-origin browsers - #740
Open
imMamdouhaboammar wants to merge 1 commit into
Open
fix(security): restrict desktop bridge to same-origin browsers#740imMamdouhaboammar wants to merge 1 commit into
imMamdouhaboammar wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The desktop bridge currently emits wildcard CORS responses and accepts browser requests without a trustworthy Origin boundary. Because browsers can reach loopback HTTP services, an unrelated page can attempt to invoke sensitive bridge endpoints such as agent prompt submission and configuration writes.
This patch restricts browser access while preserving the bundled desktop UI and native/local callers.
Root cause
cors_middleware()accepted everyOriginand returnedAccess-Control-Allow-Origin: *for preflight and normal responses.json_ok()independently added the same wildcard header.A simple
Origin == Hostcomparison is also insufficient on a loopback service because both headers can contain the same attacker-controlled hostname in a DNS-rebinding scenario.Changes
127.0.0.1,localhost, or::1request.hostOrigin: null*, withVary: Originjson_ok()Originfor native/local callersPATCHin the preflight method list to match the existing PATCH routeGA_ROOT, preventing import-time upload cleanup from touching developer dataThe Tauri shell already navigates the main webview to
http://127.0.0.1:14168/, so the bundled UI remains allowed.Regression coverage
The test suite covers:
Origin: nullrejectionVerification
python -m py_compile frontends/desktop_bridge.py tests/test_desktop_bridge_origin.pypassed during the implementation gategit diff --checkpassed before each production patch commit31160123977passed the test job while every self-patching step was skipped, proving the committed code itself is greenNo new runtime dependency is added.
aiohttpis already a core dependency.Residual boundary
This is a browser-origin fix, not authentication for trusted local processes. Requests without
Originremain allowed for native/local clients by design. A per-launch token would be a separate defense-in-depth change.The connected GitHub integration has write access to this fork, but upstream write operations return
403 Resource not accessible by integration, so I cannot open the cross-fork PR tolsdefine/GenericAgentdirectly from this session.