Skip to content

feat(shell): let enterprise IdP pages load in the WebView during sign-in, under a native bar - #176

Merged
os-zhuang merged 4 commits into
mainfrom
claude/issue-155-idp-excursion
Nov 3, 2026
Merged

os-zhuang merged 4 commits into
mainfrom
claude/issue-155-idp-excursion

Conversation

@objectstack-fleet

@objectstack-fleet objectstack-fleet Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #155

Clause-②: no
Metadata-protocol: none

维护者速读

  • 改了什么:服务器登录页跳到企业身份提供方(OIDC/SAML)时,提供方的 https 页面现在在应用内 WebView 打开,顶部原生条显示锁、确切域名、「正在外部页面登录 · 服务器名」和「取消」;回到服务器即结束,取消回到服务器的 /login。
  • 为什么改:私有部署的企业登录以前被送去应用内浏览器,登录态(会话 Cookie)回不到 WebView,用户在应用里登不进去。
  • 风险与回滚:这是安全边界,新增了可在顶层加载的外部来源,威胁模型见下文。只从登录页出发、只放行 https、期间桥接全关、30 次跳转或 10 分钟封顶,Google 这类拒绝内嵌 WebView 的提供方直接提示「暂不支持」。纯 JS 改动,回滚即还原本 PR。
  • 先看:① 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 个测试全部通过。
  • 需要你做的:在开发构建上用一个 https 的测试 OIDC 提供方做一次真机登录检查(步骤见 Verification,席位未做真机检查),核对通过后由你合并。

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: decideNavigation keeps its behaviour, and every pre-existing test of it passes untouched.

  • lib/shell/sign-in-excursion.ts (new). A pure state machine on top of decideNavigation, covering the start, the end, the caps and the refusal.
  • lib/shell/navigation-policy.ts. Adds isSignInSurface, SIGN_IN_ROUTE (/login) and AUTH_API_PATH (/api/v1/auth/), judged on the server's origin and under its base path.
  • lib/shell/bridge/handler.ts. Adds BridgeDeps.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.ts is unchanged.
    • The start dispatches the machine's reload, so routes and push tokens are held as at a cold start.
    • An excursion page's load end is not fed to the machine.
    • An ending other than a return dispatches switch with /login on the same host: a new WebView, so the provider's page and history are gone.
    • Answers to calls made before the excursion started or ended are dropped.
    • On Android, history is cleared once the WebView is back on the server.
  • app/console.tsx. Passes the current connection's label to the bar.
  • locales/*.json. Nine new keys under excursion, 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:

  • a top-frame navigation request that the policy let load;
  • the URL the native WebView reports with a load start or a load end.

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 for pushState, replaceState and popstate (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/login or /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.

routeChanged is 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 without WebMessageListener, a sub-frame's bridge message carries the main frame's URL, so it is no stronger there.

Caps: 30 navigations and 10 minutes.

  • 30 navigations, the first included. Browsers stop one request's redirect chain at 20 (the Fetch Standard, Chromium and WebKit). A sign-in is several such chains joined by the user's own steps (password, MFA method, consent, a federation hop). On iOS a link the user taps or a form they submit counts too, and Android reports no navigation type, so the cap counts every off-server top-frame navigation. 30 leaves room for ten such steps over one full chain. A script or meta-refresh loop, which no browser cuts, ends within seconds.
  • 10 minutes. This is the server's own limit. better-auth 1.7.12, the version packages/plugins/plugin-auth pins, stores the OAuth state with expiresAt: 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:

  • a request to accounts.google.com;
  • any excursion URL carrying the disallowed_useragent code, 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.

  • Start only from the current server's sign-in surface, judged on the native record and never on a page message. A Console page elsewhere, another origin's /_console/login, http on the same host, and another saved connection's sign-in page all keep the in-app browser.
    • Pinned by 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".
    • Pinned by ConsoleWebView.test.tsx: "sends the same page to the system browser from any other Console page", and the pre-existing "applies the navigation policy".
    • Ablation leg A turns 7 of these red.
  • What the sign-in surface can reach is the server's own answers. The Console's /login leaves the server only with a URL the server returned: the SSO and social url from /api/v1/auth/sign-in/*, or the OAuth-provider authorize replay. Its redirect param is same-origin only (isSafeRedirect in ui/apps/console/src/pages/auth/LoginPage.tsx). /api/v1/auth/* redirects are better-auth's, which checks callbackURL and errorCallbackURL against the server's trusted origins.
    • Residual: an open redirect on the server's sign-in surface would put the attacker's page under the bar. That is the server's boundary, and the shell relies on it.
    • Residual: when the server is itself an OAuth provider and a first-party client skips consent, the redirect to that relying party leaves from /login and 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.
  • The bar is always on screen while an excursion page is. It is native, outside the WebView, so the page cannot hide or cover it.
    • It shows a lock, the exact host of the page on screen (port included, drawn left to right in every language, truncated at its start so the registered domain stays visible), and which server the sign-in is for.
    • The text says "signing in on an external page"; it never vouches for the page.
    • Pinned by SignInExcursionBar.test.tsx (all three bar tests) and ConsoleWebView.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".
  • https only, and the lock is honest. react-native-webview cancels Android's onReceivedSslError and 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".
  • The attacker's page reaches nothing native.
    • The bridge answers no call (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.
    • installId is null off the server (existing bootstrap gate).
    • Pinned by bridge-handler.test.ts "during a sign-in excursion" (both tests) and ConsoleWebView.test.tsx "the bridge" (four tests). Ablation legs B1 and B3.
  • No route or token is sent into it while the excursion lasts: both are held through the load state machine until the server page is back.
    • Routes and push tokens are held until the server's Console posts ready. connectionRemoved is not dispatched.
    • Pinned by "returns: holds a route asked for meanwhile until the Console is ready again" and "asks no excursion page to unregister the push token".
  • An answer to a call the Console made before it left is dropped, not injected into the page that replaced it. A page that defines __objectstackNativeResolve before 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.

  • Navigation cap of 30: the excursion ends with an error and a new WebView at /login. Pinned by "ends after 30 navigations" (both suites).
  • Time cap of 10 minutes, at the timer or at the next navigation or report. Pinned by "ends after the time limit, at the timer or at the next navigation" and "ends with an error after the time limit".
  • 取消 is always on the native bar. It re-creates the WebView at /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".
  • After a return, Android's history is cleared, because Android's back button walks history without asking the policy. Pinned by "clears Android's history back on the server, …".
    • Residual: iOS keeps the excursion pages in history (WKWebView's back list cannot be cleared). Swiping back to one after a return is a navigation outside an excursion, so the policy opens it in the in-app browser, never in the WebView.
  • A connection switch, a load failure or a dead renderer ends the excursion. Pinned by "ends when the user switches to another connection" and "ends when a network failure replaces the page".

T3. A stale report ends an excursion early, or keeps a returned one alive. Native events arrive asynchronously.

  • A server load end counts as a return only after an excursion page has finished loading. Earlier reports are the page left behind. Pinned by "ignores a late report of the server page left behind".
  • A load start on the server is not a return. Pinned by the same test.
  • A request back to the server's origin is a return at once. Pinned by "ends on a request back to the server's origin".
  • A SAML response arrives on Android as a form POST the WebView never asks about. It counts as a return at its server load end. Pinned by "returns on a server page Android loads without asking (a SAML form POST)".

T4. Same-origin script starts an excursion to any host. A kind:'react' page, or XSS on the server, can move the record onto /login and then navigate off.

  • Accepted residual. That script already holds the session and can draw a fake sign-in form inside the Console itself, with no bar at all. The excursion adds a bar with the real host.

T5. Android cannot tell a sub-frame's navigation from the top frame's. react-native-webview 13.16 reports no isTopFrame on Android; the shell's docs already list this as a known limit.

  • A sub-frame on the sign-in page that navigates off the server can start an excursion. It still loads only inside its own frame, which iOS already allows for every sub-frame.
  • Moving the top frame from a cross-origin frame takes a user gesture in Chromium, and the bar then shows that page's host.
  • On iOS a sub-frame never starts one. Pinned by "never starts one from a sub-frame the platform reports as such".
  • The Android half is platform behaviour and is not pinned by a unit test. It is documented under Known limits.

Tests

All readings are at head 0c0706a on objectstack-ai/mobile unless stated otherwise. Base 678fbe9.

  • New: __tests__/lib/shell/sign-in-excursion.test.ts and __tests__/components/SignInExcursionBar.test.tsx.
  • Extended: navigation-policy.test.ts (isSignInSurface), bridge-handler.test.ts (during a sign-in excursion) and ConsoleWebView.test.tsx (sign-in excursion).

The card's acceptance list maps to these tests as follows:

  • Start only from the sign-in surface: T1.
  • End on return: T3, and "returns: holds a route …".
  • Cancel: T2.
  • http refused: T1.
  • Cap reached: T2.
  • The bridge never trusting an excursion origin: bridge-handler.test.ts "never trusts the excursion page's origin, in an excursion or after it".
Gates (exit codes captured before any pipe)
npx tsc --noEmit                          exit 0
npx eslint . --ext .ts,.tsx               exit 0
npx jest --ci --coverage                  exit 0   Test Suites: 41 passed, 41 total · Tests: 729 passed, 729 total
npx jest --ci --no-cache (cold) __tests__/components/SignInExcursionBar.test.tsx __tests__/components/ConsoleWebView.test.tsx
                                          exit 0   Test Suites: 2 passed, 2 total · Tests: 82 passed, 82 total
baseline at 678fbe9: npx jest --ci        exit 0   Test Suites: 39 passed, 39 total · Tests: 669 passed, 669 total
coverage: sign-in-excursion.ts 95.71% stmts · SignInExcursionBar.tsx 100% · navigation-policy.ts 100% · handler.ts 100% stmts · ConsoleWebView.tsx 99.23% stmts
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 full npx jest --ci and was then restored: the blob equals HEAD, git diff HEAD is empty and the tree is clean.

A  sign-in surface start check   lib/shell/sign-in-excursion.ts
   'if (state.location === null || !isSignInSurface(serverUrl, state.location)) {' -> 'if (state.location === null) {'
   anchor 1 -> 0 · blob 580bcbf6 -> 3427199c · restored 580bcbf6 == HEAD
   Tests: 7 failed, 721 passed, 728 total
     sign-in excursion: the start › does not start from any other page on the server
     sign-in excursion: the start › does not start from a sign-in page of another origin
     sign-in excursion: the start › takes the record only from navigation the WebView reports, …
     sign-in excursion: the end › does not start again from the provider's pages once it has returned
     sign-in excursion: the end › is judged against the current connection only
     ConsoleWebView — sign-in excursion › sends the same page to the system browser from any other Console page
     ConsoleWebView › applies the navigation policy   (pre-existing test)

B1 bridge closed during an excursion   lib/shell/bridge/handler.ts
   'if (deps.inExcursion?.()) return null;' -> comment
   anchor 1 -> 0 · blob 3ae5afe9 -> 32a6b898 · restored 3ae5afe9 == HEAD
   Tests: 2 failed, 726 passed, 728 total
     bridge handler › during a sign-in excursion › answers no call and takes no event, even one naming the server's origin
     ConsoleWebView — sign-in excursion › the bridge › answers no call while an excursion page is on screen, whatever origin it names

B2 late answer dropped across an excursion   components/shell/ConsoleWebView.tsx
   'if (excursionEpochRef.current !== epoch || excursionRef.current.active) return;' -> comment
   anchor 1 -> 0 · blob 9c5cbea9 -> 472c58f1 · restored 9c5cbea9 == HEAD
   Tests: 1 failed, 727 passed, 728 total
     ConsoleWebView — sign-in excursion › the bridge › drops the answer to a call the Console made before it left for the provider

B3 the excursion origin is not on the trust list   lib/shell/bridge/handler.ts
   'originOf(sourceUrl) === serverOrigin' -> 'originOf(sourceUrl) !== null' (any origin trusted)
   anchor 1 -> 0 · blob 3ae5afe9 -> aa518b44 · restored 3ae5afe9 == HEAD
   Tests: 12 failed, 716 passed, 728 total
     bridge handler › during a sign-in excursion › never trusts the excursion page's origin, in an excursion or after it
     + 11 pre-existing origin tests (bridge handler: another origin ×4, switched-away connection; ConsoleWebView: another origin ×2, askConsoleToRemove ×3, switching ×1)

Acceptance notes

  • PM mechanism assumption 1, measured at 678fbe9: confirmed, with one precision. An off-server top-frame http(s) page goes to the in-app browser (expo-web-browser openBrowserAsync, i.e. SFSafariViewController / Custom Tabs), unless its host is in EXPO_PUBLIC_TRUSTED_HOSTS. App schemes go to the OS, and sub-frames load.
  • Two pre-existing navigation-policy observations outside this PR's scope were reported to the maintainer through the seat, not here.
  • The bar's host is the host the WebView reports. Both engines report hosts in canonical ASCII (punycode) form as far as I know; this is not measured on a device, and it is part of the device check below.
  • Push taps route to the current connection, even when the notification came from another saved server #174 may touch app/console.tsx (one line here, the serverLabel prop). 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:

  1. Open the server's Console and go to sign-in. Use "Sign in with SSO" or the provider's button. The provider's page loads in the app, under a bar with a lock, the provider's exact host, and 「正在外部页面登录 · SERVER_LABEL」 with 取消.
  2. Complete sign-in. The bar goes away, the Console loads behind the cover and you are signed in. On Android, the back button does not return to the provider's pages.
  3. Start again and tap 取消: you are back on /login.
  4. Optional: a Google social button shows "This sign-in method isn't supported in the app yet." and opens nothing.
  5. Check that the host on the bar is the provider's real host, also for a long host, and in Arabic.

Generated by Claude Code

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:mobile#1 · os-justin · session_01QSeKYnW1Xf6HDSWz1eGAqv

Seat verdict: ACCEPT — the maintainer merges (security boundary: this admits new top-frame origins). Head-sha: 0c0706a9af7f2b493101cd33c93449b6b9e91f8b

维护者速读

  • 改了什么: 企业 IdP(OIDC/SAML)登录的「外出登录」模式。只有从服务器的登录页(Console /login 或 /api/v1/auth/*)出发,顶层页面才允许跳到外部的 https 登录页。

    • 跳出期间,顶部原生栏显示锁、确切的外部域名、「正在外部页面登录 · 服务器名」和「取消」。
    • 结束条件:回到服务器、点取消、外部跳转超过 30 次、超过 10 分钟(对齐 better-auth 的 OAuth 状态有效期)、遇到 http 页面、或遇到拒绝内嵌浏览器的提供方(谷歌)。最后两种会提示「暂不支持」。
    • 跳出期间桥接完全关闭,外部来源永远不进桥接信任名单。路由和推送令牌暂存,回到服务器后再送。
  • 为什么改: 之前外部登录页一律在系统浏览器打开,会话回不到 App,企业 IdP 用户登录不了。

  • 风险与回滚: 放行了新的顶层来源,属于安全边界。PR 正文的「Threat model」一节逐条列了钓鱼重定向、跳出不回等 5 类威胁,每类都写了缓解措施和钉住它的测试,另有两条已知残留风险请你审:

    • 从 /login 跳转到已跳过授权确认的第一方 OAuth 客户端时,会在栏下打开;
    • iOS 返回后左滑会打开应用内浏览器。

    回滚就是 revert 本 PR。

  • 先看: PR 正文的「Threat model」一节 → lib/shell/sign-in-excursion.ts → lib/shell/bridge/handler.ts(inExcursion)。

  • 两分钟验证: npx jest --ci __tests__/lib/shell/sign-in-excursion.test.ts __tests__/components/SignInExcursionBar.test.tsx __tests__/lib/shell/bridge-handler.test.ts

  • 需要你做的:

    1. 审「Threat model」和两条残留风险。
    2. 在开发包上对一个测试 OIDC 提供方走一遍登录。本 PR 未上真机。
    3. 审批并合并(合并时点「Merge when ready」进队列)。

席位意见: 起点判断用的是壳自己记录的顶层地址,不信页面上报的 routeChanged。桥接在跳出期间关闭,有测试钉住。四腿消融全部转红:去掉登录页起点检查,7 个用例红;去掉桥接关闭,2 个红;去掉在途应答丢弃,1 个红;放宽信任名单,12 个红。另有两处本 PR 之外的既有观察,席位已在会话里直接报告给你,没写进 GitHub。建议合并。

席位核对

  1. Shape: draft → main. First line Fixes #155. Clause-②: no and Metadata-protocol: none are present, and the PR carries a changeset. The ## Threat model section is present, with five threats, each mapped to its mitigation and pinning test.
  2. Premise, measured: on main, every off-server top-frame page went to the system browser, and no excursion mode existed. decideNavigation and console-load.ts are unchanged; the excursion rides the existing reload event.
  3. Gates:
    • Check-runs on head 0c0706a: Code Quality success, Lint & Type Check success.
    • mergeable_state: clean.
    • Local jest --ci --coverage: 41/41 suites, 729 tests.
  4. Accepted deviation: the first WIP commit's trailer was amended with --force-with-lease, before any PR existed and under the os-dev conditions for its own branch.
  5. Out of scope: two pre-existing navigation-policy observations were reported to the maintainer through the seat, outside GitHub. Skills-docs: n/a.
  6. Landing: the path surface is NOT governed (+1672 / −72). The card puts this on the human floor, so the maintainer merges it. The seat does not enable auto-merge.

@objectstack-fleet objectstack-fleet Bot added the needs-user-decision Blocked on a maintainer decision — do not dispatch; decision cards only, never on a PR label Nov 3, 2026
@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review November 3, 2026 00:09
@os-zhuang
os-zhuang added this pull request to the merge queue Nov 3, 2026
Merged via the queue into main with commit f62fe15 Nov 3, 2026
2 checks passed
@objectstack-fleet objectstack-fleet Bot removed the needs-user-decision Blocked on a maintainer decision — do not dispatch; decision cards only, never on a PR label Nov 3, 2026
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.

External sign-in bar: let enterprise IdP pages load in the WebView during sign-in, behind a native bar showing the IdP's domain

2 participants