Repository navigation
feat(shell): let enterprise IdP pages load in the WebView during sign-in, under a native bar - #176
Conversation
Claude-Session: https://claude.ai/code/session_01QSeKYnW1Xf6HDSWz1eGAqv Co-authored-by: Claude <noreply@anthropic.com>
…osed bridge 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>
Claude-Session: https://claude.ai/code/session_01QSeKYnW1Xf6HDSWz1eGAqv Co-authored-by: Claude <noreply@anthropic.com>
|
repo:mobile#1 · os-justin · session_01QSeKYnW1Xf6HDSWz1eGAqv Seat verdict: ACCEPT — the maintainer merges (security boundary: this admits new top-frame origins). Head-sha: 维护者速读
席位意见: 起点判断用的是壳自己记录的顶层地址,不信页面上报的 席位核对
|
Fixes #155
Clause-②: no
Metadata-protocol: none
维护者速读
/login。lib/shell/sign-in-excursion.ts的stepExcursion(起止规则与上限);②components/shell/ConsoleWebView.tsx的applyExcursion与onLoadEnd(和加载状态机的衔接);③lib/shell/bridge/handler.ts的inExcursion一行。npx jest --ci __tests__/lib/shell/sign-in-excursion.test.ts __tests__/components/ConsoleWebView.test.tsx,预期 2 个套件、98 个测试全部通过。What changes
A private server's Console can now sign in through an enterprise identity provider whose host the shell does not know in advance. When the server's sign-in surface sends the top frame off the server, the provider's https pages load in the WebView under a native bar. The session cookie the server sets on the way back lands in the WebView's own cookie store, as in a browser. Outside an excursion the navigation policy is unchanged:
decideNavigationkeeps its behaviour, and every pre-existing test of it passes untouched.lib/shell/sign-in-excursion.ts(new). A pure state machine on top ofdecideNavigation, covering the start, the end, the caps and the refusal.lib/shell/navigation-policy.ts. AddsisSignInSurface,SIGN_IN_ROUTE(/login) andAUTH_API_PATH(/api/v1/auth/), judged on the server's origin and under its base path.lib/shell/bridge/handler.ts. AddsBridgeDeps.inExcursion: while an excursion is on screen, no call is answered and no event is accepted, whatever origin the message names. The trust list is unchanged: the current server's origin only.components/shell/SignInExcursionBar.tsx(new). The bar (lock, exact host, 「正在外部页面登录 · SERVER_LABEL」, 取消) and the notice shown when an excursion ends without returning.components/shell/ConsoleWebView.tsx. Feeds the machine the WebView's requests, load starts and load ends. The wiring goes through the existing load state machine;console-load.tsis unchanged.reload, so routes and push tokens are held as at a cold start.switchwith/loginon the same host: a new WebView, so the provider's page and history are gone.app/console.tsx. Passes the current connection's label to the bar.locales/*.json. Nine new keys underexcursion, in all ten bundles.docs/HYBRID-SHELL.md. A new "Sign-in excursion" section, plus the policy table, the bridge security notes, load states, testing and known limits.Landing point: every changed file is inside the claim's file surface.
Design decisions
The "started from the sign-in surface" signal. The start is judged on the shell's own record of the top-frame URL. Only two things write that record:
On Android a load start also fires for every SPA history change (react-native-webview 13.16 emits it from
doUpdateVisitedHistory). On iOS a load end also fires forpushState,replaceStateandpopstate(its history shim). So the record follows SPA route changes on both platforms.Why a page that is not the sign-in surface cannot spoof it: a page can change the top-frame URL only within its own origin, because the history API is same-origin. Only a document on the server's origin can put the record on
/_console/loginor/api/v1/auth/*, and such a document is the server's own content, which already holds the session.The request-level write is what makes
/api/v1/auth/*work: on Android a server redirect out of/api/v1/auth/sign-in/...never commits the API URL, so only the admitted request records it.routeChangedis deliberately not used. It cannot report/api/v1/auth/*(that is not a Console route). A Console older than shell mode does not post it. And on an Android WebView withoutWebMessageListener, a sub-frame's bridge message carries the main frame's URL, so it is no stronger there.Caps: 30 navigations and 10 minutes.
packages/plugins/plugin-authpins, stores the OAuth state withexpiresAt: Date.now() + 600 * 1e3(dist/oauth2/state.mjs, line 31). A return after that is refused by the server anyway, so the cap never cuts a sign-in the server would still accept.Refusal detection (card ask 4). The system-auth-session path of #148 is not built here. Google answers an embedded WebView with "Error 403: disallowed_useragent". The shell detects that before the page loads, in two ways:
accounts.google.com;disallowed_useragentcode, which an IdP or proxy may pass on in a redirect.When it detects one, it blocks the navigation, goes back to
/login, and says "This sign-in method isn't supported in the app yet." A provider that refuses by its own user-agent check without that code cannot be told apart. Its error page shows under the bar, and 取消 goes back.http. Plain http never starts an excursion: that request keeps the policy's answer, the in-app browser. An http page during an excursion ends it with an error, whether the WebView asked first or only reported the page.
No session transfer. Nothing moves a session between hosts or between the WebView and native code. The shell reads no cookie and calls no API. The server sets its own cookie on the return, in the same WebView store as before.
Threat model
Scope: what the shell admits into its WebView's top frame, what that page can reach, and how it ends. Each row names the mitigation and the test that pins it. Ablations are under Tests.
T1. Phishing through a crafted login redirect. A link lands the WebView on the server's sign-in surface, which then navigates to an attacker's page dressed as an IdP. The page collects the password under a bar that reads like the server's own sign-in.
/_console/login, http on the same host, and another saved connection's sign-in page all keep the in-app browser.sign-in-excursion.test.ts: "does not start from any other page on the server", "does not start from a sign-in page of another origin", "does not start before the WebView has reported where it is", "takes the record only from navigation the WebView reports, …", "is judged against the current connection only".ConsoleWebView.test.tsx: "sends the same page to the system browser from any other Console page", and the pre-existing "applies the navigation policy"./loginleaves the server only with a URL the server returned: the SSO and socialurlfrom/api/v1/auth/sign-in/*, or the OAuth-provider authorize replay. Itsredirectparam is same-origin only (isSafeRedirectinui/apps/console/src/pages/auth/LoginPage.tsx)./api/v1/auth/*redirects are better-auth's, which checkscallbackURLanderrorCallbackURLagainst the server's trusted origins./loginand loads under the bar. Clients that need consent leave from/oauth/consent, which is not on the sign-in surface, so they keep the in-app browser.SignInExcursionBar.test.tsx(all three bar tests) andConsoleWebView.test.tsx: "loads the provider from the sign-in page, uncovered, under a bar with its host and the server", "follows the host of the page on screen".onReceivedSslErrorand leaves iOS to the system trust check. The shell sets neither custom certificates nor basic-auth credentials. Pinned by "refuses plain http, …" and "ends with an error when a page is plain http" (both suites) and "keeps the system browser for plain http, even from the sign-in page".getPushToken,scan,navigate,resetServer,showConnectionSwitcher) and accepts no event (ready,routeChanged). This holds even for a message naming the server's origin, because on iOS a server-origin sub-frame inside the provider's page reports its own URL.installIdisnulloff the server (existing bootstrap gate).bridge-handler.test.ts"during a sign-in excursion" (both tests) andConsoleWebView.test.tsx"the bridge" (four tests). Ablation legs B1 and B3.ready.connectionRemovedis not dispatched.__objectstackNativeResolvebefore the Android bootstrap lands could otherwise read it. Pinned by "drops the answer to a call the Console made before it left for the provider". Ablation leg B2.T2. An excursion that never returns. A provider page, or an attacker's, keeps the user in the WebView, loops redirects, or traps navigation.
/login. Pinned by "ends after 30 navigations" (both suites)./login, so the provider's page and its history are gone; a page cannot block it. Pinned by "取消 goes back to the server's sign-in page in a new WebView".T3. A stale report ends an excursion early, or keeps a returned one alive. Native events arrive asynchronously.
T4. Same-origin script starts an excursion to any host. A
kind:'react'page, or XSS on the server, can move the record onto/loginand then navigate off.T5. Android cannot tell a sub-frame's navigation from the top frame's. react-native-webview 13.16 reports no
isTopFrameon Android; the shell's docs already list this as a known limit.Tests
All readings are at head
0c0706aon objectstack-ai/mobile unless stated otherwise. Base678fbe9.__tests__/lib/shell/sign-in-excursion.test.tsand__tests__/components/SignInExcursionBar.test.tsx.navigation-policy.test.ts(isSignInSurface),bridge-handler.test.ts(during a sign-in excursion) andConsoleWebView.test.tsx(sign-in excursion).The card's acceptance list maps to these tests as follows:
bridge-handler.test.ts"never trusts the excursion page's origin, in an excursion or after it".Gates (exit codes captured before any pipe)
Ablations (run at f015c25: same code, 728 tests; the later commits add one test and docs)
Each leg mutated one line through
scripts/ablation-replace.mjs(objectstack; anchor hit, on-disk counts) under an EXIT/INT/TERM restore. It ran the fullnpx jest --ciand was then restored: the blob equals HEAD,git diff HEADis empty and the tree is clean.Acceptance notes
678fbe9: confirmed, with one precision. An off-server top-frame http(s) page goes to the in-app browser (expo-web-browseropenBrowserAsync, i.e. SFSafariViewController / Custom Tabs), unless its host is inEXPO_PUBLIC_TRUSTED_HOSTS. App schemes go to the OS, and sub-frames load.app/console.tsx(one line here, theserverLabelprop). Ordinary concurrency: the second to land reconciles.Verification
Device check: NOT RUN by the seat. NOT MEASURED: on-device, reason: no device in this container. For the maintainer, on a development build, against an https test OIDC provider (for example a Keycloak or an Okta developer tenant) configured as the server's SSO:
/login.Generated by Claude Code