Repository navigation
fix(shell): bridge answers follow the shell's origin rule - #178
Merged
Merged
Conversation
A call's answer is spliced only into a page on the configured server's origin, the same rule as the shell's other page scripts that carry data: the resolve script checks window.location.origin against the server's origin (default ports dropped) before it calls the resolve global, and any other page gets nothing. An unusable server URL builds no script. Claude-Session: https://claude.ai/code/session_01QSeKYnW1Xf6HDSWz1eGAqv Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QSeKYnW1Xf6HDSWz1eGAqv Co-authored-by: Claude <noreply@anthropic.com>
Contributor
Author
|
repo:mobile#1 · os-justin · session_01QSeKYnW1Xf6HDSWz1eGAqv Seat verdict: ACCEPT. Landed by the seat under the maintainer ruling on #160. Head-sha: 维护者速读
席位核对
|
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.
Clause-②: no
Metadata-protocol: none
维护者速读
__objectstackNativeResolve)时,只写给已配置服务器同源的页面,与壳其余携带数据的页面脚本(navigate、pushTokenChanged、connectionRemoved)同一条来源规则。lib/shell/bridge/scripts.ts的buildResolveScript;components/shell/ConsoleWebView.tsx中onMessage的调用点;__tests__/lib/shell/bridge-scripts.test.ts的resolve script组。npx jest --ci __tests__/lib/shell/bridge-scripts.test.ts,预期 54 passed,其中calls no resolve global on a page on another origin五例全绿。What changes
buildResolveScript(result, serverUrl)(lib/shell/bridge/scripts.ts) follows the origin rule ofbuildNavigateScript,buildPushTokenChangedScriptandbuildConnectionRemovedScript: the script returns at once unlesswindow.location.originequals the configured server's origin (default ports dropped, viaoriginOf). There it callswindow.__objectstackNativeResolvewith the result.window.location.originand nothing else: no global of the page is called.null), as for the three sibling scripts.ConsoleWebViewpassesserverUrl, the same value its bridge handler judged the call against, and injects nothing for anullscript. ThedocumentRefand excursion drops are unchanged.typeoffunction check instead of a truthiness check.docs/HYBRID-SHELL.md(Wire format, Security) and theBRIDGE_RESOLVE_GLOBALdoc comment state the rule..changeset/bridge-resolve-origin.md(patch).Tests
__tests__/lib/shell/bridge-scripts.test.ts, newresolve scriptgroup:settles the call on a page of the configured server's origin: server URL with a base path, the page's resolve global called once with the result.compares the page origin with the default port dropped: server URLhttps://acme.example.com:443/os, page originhttps://acme.example.com.calls no resolve global on a page on another origin, five cases: another host, another scheme, another port, a subdomain, an opaque origin.reads nothing but the origin of a page on another origin: the script's reads of the page, recorded through a Proxy, are exactlylocationandlocation.origin.does nothing on a page of the server's origin that has no resolve global.builds no script for an unusable server URL.splices the result as escaped JSON.Existing
bootstrap scripttests pass the server URL; the page helper now refuses anullscript, so a missing script cannot pass silently.settles no call of a later document with an answer meant for an earlier oneuses two documents on the server's origin; other origins are the new group's.__tests__/components/ConsoleWebView.test.tsx, each running the injected answer in a fake page:delivers an answer only to a page on the configured server's origin(new): settled on the server's origin, nothing on another.still settles the call after a load start in the same WebView (an in-app navigation): the answer now also settles the call on the server's origin.follows the new connection's origin: the host left gets no answer, the new one does: the answer settles on the new connection's origin only.Ablation, on committed code, mutated through
ablation-replace.mjs(anchor hit once, blob changed on disk) and restored to the HEAD blob withgit diff HEADempty:another origincases,reads nothing but the origin of a page on another origin,delivers an answer only to a page on the configured server's originandfollows the new connection's origin: the host left gets no answer, the new one does.Acceptance notes
npx prettier --checkwarns on lines in the touched files that read the same onmain(gatedInstallIdinscripts.ts; one listener inbridge-scripts.test.ts; several inConsoleWebView.test.tsx). Left untouched; the added lines are prettier-clean.--maxWorkers=2on a shared container; CI runs the plain command.Verification
All at head
5028e6f(basee60866b), each through the shared verify lock, exit code captured before any pipe.npx tsc --noEmit: exit 0
npx eslint . --ext .ts,.tsx: exit 0
npx jest --ci --coverage --maxWorkers=2: exit 0
Browser check, Chromium 153, two loopback origins
Generated by Claude Code