Repository navigation
fix(app): keep a PC address that redirects to Ovis in the app - #1903
Conversation
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Health probes and origin validation app/android/app/src/main/java/sh/ovis/app/PCStore.java, app/android/app/src/test/java/sh/ovis/app/PCStoreTest.java, app/android/app/build.gradle, app/ios/App/App/HerdrBridgeViewController.swift, shared/bridge-protocol.test.ts |
Both platforms probe /api/health?scope=bridge and validate the response, including supported bridge protocol values. Probes enforce redirect, timeout, and response-size limits and reject invalid JSON. Android tests cover probe outcomes, address classification, and preservation of target URL components. |
Android initial-load redirects app/android/app/src/main/java/sh/ovis/app/MainActivity.java, app/android/app/src/main/java/sh/ovis/app/HerdrShellPlugin.java, docs/native-app.md |
Before the first page appears, MainActivity intercepts cross-origin main-frame redirects and probes their destinations. It reopens verified Ovis origins or shows an error for rejected destinations and redirect limits. Open, retry, and successful loads reset the redirect counter. The documentation describes this behavior. |
iOS initial-load redirects app/ios/App/App/HerdrBridgeViewController.swift, app/ios/App/App/HerdrShellPlugin.swift, docs/native-app.md, changelog.d/app-redirect-stays-in-app.md |
Before the first page commits, NavigationFailureProxy intercepts provisional cross-origin navigation and probes its destination. It reopens verified Ovis origins or reports an error for rejected destinations, insecure hops, and redirect limits. Open, retry, and successful loads reset the redirect counter. The documentation and changelog describe the behavior. |
Priority:
Estimated code review effort: 4 (Complex) | ~60 minutes
Change: Bug fix
Possibly related PRs
- devswha/ovis#1697: Both PRs change native app first-load navigation and failure handling.
- devswha/ovis#1860: Both PRs change iOS provisional navigation behavior in
HerdrBridgeViewControllerandNavigationFailureProxy.
Merge Risk: 
Minimal · up to a04f6
-
This change keeps a PC address that redirects to an Ovis server inside the app and refuses non-Ovis destinations. No actionable merge-blocking issue was identified. The remaining uncertainty is limited to real-device redirect behavior, which the author reports testing on an emulator and a simulator.
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passed-
Full details: Description check
-
Explanation
The description explains the problem, resulting behavior, platform-specific implementation, security constraints, tests, emulator and simulator validation, and the Android bundle limitation. It uses headings different from the template but provides the required change and validation information.
-
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 34.57% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 81 functions across 7 files. (3 skipped: 3 unsupported.)
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
-
Finishing Touches: 💡 2
-
📝 Generate docstrings: 💡
-
- Commit to this branch
- Create a new PR
🧪 Generate unit tests (beta)
-
- Commit to this branch
- Create a new PR
🛠️ Fix failing CI checks: 💡
-
- Commit to this branch
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands.
|
CodeRabbit hit its review limit on this PR, so no review ran. Two agent reviews stand in for it. Both read the v4 change in full: an omo-native-code-reviewer pass and a Codex Sol pass (gpt-6.1-sol, read-only). They reviewed f52bf9828. This PR's 614941b is that commit rebased on main, with only the Verdicts: both approve, with no blocker or major finding. Findings from earlier rounds, resolved in v4:
Findings on v4:
|
|
@coderabbitai review |
|
|
Merge pass: this is now under review (Astra gate, native shell). One ordering point: #1860 (show the PC being opened on iOS) is older and already approved, and it conflicts with this PR in |
|
Merge pass gate review of 614941b: two blockers. The "answers as Ovis" check is looser than it should be. It decides who gets the native bridge. 1. Any numeric
2. Android accepts malformed JSON and trailing garbage (
Please also close this, though the gate rates it a note: Android adopts a redirect from https to http, and that skips the connect screen's public-HTTP warning. A user who typed an https address can end up giving the bridge to a plain-text origin. Refuse a downgrade, or route it through the same warning. Holds
The merge pass re-checks the fix (changed range only). #1860 merges first, as noted above. |
|
Status for the merge pass: your gate findings are fixed in a local commit, which I'll push once, rebased onto main, right after #1860 merges (the conflict with #1860 is resolved and was built and checked on the iOS simulator). The changes:
Checked:
Reviews: omo-native-code-reviewer and Codex Sol needed three rounds. Sol's later findings were fullwidth |
A PC address that answered with a redirect opened in the phone's browser: Capacitor hands any main-frame navigation to another host or scheme to ACTION_VIEW on Android and to Safari on iOS, redirects included. Testers with Firefox as their default browser saw Ovis open there. A redirect to another port stayed in the Android WebView, but without the bridge. Until the first page shows, the app now holds such a redirect of the address being opened back and asks the target's /api/health?scope=bridge, which Ovis answers to anyone, following up to five redirects of that question within ten seconds and reading at most 64 KB. An origin that answers as Ovis (http to https, an IP address to the PC's name, another port) becomes the PC and opens again as the first page, with the bridge: the address's own page would have had the bridge too. Anything else, such as a sign-in page, another site or a loop, gets no bridge and is not saved, and the error page names where the address led. Once the first page shows, Capacitor decides on redirects as before, so a link to a page that is not the PC's (another port on its host) cannot make that page's redirect the PC. Links to other sites still open in the browser.
The merge pass's gate found the "answers as Ovis" check looser than a check that hands out the native bridge should be. Android read /api/health with org.json, which takes unquoted names and ignores text after the object, and both platforms took any number as the bridge protocol (-1 and 0.5 on Android). Both platforms now read the answer strictly: valid UTF-8, one JSON value for the whole text, quoted names given once, ASCII hex in \u escapes and nesting kept shallow (Android with its own reader, iOS with a check before JSONSerialization, which lets a trailing comma pass and keeps the first of two equal names). Only an integer bridge protocol this app knows counts, 1 for now: shared/bridge-protocol.test.ts fails when BRIDGE_PROTOCOL in shared/machines.ts moves without the app's range. The way from the address being opened to the Ovis server it leads to, each hop of the probe included, must not go over public plain http or from https to http: the app does not switch there on its own, as the connect screen warns before a public http address. A numeric host in any form but a plain dotted quad (134744072, 010.0.0.1, 0x8.8.8.8), which the web view reads as some IPv4 address, counts as public. The error page names the hop and the address to open directly.
|
Merge pass: #1860 is merged (ce8ede5). Please rebase this PR onto main now. It conflicts with #1860 in |
614941b to
a04f64d
Compare
|
Merge pass: rebased onto main after #1860 (
Checked on this exact tree:
Reviews: omo-native-code-reviewer and Codex Sol both approve the final gate commit after three rounds. The PR body is updated. |
|
Merge pass review-work report. Overall: PASSED.
QA at a04f64d
Gate
Notes (not blocking): hostname exemptions are by name, not DNS-verified, and none of them bypasses the https downgrade check. The custom parser needs maintenance. All required checks are green and no review thread is open. CodeRabbit did not review this PR (rate-limited or skipped). The reviews above stand in for it. |
What was wrong
Testers on Android typed their PC's address on the app's connect screen and Ovis opened in Firefox instead of in the app.
Capacitor 8.5.3 hands every main-frame navigation whose host or scheme differs from
server.urlto the system browser (Bridge.launchIntent→ACTION_VIEWon Android,UIApplication.open→ Safari on iOS), and a server redirect is such a navigation. So a PC address that answers with a redirect left the app: http to https (Caddy and nginx setups redirect by default), an IP address to the PC's name, a sign-in page in front of it. A redirect to another port on the same host stayed in the Android WebView, but without Capacitor's bridge (it is injected for theserver.urlorigin only): no Change PC, no push, and the PC was never saved. The Ovis server itself never redirects, so the testers' setups had a proxy or tunnel in front.The fix
Until the first page shows, a main-frame redirect of the address being opened to another http or https origin is held back, and the app asks that origin's
/api/health?scope=bridge, the open route Ovis answers to anyone ({ ok: true, auth: { ... }, bridge_protocol: 1 }). Only that shape counts:oka JSONtrue,authan object, andbridge_protocolan integer this app knows (1,BRIDGE_PROTOCOLinshared/machines.ts), in strictly valid JSON: one value for the whole text, quoted names given once, ASCII hex in\uescapes, nesting at most 32 deep. Android reads it with its own strict reader (org.jsontakes unquoted names and ignores text after the object); iOS checks it beforeJSONSerialization, which lets a trailing comma pass and keeps the first of two equal names.shared/bridge-protocol.test.tsfails whenBRIDGE_PROTOCOLmoves without the app's range. It follows up to five redirects of that question itself (no automatic redirects), gives up after about ten seconds in all (on Android a slow name lookup, which cannot be cut short, can add a few) and reads at most 64 KB.?pair=) carry over. The address that only redirected is not saved.onPageCommitVisible, iOSdidCommit), not when the page finishes loading, so a PC page with a resource that never finishes does not keep it open.publicHttpinapp/web/shell.js, ported to both platforms). The error page names the hop and the Ovis address to open directly. A tailnet or home address (100.64.0.0/10,192.168.x.x,*.ts.net,*.local, a one-word name) to another one, or anything to https, is fine.Trust: before the first page shows, a redirect can only come from the address the user is opening, and that address's own page would get the bridge anyway, so the origin it leads to gets nothing more, and only if it answers
/api/healthas Ovis. A sign-in or other page a proxy redirects to never gets the bridge.Per platform:
MainActivity'sBridgeWebViewClientcatchesrequest.isRedirect()in the main frame before Capacitor sees it and probes on a background thread (PCStore.ovisOrigin,PCStore.startOn). Same-origin redirects still go to Capacitor. The probe's budget holds even against a server that trickles its headers or body: a scheduleddisconnect()ends the request at the deadline, and the body loop checks it too.NavigationFailureProxytakes any main-frame action to another origin that arrives before the first commit, while the main frame's navigation is provisional, and probes with an ephemeralURLSession(PCStore.ovisOrigin(leadingTo:), streamed with the 64 KB cap,StrictJSONfirst, thenokmust be a JSON boolean andbridge_protocolan integerCFNumberin range). App Transport Security keeps thatURLSessionto https and local names, so a redirect to plain http on a tailnet address or name ends on the error page naming the address to open directly (documented indocs/native-app.md).Checked
./gradlew :app:testDebugUnitTest:PCStoreTest8/8 pass. Mutations: without thedisconnect()watchdog, the header-trickle case runs into the test's 20 s timeout. Without the body-loop check, it still passes, ending about 3 s late, so that check is a backstop.10.0.2.2and, throughadb reverse, aslocalhost):10.0.2.2:7491→ 302localhost:7492(Ovis): the app's probe (Dalvik user agent) asked/api/health?scope=bridge, then the WebView loadedhttp://localhost:7492/withCapacitor.isNativePlatform() === true. Saved was[http://localhost:7492], Ovis stayed the top activity, and no Firefox task opened.10.0.2.2:7497→ 302localhost:7498(a sign-in page): only the probe reached 7498, and the WebView never loaded the sign-in page. The error page read "It redirected to http://localhost:7498, which did not answer as Ovis. If that is your PC, open http://localhost:7498 itself." Nothing was saved, and Firefox did not open.10.0.2.2:7489→ 302localhost:7488, whose server trickles response headers forever: the app closed that connection after 9.99 s (Android's ownHttpURLConnection, so the watchdog holds on a device too), and the error page showed 11 s after Open.localhost:7492, a link redirecting to10.0.2.2:7492(Ovis) opened in Firefox (ACTION_VIEW dat=http://10.0.2.2:7492/). There was no probe, and the PC and saved list were unchanged on returning.10.0.2.2:7499,readyStatestillinteractive): the link redirecting tolocalhost:7492opened in Firefox with no probe, and the app kept10.0.2.2:7499.ACTION_VIEW dat=https://github.com/devswha/ovis), and the PC was unchanged on returning.app/ios, servers tunnelled to the Mac):127.0.0.1:7591→ 302localhost:7592(Ovis): the app'sURLSessionasked/api/health?scope=bridge, then the WebView loadedlocalhost:7592withCapacitor.isNativePlatform() === true. Current, last and saved werelocalhost:7592. Safari did not open.127.0.0.1:7597→ 302localhost:7598(a sign-in page): only the probe reached 7598. The error page read "It redirected to http://localhost:7598, which did not answer as Ovis. If that is your PC, open http://localhost:7598 itself." Safari did not open.localhost:7593whose link/go-ovisredirects to127.0.0.1:7592(Ovis): there was no probe, Safari loaded it, and the app keptlocalhost:7593.didFinishnever comes): the v4 build sent it to Safari with no probe. The previous build, which closed the window atdidFinish, adopted127.0.0.1:7592as the PC. Codex Sol found that case in review; this commit closes the window at the first commit instead.PCStoreTest12/12, with new tests for rejected protocol values (-1, 0, 0.5, 1.0, 1e0, 2, "1", true, null, 20 digits), non-strict JSON (unquoted names, trailing text, two objects, a duplicate name, single quotes, a trailing comma, a fullwidth\uescape, 60000[), the way's hops (https to http, a later hop to public http, private to public http, and the tailnet, home and https cases that stay allowed) andpublicHttpagainstshell.js's cases. Each check was mutated away once (range, end of text, depth cap, ASCII hex, whole path), and the matching test failed.PCStore/StrictJSONpart of the Swift file was compiled withswiftcon the Mac against the same cases: 61/61.bridge_protocol: 3ended on the error page with nothing saved, and one answering 1 was adopted with the bridge. A sign-in page was refused.bridge_protocol: 3, the typed10.0.2.2:7491ended on the error page with nothing saved.10.0.2.2:7486redirects tohttp://127.0.0.1.nip.io:7492(a public-looking http name that resolves to the PC), which answered as Ovis. The app still refused it: "It redirected over plain http to http://127.0.0.1.nip.io:7492, which the app does not follow on its own." Nothing was saved. The first round's checks passed again: the Ovis redirect was adopted with the bridge, the sign-in page and the trickling server (cut off after 9.99 s) ended on the error page, and after the page loaded, the Ovis link and the GitHub link went to Firefox.bun run check faston the rebased head: passed (unit tests 6413 pass, 0 fail, 13 skip; typecheck and build).Note for the Android bundle
The fix is in the native shell, so
ovis-android-1.0-2.aab, built before it, does not have it and needs to be built again from a commit that includes it.