Skip to content

Commit 58388b3

Browse files
committed
Take the https callback page's "Open the OpenBot app" intent as the callback, read only the ticket, and record enter's request headers on both WebView versions
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012xYtaUjbkB1hwLtK4TEzhq
1 parent 06624d0 commit 58388b3

5 files changed

Lines changed: 89 additions & 6 deletions

File tree

‎android-shell/PRODUCTION-PARITY.md‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,25 @@ emulator) the WebView very often gets Cloudflare's challenge instead of OpenBot:
6767
fix is on the Cloudflare side (a rule that does not challenge the app, for example by its
6868
`OpenBotShell-Android` mark combined with a signed header), not in the app.
6969

70+
## The request headers of `enter`
71+
72+
`enter` is a native `loadUrl(url, headers)` (`WebController.loadEnter`), with the header
73+
`OpenBot-Shell: android`. `ProbeTest#testEnterRequestHeaders` runs that exact code path against the
74+
probe's header echo (`/api/echo-headers` on `127.0.0.1`, a trustworthy origin, so Chromium sends the
75+
`Sec-Fetch-*` headers as it would to https), (a) from the signed-out first screen with nothing
76+
loaded and (b) while a page is showing, as in a renewal:
77+
78+
| WebView | Case | Sec-Fetch-Site | Sec-Fetch-Mode | Sec-Fetch-Dest | Sec-Fetch-User | OpenBot-Shell |
79+
| --- | --- | --- | --- | --- | --- | --- |
80+
| 124.0.6367.219 (API 35, run 46144762894) | first screen | none | navigate | document | ?1 | android |
81+
| 124.0.6367.219 (API 35, run 46144762894) | page showing | none | navigate | document | ?1 | android |
82+
| 133.0.6943.137 (API 36, run 46144794643) | first screen | none | navigate | document | ?1 | android |
83+
| 133.0.6943.137 (API 36, run 46144794643) | page showing | none | navigate | document | ?1 | android |
84+
85+
A native `loadUrl` is a browser-initiated navigation: `Sec-Fetch-Site: none` even with an OpenBot page
86+
on screen. A page cannot produce that combination with a custom header (a page's navigation is
87+
`same-origin` or `cross-site`, and a page's `fetch` with `OpenBot-Shell` is `Sec-Fetch-Mode: cors`).
88+
7089
## Real-device checklist
7190

7291
1. Install from an internal-testing track; sign in with Google in the Custom Tab (default browser),

‎android-shell/README.md‎

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,25 @@ What is native:
2727
on only while a sign-in this app started is waiting (`PendingSignIn`, in memory; otherwise it is
2828
dropped). `"callback":"https"`: the same, finishing on `https://my.open.bot/api/auth/shell/callback`,
2929
claimed as an App Link (`android:autoVerify="true"`); the app uses it only when Android reports the
30-
domain verified (API 31+, `DomainVerificationManager`), else the web sign-in. The ticket and the
30+
domain verified (API 31+, `DomainVerificationManager`), else the web sign-in. The server's https
31+
callback is `<app>/api/auth/shell/callback?ticket=<T>&platform=android`; only `ticket` is read. When
32+
the browser shows that address as a page, its "Open the OpenBot app" link is an `intent://` address
33+
for this package (`scheme=https`, `browser_fallback_url`): the same https filter on the trampoline
34+
takes it, with the same pending sign-in and ticket checks (`testOpenTheAppIntentIsTheCallback`). The ticket and the
3135
verifier then go to `/api/auth/shell/enter` in the WebView, which sets the session cookie there;
3236
that one request carries the header `OpenBot-Shell: android`, which the server requires for it
3337
(login CSRF: a page cannot add the header, so it cannot plant a session in someone else's app). The
3438
enter address is never kept as the page to reload or logged. The trampoline passes a callback on
3539
only with a well-formed ticket for the pending sign-in's mode, so another app firing
36-
`openbotshell://` neither ends the sign-in nor closes the Custom Tab.
40+
`openbotshell://` neither ends the sign-in nor closes the Custom Tab. From the first screen,
41+
`enter` loads only after the web view's session cookies, the origin's other cookies (not
42+
Cloudflare's), all site storage and the cache have been cleared (the server refuses `enter` over
43+
another person's live session, and the web app's /sign would carry on as that person). Once the
44+
failure page (`/sign?native-sign-in=failed`) shows for an attempt, it failed, whatever cookie or
45+
page follows. The verifier stays until an `enter` succeeds or the person cancels: a well-formed
46+
ticket the server refuses (another app's) goes back to waiting, at most 3 callbacks
47+
(`SignInAttempt`, `SignInAttemptTest`). A renewal keeps the session, and the outgoing page's
48+
`signed-out` and `/sign` are ignored while its `enter` loads.
3749
Every step has a timeout and an error line on the native screen; closing the Custom Tab returns
3850
quietly. The hand-off path is `/api/auth/shell/handoff?challenge=<C>&platform=android&callback=<scheme|https>`
3951
(`ShellUrls.kt`, to the letter of the server's `docs/shell-sign-in.md`). The confirmation page's
@@ -55,7 +67,8 @@ What is native:
5567
once, and a landing on `/sign` (a `route` message, or the URL of a web app without the bridge)
5668
after a 2.5 s confirmation (still on `/sign`, or no session cookie: the web app's /sign sends a
5769
signed-in person on to "/"). Then the two session cookies, the origin's other cookies (except
58-
Cloudflare's `cf_*` clearance), its storage, the cache and the history go, and the native sign-in
70+
Cloudflare's `cf_*` clearance), all site storage (`WebStorage.deleteAllData`: this WebView holds only
71+
OpenBot and identity providers), the cache and the history go, and the native sign-in
5972
shows. After signing in the history is cleared, and Back never goes to another site's page, `/sign`
6073
or `/api/`.
6174
- **The loading skeleton.** `LoadingSkeletonView` (`loading_skeleton`, "Loading") is the web area's
@@ -102,9 +115,11 @@ What is native:
102115
(parsed with `Intent.parseUri`, component and selector removed, browsable only, from a tap); `mailto:`
103116
and `tel:` to the system. File inputs use the photo picker for images and the document picker
104117
otherwise (no media permission). `window.open` goes through a throwaway WebView that catches the
105-
address: the app's own pages load in the one WebView, other sites in a Custom Tab, a blank window is
106-
dropped (the app's page stays). JavaScript dialogs show only for the app's own pages, titled
107-
OpenBot. Downloads: http(s) go to the system's DownloadManager with the page's cookies; `blob:` and
118+
address: the app's own pages load in the one WebView, other sites in a Custom Tab, `mailto:`, `tel:`
119+
and `sms:` go to the system; a blank window waits for its address until the page closes it, or 60 s
120+
(the app's page stays). JavaScript dialogs show only for the app's own pages, titled
121+
OpenBot. Downloads: http(s) from the app's own origin go to the system's DownloadManager with the
122+
page's cookies, into Downloads (API 29+); other sites' files are declined; `blob:` and
108123
`data:` downloads cannot be handed over and are declined with a message. The microphone and camera are granted only to the base origin,
109124
after Android's own runtime permission. A dead renderer (`onRenderProcessGone`) gets a new WebView
110125
and a reload.
@@ -143,6 +158,8 @@ Intent extras (strings), read in `src/debug/java/ai/openbot/shell/DebugHooks.kt`
143158
| `openbot.force_dark=1` | The whole app, WebView included, in dark mode. |
144159
| `openbot.debug_tab_url=URL` | Sign in opens URL in a Custom Tab instead. |
145160
| `openbot.delay_first_load_ms=N` | The first page load starts N ms late, so the loading skeleton can be seen. |
161+
| `openbot.software_layer=1` | The WebView drawn in software (recordings only: the emulator's GPU path misdraws some pages). |
162+
| `openbot.start_signed_out=1` | The first screen even with a session cookie: a leftover session, for `testSignInClearsALeftoverSession`. |
146163

147164
Debug and releaseTest (`TEST_OVERRIDES`): `openbot.base_url`, `openbot.diagnostics=1`, `openbot.test_name`.
148165
Debug builds also draw an invisible view whose content description starts `debug-state` with the

‎android-shell/app/src/androidTest/java/ai/openbot/shell/test/ShellFlowTest.kt‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
package ai.openbot.shell.test
22

3+
import ai.openbot.shell.HandoffMode
4+
import ai.openbot.shell.PendingSignIn
5+
import ai.openbot.shell.PkcePair
6+
import android.content.Intent
37
import androidx.test.ext.junit.runners.AndroidJUnit4
8+
import androidx.test.uiautomator.Until
49
import androidx.test.uiautomator.By
510
import org.junit.Test
611
import org.junit.runner.RunWith
@@ -318,6 +323,38 @@ class ShellFlowTest : ShellTestBase() {
318323
check(signInThroughCustomTab("real", shots = false), "the real sign-in did not reach the tabs after a forged ticket")
319324
}
320325

326+
// The https callback page's "Open the OpenBot app" link: an intent:// address for this package.
327+
// It must reach the trampoline and be taken like the automatic return (same pending sign-in,
328+
// same ticket check). Here the mock refuses the ticket, so the sign-in screen says so.
329+
@Test
330+
fun testOpenTheAppIntentIsTheCallback() {
331+
launch(MOCK_A, "open-the-app")
332+
if (!check(waitFor("sign_in_button", 20_000) != null, "no Sign in button")) return
333+
val ticket = "B".repeat(32)
334+
val https = "https://my.open.bot/api/auth/shell/callback?ticket=$ticket&platform=android"
335+
val link = "intent://my.open.bot/api/auth/shell/callback?ticket=$ticket&platform=android" +
336+
"#Intent;scheme=https;package=$pkg;S.browser_fallback_url=${java.net.URLEncoder.encode(https, "UTF-8")};end"
337+
val intent = Intent.parseUri(link, Intent.URI_INTENT_SCHEME)
338+
.addCategory(Intent.CATEGORY_BROWSABLE)
339+
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
340+
val targets = instrumentation.targetContext.packageManager.queryIntentActivities(intent, 0).map { it.activityInfo.name }
341+
note("the Open the OpenBot app intent resolves to $targets")
342+
check(targets == listOf("ai.openbot.shell.SignInCallbackActivity"), "the intent does not reach the trampoline: $targets")
343+
// With no sign-in pending, the trampoline drops it.
344+
instrumentation.targetContext.startActivity(Intent(intent))
345+
sleep(3_000)
346+
check(device.findObject(By.text(notFinished())) == null, "a callback with no pending sign-in was taken")
347+
// With an https sign-in pending, it is the callback.
348+
PendingSignIn.begin(PkcePair.make(), HandoffMode.Https("my.open.bot", "/api/auth/shell/callback"), "/")
349+
instrumentation.targetContext.startActivity(Intent(intent))
350+
val refused = device.wait(Until.findObject(By.text(notFinished())), 30_000)
351+
check(refused != null, "the intent was not taken as the callback; ${debugState()}")
352+
screenshot("open-the-app-intent-taken")
353+
PendingSignIn.clear()
354+
}
355+
356+
private fun notFinished(): String = instrumentation.targetContext.getString(ai.openbot.shell.R.string.sign_in_not_finished)
357+
321358
private fun sessionCookieNames(): List<String> {
322359
val header = android.webkit.CookieManager.getInstance().getCookie("$MOCK_A/") ?: return emptyList()
323360
return header.split(";").map { it.substringBefore("=").trim() }.filter { it.endsWith("better-auth.session_token") }

‎android-shell/app/src/test/java/ai/openbot/shell/HandoffConfigTest.kt‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,15 @@ class HandoffConfigTest {
7373
assertNull(HandoffConfig.ticket("openbotshell://signed-in?ticket=T2", HandoffMode.WebSignIn("x")))
7474
}
7575

76+
@Test
77+
fun ticketIgnoresTheCallbacksOtherParameters() {
78+
val https = HandoffMode.Https("my.open.bot", "/api/auth/shell/callback")
79+
assertEquals("T3", HandoffConfig.ticket("https://my.open.bot/api/auth/shell/callback?ticket=T3&platform=android", https))
80+
assertEquals("T3", HandoffConfig.ticket("https://my.open.bot/api/auth/shell/callback?platform=android&ticket=T3", https))
81+
assertEquals("T4", HandoffConfig.ticket("openbotshell://signed-in?ticket=T4&platform=android", HandoffMode.Scheme))
82+
assertNull(HandoffConfig.ticket("https://my.open.bot/api/auth/shell/callback?platform=android", https))
83+
}
84+
7685
@Test
7786
fun pkceChallengeIsS256OfTheVerifier() {
7887
// RFC 7636 appendix B.

‎android-shell/ci/run_tests.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
"ShellFlowTest#testSignOutFromAccountMenu",
7979
"ShellFlowTest#testSignInClearsALeftoverSession",
8080
"ShellFlowTest#testWellFormedForgedTicketDoesNotSignIn",
81+
"ShellFlowTest#testOpenTheAppIntentIsTheCallback",
8182
"ShellFlowTest#testFallbackToWebSignIn",
8283
"ShellFlowTest#testOfflineLock",
8384
"ShellFlowTest#testKeyboardHidesTabBar",

0 commit comments

Comments
 (0)