Repository navigation
Conversation
Allow per-host edge-auth headers (e.g. Cloudflare Access service tokens) on direct WebSocket dials. Headers live in SecureStore, never in pairing URLs, and only header names reach logs.
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Credential handling can erase saved secrets or transmit them unencrypted, and lifecycle and route regressions remain unresolved.
Review effort: Balanced
Findings: 3
Open (7)
Move support component out of Expo Router app tree · New Prevent saving before credentials and baseline finish loading · New Require wss for endpoints carrying authentication headers · New Hide unsupported credential controls on web · New Prevent partial endpoint updates when credential operations fail · New Update accessibility test for added credential inputs · New Recheck canceled opens before starting client lifecycle · New
What changed in this PR
Adds per-host edge authentication for Orca Mobile’s direct connections, enabling header-protected tunnels without putting credentials in pairing links.
Changes:
- Adds editable authentication headers backed by secure storage.
- Passes saved headers into direct WebSocket handshakes.
- Adds validation, storage, handshake, and log-redaction tests.
| File | Description |
|---|---|
mobile/src/transport/unpaired-host-credential-deletion.ts |
Deletes headers when unpairing. |
mobile/src/transport/settings-host-client-lifecycle.test.ts |
Mocks credential priming. |
mobile/src/transport/rpc-client.ts |
Adds header connection options. |
mobile/src/transport/rpc-client-socket-session.ts |
Supports custom socket construction. |
mobile/src/transport/rpc-client-socket-headers.test.ts |
Tests handshake headers and redaction. |
mobile/src/transport/rpc-client-socket-factory.ts |
Creates authenticated sockets. |
mobile/src/transport/mobile-endpoint-lifecycle.ts |
Supplies headers to direct connections. |
mobile/src/transport/host-open-recovery.test.tsx |
Mocks credential priming. |
mobile/src/transport/host-logical-client.ts |
Supplies cached host headers. |
mobile/src/transport/host-entry-opener.ts |
Loads credentials before connecting. |
mobile/src/transport/endpoint-auth-headers.ts |
Validates and caches headers. |
mobile/src/transport/endpoint-auth-headers.test.ts |
Tests validation and caching. |
mobile/src/transport/endpoint-auth-headers-store.web.ts |
Provides no-op web storage. |
mobile/src/transport/endpoint-auth-headers-store.ts |
Stores credentials securely. |
mobile/src/transport/endpoint-auth-headers-store.test.ts |
Tests credential storage behavior. |
mobile/src/transport/direct-rpc-client.ts |
Forwards headers and extracts request wiring. |
mobile/src/transport/direct-request-pipeline.ts |
Groups request and stream initialization. |
mobile/src/transport/client-context.test.ts |
Mocks credential priming. |
mobile/app/h/[hostId]/edit.tsx |
Loads and saves authentication settings. |
mobile/app/h/[hostId]/edge-auth-headers-section.tsx |
Adds header editing controls. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| return { id: `edge-auth-${nextRowId}`, name: '', value: '' } | ||
| } | ||
|
|
||
| export function EdgeAuthHeadersSection({ |
There was a problem hiding this comment.
Fixed — moved to mobile/src/components/edge-auth-headers-section.tsx (route-boundary test passes). The row factory moved with it.
| try { | ||
| const stored = await readEndpointAuthHeaders(found.id) | ||
| const entries = stored ? Object.entries(stored) : [] |
There was a problem hiding this comment.
Fixed — the seed now matches normalized blank rows, and an auth-read failure routes to the load-error screen with the form blocked, so an unread baseline can never enable a destructive save.
| export function createEndpointAuthSocket(url: string, headers: EndpointAuthHeaders): WebSocket { | ||
| // Why Reflect: the DOM lib type only knows the two-arg constructor, so the third arg cannot be | ||
| // written directly; React Native's runtime WebSocket accepts (url, protocols, { headers }). | ||
| return Reflect.construct(WebSocket, [url, undefined, { headers }]) |
There was a problem hiding this comment.
Fixed both layers — the editor blocks saving headers against a non-wss endpoint, and the dial path drops headers for ws:// with a values-free warning log instead of sending cleartext. Headerless ws:// still dials as before.
| error: string | null | ||
| onRowsChange: (rows: EdgeAuthRow[]) => void | ||
| }) { | ||
| return ( |
There was a problem hiding this comment.
Fixed — section renders only when Platform.OS is not web; the web store sibling stays a no-op so browser clients can never hold secrets.
| await deleteEndpointAuthHeaders(host.id) | ||
| } else { | ||
| await writeEndpointAuthHeaders(host.id, authNormalized.headers) |
There was a problem hiding this comment.
Fixed — metadata commit and header commit are separate steps now. A header failure keeps a static error on screen (never a keychain message) while an endpoint move still refreshes the live client, so no partial state goes unnoticed.
| <Text style={styles.previewError}>{endpointEdit.error}</Text> | ||
| ) : null} | ||
|
|
||
| <EdgeAuthHeadersSection |
There was a problem hiding this comment.
Fixed — that test now selects Name/Address by label and has a second case covering the header name/value controls and Add-header behavior.
| recordConnectionClientSessionStart(hostId) | ||
| // Why: SecureStore reads are async but the dial path is sync — prime the | ||
| // in-memory snapshot here so every socket this client opens carries it. | ||
| await primeEndpointAuthHeaders(hostId) |
There was a problem hiding this comment.
Fixed — the opener rechecks ticket, demand, and published entry immediately after priming, before constructing the client, so cancelled opens never dial.
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (5)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review. 📝 WalkthroughWalkthroughThe change adds mobile endpoint-authentication header editing, validation, keychain storage, and WebSocket handshake support. It primes stored headers before host connections and clears stored or cached headers during host cleanup. The host edit screen saves authentication changes and refreshes the client when needed. The change also extracts direct request tracker and stream registry construction into a shared pipeline factory. Priority: ➖ Normal Merge Risk: ⚪ Minimal · up to Endpoint authentication headers are validated, stored securely, sent only on secure WebSocket connections, and cleared when a host is removed. No outstanding issue blocks merging. Architecture SummaryArchitecture risk: 🟡 Medium · up to The change affects 1 system. Changed systems: Architecture concerns Review detailsSystems and components
Before / after behavior
Reliability and maintainability
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Out of Scope Changes checkExplanation The PR adds
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 |
There was a problem hiding this comment.
Actionable comments posted: 4
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
045082c9-f2d9-443a-91dd-151fe69a2b9e
📒 Files selected for processing (20)
mobile/app/h/[hostId]/edge-auth-headers-section.tsxmobile/app/h/[hostId]/edit.tsxmobile/src/transport/client-context.test.tsmobile/src/transport/direct-request-pipeline.tsmobile/src/transport/direct-rpc-client.tsmobile/src/transport/endpoint-auth-headers-store.test.tsmobile/src/transport/endpoint-auth-headers-store.tsmobile/src/transport/endpoint-auth-headers-store.web.tsmobile/src/transport/endpoint-auth-headers.test.tsmobile/src/transport/endpoint-auth-headers.tsmobile/src/transport/host-entry-opener.tsmobile/src/transport/host-logical-client.tsmobile/src/transport/host-open-recovery.test.tsxmobile/src/transport/mobile-endpoint-lifecycle.tsmobile/src/transport/rpc-client-socket-factory.tsmobile/src/transport/rpc-client-socket-headers.test.tsmobile/src/transport/rpc-client-socket-session.tsmobile/src/transport/rpc-client.tsmobile/src/transport/settings-host-client-lifecycle.test.tsmobile/src/transport/unpaired-host-credential-deletion.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
There was a problem hiding this comment.
Important
One finding can silently clear saved edge credentials after a keychain read failure — details inline. Everything else looks sound; the WebSocket header plumbing checks out on both platforms.
Reviewed changes
- New edge-auth header model —
endpoint-auth-headers.tsvalidates/normalizes name/value rows, redacts values for logs, caches a per-host snapshot, and builds the header-carrying socket viaReflect.construct. - SecureStore persistence —
endpoint-auth-headers-store.tswrites/reads/deletes a zod-validated bundle through the pairing keychain, marks the host credential write revision, and has a no-op.web.tssibling. - Transport plumbing —
edgeAuthHeadersthreads throughConnectOptions → DirectRpcClient → RpcClientSocketFactory → RpcClientSocketSession; both direct dial sites read the snapshot andhost-entry-opener.tsprimes it before the client is built. - Edit-host UI —
edge-auth-headers-section.tsxandedit.tsxread/write/delete headers and refresh the live client when they change. - Unpair cleanup — deletes the bundle alongside the other host credentials.
- Unrelated extraction —
direct-request-pipeline.tsplus the liveness-probe counter move; no functional change I can see.
ℹ️ Pairing still cannot present edge credentials
Edge headers are only configurable after pairing (Edit host), and the pairing dial (pre-profile-pairing-coordinator → connectDirect) does not carry them. A desktop that is reachable only through the authenticated tunnel still has to be paired over LAN/relay/VPN first. If that is intended (the issue scopes pairing out), a line in the Edit-host help text would set expectations; otherwise the pairing path needs the same snapshot.
ℹ️ Nitpicks
- The new unpair deletion (
unpaired-host-credential-deletion.ts:56) has no test —host-credential-cleanup.test.tscovers the scheduler, not this module — so the "cleared on unpair" security promise is unpinned.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
- wss-only guard for edge-auth headers (editor + dial path) - fail-closed auth baseline on edit screen, no phantom dirty state - split header commit from metadata commit on save - hide section on web, move section out of the route tree - prime-then-recheck cancelled opens, snapshot write-through and synchronous clear on removal - cap values at 1 KiB, truncate invalid names in errors - cover removal chain, redial reuse, prime wiring, pipeline ids
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
This run re-reviewed the two commits on top of 041d9b0803, focusing on the follow-up 396fc889d1.
- Moved edge-auth UI out of the router tree —
useEdgeAuthHeadersandEdgeAuthHeadersSectionnow live insrc/components/edge-auth-headers-section.tsxinstead of the Expo Routerapp/tree. - Fail-closed non-wss dial — new
edgeAuthHeadersForEndpointyields headers only forwss://; the socket factory drops them with a names-only warning, and the edit screen independently blocks saving non-empty headers on aws://address. - Hardened store read/write paths —
writeEndpointAuthHeadersnow writes through to the in-memory snapshot,MAX_VALUE_LENGTHdropped from 4096 to 1024 with a documented keychain rationale, and a store-read failure blocks the edit form (load-error) instead of enabling Save against a mismatched baseline. - Re-check after priming —
host-entry-openerre-checksisCurrent/isWanted/state.storeafter the awaited prime, so a canceled open no longer constructs a client. - Unpair cleanup coverage —
deleteEndpointAuthHeadersin the deletion pipeline is now exercised by a test, andremoveHostsynchronously clears the in-memory snapshot so a re-paired host id cannot inherit stale headers. - Unrelated extraction —
direct-request-pipeline.tsshares onenextIdacross requests, streams, and the liveness probe.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
2c09c9dc-9aad-495c-a057-25c491c14b9f
📒 Files selected for processing (17)
mobile/app/h/[hostId]/edit.tsxmobile/src/components/edge-auth-headers-section.tsxmobile/src/diagnostics/use-mobile-web-bundle-probe.test.tsxmobile/src/host-edit-route-accessibility.test.tsmobile/src/transport/direct-request-pipeline.test.tsmobile/src/transport/direct-request-pipeline.tsmobile/src/transport/direct-rpc-client.tsmobile/src/transport/endpoint-auth-headers-store.test.tsmobile/src/transport/endpoint-auth-headers-store.tsmobile/src/transport/endpoint-auth-headers.test.tsmobile/src/transport/endpoint-auth-headers.tsmobile/src/transport/host-entry-opener.tsmobile/src/transport/host-open-recovery.test.tsxmobile/src/transport/host-store.tsmobile/src/transport/rpc-client-socket-factory.tsmobile/src/transport/rpc-client-socket-headers.test.tsmobile/src/transport/unpaired-host-credential-deletion.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- mobile/app/h/[hostId]/edit.tsx
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
8e9ef02c-9827-4bec-89eb-5561aeae9804
📒 Files selected for processing (4)
mobile/src/transport/endpoint-auth-headers-store.test.tsmobile/src/transport/endpoint-auth-headers-store.tsmobile/src/transport/endpoint-auth-headers-store.web.tsmobile/src/transport/host-entry-opener.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
This run re-reviewed the one commit on top of 396fc889d1, focusing on the hardening in 749609ccf0.
- Normalize on write —
writeEndpointAuthHeadersnow runs input throughnormalizeEndpointAuthHeadersbefore persisting, so a write can never store a bundle that the reader'sparseStoredBundlewould later reject. Invalid rows throw a name-onlyInvalid edge-auth headers: ...error (values never appear). - Guard prime against stale opens —
primeEndpointAuthHeadersaccepts an optionalisCurrentpredicate and skips caching the snapshot when the open is no longer current, so a removal that cleared the cache mid-read cannot be resurrected.host-entry-openerpasses itsisCurrentand still re-checks ownership after the await. - Test coverage — added cases pinning that un-normalizable headers are rejected without touching the keychain, and that a non-current prime returns headers without caching.
- No regressions — write is only reached via
useEdgeAuthHeaders.persistAuthChanges(already normalized), and the web sibling signature stays in sync.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
ℹ️ No critical issues — one minor correctness note inline.
Reviewed changes
This run re-reviewed the single commit on top of 749609ccf0, the prime/hardening change in a925e75.
- Prime skips cache on a mid-read write —
primeEndpointAuthHeaderssnapshotsgetHostCredentialWriteRevision(hostId)before the keychain read and only caches when the revision is unchanged afterward, so a header write landing during the read wins instead of being overwritten by the stale value. - Failed read no longer clobbers a concurrent write — the
catchbranch cachesnullonly when the revision is still unchanged. - Test — a new case marks a write from inside the mocked
getItemAsyncand asserts the snapshot stays empty.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
This run re-reviewed the single commit on top of a925e75, the prime/removal hardening in a78a90c.
- Auth mutation epoch — added
noteEndpointAuthHeadersChanged/endpointAuthMutationEpochto the shared module; writes, deletes, and removals bump a per-host epoch, andprimeEndpointAuthHeadersnow caches only when both the credential write revision and the epoch are unchanged across the read. - Delete bumps the epoch, not the revision —
deleteEndpointAuthHeadersdeliberately avoidsmarkHostCredentialWrite(a revision change would trip the deferred cleanup re-pair guard inunpaired-host-credential-deletion), so the epoch is what invalidates an in-flight prime on a clear. - Removal clears the snapshot — moved the synchronous edge-auth cache clear out of
host-store.removeHostintoremoveHostAndCloseClient, paired with the epoch bump; basehost-storeis unchanged again andremoveHosthas no other production caller. - Tests — a mid-read clear case in the store suite, plus removal coverage asserting the snapshot is cleared and the epoch advances.
The prior open thread (endpoint-auth-headers-store.ts:101, mid-read clear re-caching removed headers) is addressed by this epoch mechanism and has been resolved.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
This run re-reviewed the single commit on top of 02e0149, the dial-diagnostics change in ebda868.
- Edge-auth names in dial diagnostics —
RpcClientSocketFactory.opennow appends the names-onlydescribeEndpointAuthHeadersForLog(edgeAuthHeaders)output to theOpening WebSocket/Reconnectinglogdetailwhen headers actually ride the dial (i.e. the endpoint passed thewss://gate), while headerless dials keep the previousredactSocketEndpointstring. Values still never enter the detail. - Test coverage — the handshake test now pins that the
Opening WebSocketentry'sdetailcontains the endpoint host and both header names, alongside the existing assertions that neither value appears in the logs.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
This run re-reviewed the single commit on top of ebda868, 6198469a ("scroll focused edge-auth row into view").
- Scroll the focused edge-auth row above the keyboard —
EdgeAuthHeadersSectionsubscribes tosubscribeSoftKeyboard, tracks the focused row id and row refs, and on a keyboard-show event scrolls that row's native handle into view through the parentScrollView'sscrollResponderScrollNativeHandleToKeyboard.edit.tsxthreads its formScrollViewref down asscrollViewRef. - Extracted the
wss://endpoint gate — the edit screen's inlineauthNeedsWsscomputation is nowcheckEdgeAuthEndpoint(headers, endpoint)inendpoint-auth-headers.ts, alongsideedgeAuthHeadersForEndpoint;canSaveand the section error both derive from it. Behavior is unchanged (empty headers pass, non-empty headers require awss://endpoint). - Test coverage — new
edge-auth-headers-section.test.tsxpins that a keyboard show scrolls the focused row (handle123, numeric offset,preventNegativeScrollOffsettrue);host-edit-route-accessibility.test.tsadds theKeyboardmock the section now needs.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
This run re-reviewed the single commit on top of 6198469a, 8bf79833 ("default bare wss addresses to 443").
- Bare
wss://defaults to:443—resolveHostEndpointEditnow detects awss://-schemed input with no explicit port and uses443as the fallback instead of the stored endpoint's port, so typing a tunnel hostname no longer aims TLS at the stored:6768. - Explicit ports and other inputs unchanged — an explicit
:portstill wins, and bare-host /ws://inputs keep inheriting the current port; theedit.tsxhelp text was updated to match. - Test coverage — three exact-equality cases pin the new default plus explicit-port precedence (
host-endpoint-edit.test.ts:44-52).
The prior open thread on this PR (mid-read clear re-caching removed headers) remains resolved by the a78a90c mutation-epoch mechanism; nothing in this delta reopens it.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
This run re-reviewed the single commit on top of 8bf79833, 87699b45 ("scroll header row into view on focus").
- Scroll on focus, not only on keyboard-show —
EdgeAuthHeadersSectionextractsscrollFocusedRowIntoViewand now calls it fromfocusRow, so focusing a row scrolls it into view immediately when the keyboard was already open from an earlier field (no new keyboard-show event fires in that case). The keyboard-show subscription still scrolls as before. - Test coverage — a new case in
edge-auth-headers-section.test.tsxfocuses an input with no keyboard event and asserts the scroll call, pinning the focus-only path.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
|
I adapted the mobile header work into #31880, preserving Mark Hingston's co-author credit. The follow-up adds secure-origin binding, authenticated-socket redirect refusal, native capability checks and cancellation/logging regressions. The remaining client paths are split into #31886 (initial native pairing through Access) and #31885 (desktop protected storage and CLI credential-file input); #31499 covers sharing addresses/documentation. Linking these for coordination and review of the overlapping work, rather than assuming this PR should be closed. These are open review proposals, not released support. Upstream PR CI still needs maintainer approval; real-device and browser Access-session acceptance remain outstanding. Tunnel creation remains manual. |



ELI5
If your Orca desktop sits behind a tunnel that asks for its own login (like Cloudflare Access), the phone app previously had no way to present those credentials, so the connection died at the tunnel edge. Now you can save those edge credentials per host on the Edit-host screen, and the app sends them with the connection handshake.
What Changed
Before: tapping a host behind an authenticated tunnel failed (HTTP 401/403 at the edge) with no way to supply edge credentials; the only paths were an open tunnel, relay, or VPN.
After: Edit host has an Edge authentication section (header name + secret value rows). Saved headers attach to the direct WebSocket handshake for that host, including reconnects and endpoint probes (which dial through the same client).
Mechanism: per-host header bundle in SecureStore via the existing pairing-keychain machinery (
orca.mobile-endpoint-auth.<hostId>, zod-validated, RFC 9110 names, max 8); primed to memory at host-open and threadedConnectOptions -> DirectRpcClient -> RpcClientSocketFactory -> RpcClientSocketSessioninto React Native'sWebSocket(url, protocols, { headers }); header names (never values) in open logs; cleared with the rest of the host credentials on unpair. Web is structurally excluded (no-op store sibling, browsers cannot set handshake headers anyway).Why
Fixes #24709. Custom headers (option 1 in the issue) cover Cloudflare Access service tokens and any header-based edge auth without Orca becoming Cloudflare-specific. Alternatives considered: stuffing credentials into pairing URLs (rejected in the issue — secrets must not travel in links/QR), and query-param tokens (many edges only accept headers, and URLs get logged).
Linked Issue
Fixes #24709
Visual Proof
Edit Host
Network diagnostics
Testing
endpoint-auth-headers.test.ts(validation, log redaction, snapshot cache),endpoint-auth-headers-store.test.ts(keychain round-trip, host mismatch, corrupt payloads, fail-closed prime),rpc-client-socket-headers.test.ts(headers reach the handshake, plain sockets unchanged, values never logged)mobile: typecheck, tests-typecheck ratchet, fullsrc/transportsuite (1207 passed), oxlint, andcheck:code-quality:changedall passAI Disclosure
Implemented with AI coding assistance (OpenCode agent).
Notes
Security: values live only in SecureStore (
WHEN_UNLOCKED_THIS_DEVICE_ONLY) and process memory; pairing links, QR codes, connection logs, and diagnostics carry names at most. Cross-platform: native-only by construction; web resolves no-op siblings. Backwards compatible: hosts without headers dial exactly as before.