Skip to content

fix(remote)!: never send credentials over plain http off loopback - #5150

Closed
thymikee wants to merge 22 commits into
mainfrom
t3/reject-insecure-remote-daemon
Closed

thymikee wants to merge 22 commits into
mainfrom
t3/reject-insecure-remote-daemon

Conversation

@thymikee

@thymikee thymikee commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

Summary

A credential never goes over plain http or ws to a host that is not loopback (127.0.0.0/8, ::1, localhost), and no redirect carries it to another origin. Refusals come before anything is sent, with details.reason: insecure_credential_transport. Requests use fetch and node:http. Loopback is safe by design: it stays on the host.

Breaking: token-bearing http:// LAN or VPN URLs stop working, as does a plain non-loopback proxy upstreamBaseUrl. The proxy follows no upstream redirect. The Metro companion refuses relayed WebSockets to a LAN http dev server and returns relayed redirects to the bridge. Use https or ssh -L.

Net lines: latest commit +442 −458; branch +1721 −181 (non-test source +417 −92).

Before / after

agent-device session list --daemon-base-url http://10.0.0.7:4310/agent-device --daemon-auth-token <t>
base: sends "authorization: Bearer <t>" in cleartext
head: INVALID_ARGS, details.reason "insecure_credential_transport", nothing sent

Security

fetch redirect: 'follow' between two local servers; identical on Node 26.11.1 and 22.12.0; no Referer sent:

same-origin 302 {"method":"GET","kept":["authorization","proxy-authorization","cookie","x-agent-device-token","x-agent-device-runner-token","x-api-key","x-revyl-client"],"body":""}
same-origin 307 {"method":"POST","kept":["authorization","proxy-authorization","cookie","x-agent-device-token","x-agent-device-runner-token","x-api-key","x-revyl-client"],"body":"body-secret"}
cross-origin 302 {"method":"GET","kept":["x-agent-device-token","x-agent-device-runner-token","x-api-key","x-revyl-client"],"body":""}
cross-origin 307 {"method":"POST","kept":["x-agent-device-token","x-agent-device-runner-token","x-api-key","x-revyl-client"],"body":"body-secret"}
https->http 302 {"method":"GET","kept":["x-agent-device-token","x-agent-device-runner-token","x-api-key","x-revyl-client"],"body":""}
https->http 307 {"method":"POST","kept":["x-agent-device-token","x-agent-device-runner-token","x-api-key","x-revyl-client"],"body":"body-secret"}
manual     cloud profile, Metro bridge, companion register/unregister (a 3xx fails, not
           retried); relayed requests; proxy (no Location); cloud auth (same origin, max 3);
           Limrun download (max 20; same origin, or https->https without headers)
error      Apple runner, Revyl, Limrun API
Exception  runner token to the CoreDevice tunnel: devicectl-reported, in fd00::/8
Uncovered  WebDriver providers, install-from-source headers, Limrun SDK client

Validation

At 8a7acf1: the six changed test files (81 tests) and OXC format and lint passed. Full gates last passed at 572b141; CI pending.

The live Wi-Fi iPhone check passed on 678a0c6. The runner now sends there through fetch (unit-tested); not re-run live.

🤖 Generated with Claude Code

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 23 files

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

Comment thread packages/proxy/src/daemon-proxy.ts Resolved
Comment thread src/cli/cloud-auth-request.ts Resolved
Comment thread website/docs/docs/commands.md Resolved
Comment thread packages/contracts/src/daemon-http.ts Resolved
@apex-sentinel-staging

This comment has been minimized.

@thymikee
thymikee force-pushed the t3/reject-insecure-remote-daemon branch from c7646db to 9d3b49e Compare November 27, 2026 12:29
@github-actions

github-actions Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Size Report

Metric Base Current Diff
Installed (including dependencies) 6.67 MB 6.67 MB +5.2 kB
Package (unpacked) 6.67 MB 6.67 MB +5.2 kB
Package (download) 2.04 MB 2.04 MB +1.9 kB

Startup median (7 runs, lower is better):

Scenario Base Current Diff
CLI --version 22.1 ms 21.7 ms -0.3 ms
CLI --help 46.7 ms 48.4 ms +1.7 ms

@thymikee

Copy link
Copy Markdown
Member Author

Round 2 (9d3b49e) covers the security review's eight items and Cubic's four threads. The branch is rebased on main.

  1. Proxy redirects: every upstream request carries redirect: 'error'. Test: a 307 target receives nothing.
  2. Connect-cloud profile: checks the URL before attaching the bearer, and follows redirects only on the same origin (fetchCloudOnOneOrigin, shared with the auth POSTs). Tests: no fetch for an http cloud; a cross-origin redirect is refused before the target is contacted.
  3. upstreamFetch is no longer an opt-out: the rule applies to every transport, checked on the first exchange. Test: neither transport sends anything.
  4. Metro: a malformed base is refused. The final bridge, register and unregister URLs are checked before each fetch, including in the standalone worker. Tests cover http://bridge.invalid and http:.
  5. Upload tickets: every ticket URL must be https or loopback, whatever carries the credential, else the upload takes the legacy route.
  6. Environment proxies: credential requests to loopback http connect directly through @agent-device/host-kit/direct-http. This covers the daemon client, remote transfers and diagnostics, and the proxy's transports. A child-process test with NODE_USE_ENV_PROXY=1 shows the proxy receives nothing.
  7. Limrun and the forwarded runner route: Limrun API, sync and download URLs, and forwarded runner routes are checked at send time, with dispatched: no. Simulator loopback, USB and the CoreDevice tunnel are unchanged. WebDriver basic auth and install-from-source caller headers stay out of scope.
  8. Eager imports: daemon-http.ts is back to main. The rule lives in the new subpath contracts/credential-transport and is loaded lazily on request paths. eager-closure-budgets passes locally.

Cubic: neutral "Cloud base URL" subject; restored the http(s):// synopsis with the tokenless note; one loopback matcher, which Revyl now imports.

@apex-sentinel-staging

This comment has been minimized.

@apex-sentinel-staging apex-sentinel-staging Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apex Sentinel: 2 new findings on fa7fbfe. The verdict and the full list are in the summary comment.

Comment thread packages/proxy/src/daemon-proxy.ts Resolved
Comment thread packages/proxy/src/daemon-proxy.ts Resolved
@thymikee
thymikee force-pushed the t3/reject-insecure-remote-daemon branch from fa7fbfe to 3fe1be5 Compare November 27, 2026 13:14
@apex-sentinel-staging

This comment has been minimized.

@apex-sentinel-staging apex-sentinel-staging Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apex Sentinel: 2 new findings on 1809716. The verdict and the full list are in the summary comment.

Comment thread packages/host-kit/src/direct-http.ts Resolved
@thymikee

Copy link
Copy Markdown
Member Author

e3e7fb4 closes the open items:

  • Relayed Location: compared by decoded path; query and fragment dropped. An upstream redirect on /health now makes the proxy's /health answer 500.
  • Malformed upstream base (http://): no throw at construction, nothing sent, 400 per request. Other unusable bases behave the same.
  • Companion worker: the base must be a URL with a host before a path is appended.
  • Environment proxies: cloud auth, Metro, Limrun and the Apple runner send plain http through the direct requester.
  • Limrun downloads: redirects only https to https or same origin, checked on every hop, headers dropped on leaving the origin.
  • Review threads: direct requester idle bound and abort handling, direct agent always applied, and CodeQL alert 83.

Not covered by this push: Revyl on a loopback http REVYL_API_URL still uses global fetch, and the companion bridge WebSocket URL is not checked. Both are listed under Security in the description.

@apex-sentinel-staging

This comment has been minimized.

@thymikee

Copy link
Copy Markdown
Member Author

61eb773 closes the two gaps listed as open:

  • Revyl: loopback http goes through the direct requester, so an environment proxy never sees the API key. A presigned upload URL that is neither https nor loopback http is refused before anything is sent.
  • Metro bridge socket: the registered ws_url must be wss, or ws to loopback, checked before the socket opens; the companion then unregisters and exits. The check applies to every ws_url, because that URL is what admits the companion.
  • Also found: under NODE_USE_ENV_PROXY=1 the global WebSocket sent a loopback ws:// URL, query included, to the proxy. A loopback socket now connects directly through undici (already bundled; new dependency entry for react-native).

The description is shortened to meet the body word limit.

@apex-sentinel-staging

This comment has been minimized.

@apex-sentinel-staging

This comment has been minimized.

@apex-sentinel-staging

This comment has been minimized.

@thymikee

Copy link
Copy Markdown
Member Author

The code at 3e9aeb4 needs changes before merge: one device route lacks live proof, and some paths can still leak a credential or break loopback and refusal behavior.

The physical iOS route over the CoreDevice tunnel (device not attached by USB) changed in two ways at runner-transport.ts:112. It now refuses any devicectl-reported address outside fd00::/8 (runner-command-route.ts:131), and it sends through the node:http direct path (direct-http.ts:55) instead of undici fetch. If an address falls outside that range, or node:http handles a bracketed ULA host differently, would every command to a Wi-Fi-only iPhone fail with insecure_credential_transport or a transport error? This device-facing path needs live evidence. Please run pnpm build at this commit, then use node bin/agent-device.mjs against a physical iPhone that usbmuxd does not list (Wi-Fi only, cable detached). open, snapshot and one tap must all exit with status 0, and diagnostics or the daemon log must show the request going to http://[fdXX::…]:<port>/command via coredevice-tunnel.

A second independent pass found that the localhost exception likely trusts the name before the address is resolved (loopback-host.ts:14). If the system resolver maps localhost to a LAN address, a token-bearing http://localhost daemon URL is still admitted. The health and RPC senders pass that hostname to node:http (daemon-client-transport.ts:313, daemon-client-transport.ts:854), and the direct agent only disables the environment proxy, so the daemon token reaches the LAN peer in cleartext. The shared agent also serves proxy, upload and other HTTP callers, and the companion's plain WebSocket agent does its own unrestricted lookup for a localhost socket ticket. Every credential-bearing HTTP agent and WebSocket dispatcher should share a loopback-only localhost lookup, connect only to verified loopback addresses, and report insecure_credential_transport when none exists.

A second independent pass found that the Metro companion likely forwards credential headers over unchecked plain HTTP (client-companion-tunnel-worker.ts:334). A valid wss bridge can send an http-request with Authorization or Cookie for a LAN Metro server set as the local base, and the worker sends it with global fetch. The path can also be absolute, because it is resolved with new URL(message.path, localBaseUrl). The new checks cover registration, unregistration and the bridge socket, but not this outbound leg. Any relayed request that carries a credential should pass the destination check on its resolved URL and on each redirect target, and authenticated loopback sends should use the direct transport.

A second independent pass found that proxy health, diagnostics and transfer refusals likely lose the transport reason (daemon-proxy.ts:964). With a non-loopback plain HTTP upstream, GET /health and authorized diagnostics, upload and artifact requests stop before the upstream send, but the generic error body exposes only INVALID_ARGS and the message. Transfer serialization handles only COMMAND_FAILED, and proxy_upstream_userinfo is lost the same way. Every non-RPC error response should carry the safe typed admission reason, keep the existing transfer failure fields, and leave out the destination.

A second independent pass found that companion transport refusals likely end as a successful worker exit (client-companion-tunnel-worker.ts:201). When a bridge returns an off-loopback ws_url, the worker refuses and unregisters, but refuseWithoutRetry replaces the AppError with a message-only CompanionRegistrationError. The loop logs it and breaks, and the process entry reports success. Initial registration URL refusals are flattened too. Each transport refusal should stay terminal, keep its original AppError, and surface through the worker's failure path after cleanup.

A second independent pass found that loopback Metro bridge requests likely lose same-origin redirects (client-metro.ts:464). On the base branch, a 307 to the canonical path was followed with the POST body and bearer. Now the direct requester returns the 307 unchanged, so Metro prepare treats bridge setup as failed. The companion's loopback register and unregister calls set no redirect policy either, so registration fails and unregistration can report completion without reaching the canonical path. Every Metro bridge POST should follow a bounded number of same-origin redirects, use direct transport on each loopback hop, and keep the method and body semantics.

A second independent pass found that direct loopback requests likely expose compressed bytes to Response consumers (direct-http.ts:109). The base fetch path decodes Content-Encoding: gzip, but the new requester wraps the compressed stream, which affects cloud auth and profile parsing, Metro bridge and companion parsing, and Revyl API decoding. The proxy RPC and diagnostics relay also strips Content-Encoding, so its clients cannot decode the bytes, and proxy health can silently lose the upstream payload. The direct HTTP path should decode supported content encodings before it exposes the body, as fetch does.

Could one host-kit primitive be the only way to send a credential? For example, fetchWithCredential(urlOrRequest, init, { subject, send }) would call assertSecureCredentialTransport on every URL it sends to, route plain HTTP direct and the rest through fetch or the injected send, and loadNodeHttpRequester would take the URL and check it in direct mode. The proxy default upstream and the upload client could then drop their own dispatch, about 10 separate checks could go, the Limrun launch would stop relying on an earlier check, and a new credential path could not skip the rule, while the daemon client keeps its early base-URL check. Could the WebDriver provider transport, which still sends credentials outside the rule, use the same primitive, or should the trust page sentence be narrowed?

Not blocking: these can be taken or left: making fetchWithCredential own the check, because it never applies the rule itself (direct-http.ts:168) and the Limrun launch relies on an earlier check of the same URL; sharing the HTTP-or-fetch dispatch now repeated in the upload client and the proxy default upstream (also exporting one NULL_BODY_STATUSES and reducing the repeated redirect-status sets); adding to the Breaking line that the proxy no longer follows upstream redirects, even over HTTPS, so upstreamBaseUrl must address the daemon itself; rejecting a bad or unparseable upstreamBaseUrl at startup again through assertAdmittedUpstream, instead of on every request; splitting changes of this size next time, since about 2,929 changed lines over 72 files exceed the 2,500-line limit (no action needed now); deleting the old one-line doc comment left above the new block on forwardedRequest; reusing one direct WebSocket agent and closing it on shutdown, instead of building a new one on each reconnect.

For a follow-up issue, not for this PR: the trust page says provider credentials never go over plain HTTP off loopback, but BrowserStack endpoint overrides (also the session details and app upload ones) reach WebDriver senders and helper fetches that never check the URL, so either check them or name what the rule covers and list WebDriver providers, install-from-source headers and the Limrun SDK client as not covered.

CI is green: every non-skipped check passes, including Body rules (after a rerun) and the iOS and macOS smoke tests. Those smoke tests cover the simulator loopback runner route, not the CoreDevice tunnel. The Limrun forwarded route is a cloud provider path, and its fixture test is acceptable.

Not verified here: no device was available, so it is unconfirmed that devicectl always reports tunnel addresses inside fd00::/8, or that node:http reaches a bracketed ULA host as undici did. No tests were run; the view that the remote trust and proxy credential transport tests would fail without the fix comes from reading base code, and the other new test files were not checked. The mapping of a /health redirect failure to HTTP 500 was not traced and rests on the PR test. The bundle cost of the lazy undici chunk was not measured, though Bundle Size passed. It is only inferred, from the single daemon client lifecycle entry and a search of daemon token senders, that the MCP, SDK tool and Node API surfaces all reach resolveRemoteClientSettings.

Before merge, the fixes above are needed, along with the live Wi-Fi-only iPhone run on the CoreDevice tunnel route.

@thymikee

Copy link
Copy Markdown
Member Author

Re: review of 3e9aeb4. Addressed in 0285cf3. I took the suggested structure: fetchWithCredential(urlOrRequest, init, { subject, send }) checks every URL it sends to, and loadNodeHttpRequester takes the URL and checks it in direct mode. The daemon client keeps its early base-URL check.

  1. localhost: every direct HTTP agent and the companion's socket dispatcher resolve it to loopback addresses only, and refuse with insecure_credential_transport when there is none. The daemon health probe now uses the direct requester too.
  2. Relayed requests: the path must stay on the local base's origin (HTTP and sockets). A request with Authorization, Proxy-Authorization, Cookie or the daemon token follows the rule on each URL and goes direct on loopback. One without credentials still reaches a LAN dev server. Relayed requests to loopback, https or with credentials now follow same-origin redirects only; others are returned to the bridge.
  3. Proxy reasons: every route outside /rpc answers with reason.
  4. Companion failure: the typed error survives and the process exits 1 after unregistering.
  5. Redirects: up to three on the same origin, keeping method and body on 307 and 308.
  6. Encodings: gzip, deflate and br are decoded, and the two content headers dropped.

Non-blocking: taken are the check inside the primitive, the shared dispatch and status sets, the Breaking line about upstream redirects, the duplicate doc comment, and one direct socket agent closed on shutdown. Not taken: rejecting a bad upstreamBaseUrl at startup, because an earlier requirement on this PR asked for a 400 per request instead. The trust page now names what the rule covers and what it does not; the WebDriver follow-up is untouched.

The CoreDevice route has a test of the exact node:http options for a bracketed ULA address, through a loopback stand-in. The live Wi-Fi-only iPhone run is still pending and not done here.

@apex-sentinel-staging

This comment has been minimized.

@apex-sentinel-staging apex-sentinel-staging Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apex Sentinel: 1 new finding on 0aa77a6. The verdict and the full list are in the summary comment.

Comment thread packages/proxy/src/daemon-proxy.ts Resolved
@apex-sentinel-staging

This comment has been minimized.

@thymikee

Copy link
Copy Markdown
Member Author

Live check on a physical iPhone over Wi-Fi only, at 678a0c6.

  • devicectl reports Transport Type localNetwork. The tunnel address rotated between sessions (fdb5:137f:ab9a::1, then fda3:3a9e:368d::1), and both are inside fd00::/8.
  • open com.apple.Preferences, snapshot -i, press on Battery (the page opened), back and a final snapshot -i all exited 0. The phone stayed unlocked throughout.
  • During a snapshot, lsof on the daemon showed [fda3:3a9e:368d::2]:57310 -> [fda3:3a9e:368d::1]:57035 ESTABLISHED. So the runner was reached over plain http on the CoreDevice tunnel interface, not loopback or usbmux.
  • No insecure_credential_transport refusal.

Note: the route and its source aren't logged, so the route evidence comes from the socket check rather than diagnostics.

thymikee and others added 5 commits November 27, 2026 17:55
A remote daemon base URL with a token, the proxy's upstream daemon URL,
the Metro host bridge URL, and the cloud auth base URL are refused before
the first request when they use plain http to a host that is not
loopback (insecure_credential_transport). An upload ticket that would
carry a daemon credential over such a URL takes the legacy upload route.
isLoopbackHostname moves to @agent-device/contracts/daemon-http so the
proxy shares the same matcher.

BREAKING CHANGE: http:// remote URLs to LAN or VPN hosts with a token no
longer work. Use https, or a port forward to 127.0.0.1.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- proxy: every upstream request carries redirect: 'error'; the upstream
  URL rule applies to custom transports too, checked on the first
  exchange; a plain-http upstream goes direct over node:http
- direct connection for credential-bearing plain-http requests, so an
  environment proxy never sees a loopback token (daemon client, remote
  transfers and diagnostics, proxy transports)
- cloud profile discovery checks the URL and follows redirects only on
  the same origin
- metro bridge and the companion worker check each final URL before the
  bearer is sent; a malformed base is refused
- upload tickets must be https or loopback, whatever carries the
  credential
- Limrun API and download URLs and forwarded runner routes are checked
  at send time
- the rule lives in @agent-device/contracts/credential-transport and the
  matcher in @agent-device/contracts/loopback-host; daemon-http stays
  free of error imports; revyl uses the shared matcher

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- declare the host-kit direct-http subpath in the pinned export surface
- new tests use plain node:http servers where test-kit is not a
  dependency, and are named for the module they cover (R84)
- move the new upload-ticket and connect-cloud cases into focused files
  under the max-lines cap; type the fetch stub's input
- the upload cancellation test replaces the direct-http send, the seam
  loopback control requests now use
- pass string URLs to fetch where callers compare them

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Six wire-surface request builders changed only how a request reaches the
daemon: plain-http (loopback) destinations take a direct node:http agent
that bypasses environment proxies, upload control requests to loopback
use node:http instead of fetch, and preflight drops a ticket URL that is
plain http off loopback (the legacy route a released daemon already
serves). Method, path, headers and bodies are unchanged, so the ledger
records the new digests with compatibleChanges entries; the existing
acks for five of them carry the new digest and an appended rationale.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The direct request-diagnostics read sends the daemon token over plain
http to loopback, so it takes the direct agent that bypasses environment
proxies. The integration test now asserts that agent in the request
options instead of a shape without one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
thymikee and others added 8 commits November 27, 2026 17:55
- Revyl sends loopback http through the direct requester, so an
  environment proxy never sees the API key, and refuses a presigned
  upload URL that is neither https nor loopback http
- the Metro companion opens the registered bridge socket only over wss,
  or ws to loopback, and refuses it before the socket opens
- a loopback bridge socket connects directly through undici, because
  the global WebSocket sends its URL to an environment proxy

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The sockets the test servers take on upgrade and connect had no error
listener. Killing the spawned worker with its bridge socket open can
reset it, which Linux CI reported as an unhandled ECONNRESET.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
- proxy: drop a relayed Location whose serialized or decoded path holds
  the upstream token; refuse an upstream base URL with a username or
  password during admission
- Limrun download: refuse the initial URL before the cleanup path, so an
  existing destination file stays
- direct requester: pipe a streamed body instead of buffering it
- bridge socket: only wss, or ws to loopback, by the original scheme
- Apple runner: only the CoreDevice tunnel route may carry the token over
  plain http off loopback, and the docs say so

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
- direct requester: release a streamed body when the exchange fails or
  never starts, including an abort before the request
- Apple runner: treat a reported device address as the CoreDevice tunnel
  only when it is in fd00::/8, and say so in the security docs
- proxy: refuse a username or password before the scheme check, so every
  scheme reports proxy_upstream_userinfo

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
fetchWithCredential applies the transport rule to every URL it sends to,
sends plain http direct and follows only same-origin redirects. The
node:http requester takes the URL and applies the same rule.

- a localhost name connects only to loopback addresses, over HTTP and
  the companion socket
- the companion relays only paths on the local base URL, sends relayed
  credentials under the rule, and fails with the typed refusal
- proxy answers outside /rpc name the admission reason
- Metro bridge and companion POSTs follow same-origin redirects again
- the direct requester decodes gzip, deflate and br as fetch does
- the trust page names what the rule covers

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The test bridge derived a redirect Location from the request URL. It now
names each moved registration path itself.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Client abort and upstreamTimeoutMs end the exchange on the default
plain-http transport, before an answer and during one.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Node keeps loopback destinations off environment proxies, so the direct
node:http client protected against nothing. Remove it and go back to
fetch and node:http as on main. Keep the one rule: a credential never
travels over plain http or ws off loopback, and a redirect never carries
it to another origin.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@thymikee
thymikee force-pushed the t3/reject-insecure-remote-daemon branch from 678a0c6 to 572b141 Compare November 27, 2026 16:59
@thymikee

Copy link
Copy Markdown
Member Author

Re: review of 3e9aeb4. The PR was simplified by maintainer decision at 572b141: the direct node:http client is removed and requests use plain fetch again. Node keeps loopback off env proxies (verified on Node 26 with an off-host proxy), so the client protected against nothing.

Resolved by returning to fetch:

  • localhost resolution: the restriction is dropped. localhost is trusted by name, like 127.0.0.0/8 and ::1, so a resolver that maps it elsewhere is not guarded against.
  • Decompression: direct-http.ts is deleted. fetch decodes, aborts and streams natively, including on the proxy's relay and /health.
  • Metro redirects: bridge, register and unregister use redirect: 'manual' with one helper: same origin, up to three hops, method and body kept on 307 and 308, the rule on each hop.

Kept:

  • Relayed requests: one with Authorization, Proxy-Authorization, Cookie or the daemon token meets the rule and follows same-origin redirects only. Relayed paths stay on the local base.
  • Proxy: every route outside /rpc names the refusal reason. It follows no upstream redirect, and a relayed Location points only at the daemon, without the token.
  • Companion: a transport refusal stays typed and the process exits 1 after unregistering.
  • CoreDevice tunnel: same exception. A unit test shows the runner calling fetch with a bracketed fd00:: host. The live run passed at 678a0c6 and has not been repeated on this head.

Also changed: a refused Limrun download redirect now reports limrun_download_http_error with the 3xx status.

@apex-sentinel-staging

This comment has been minimized.

@apex-sentinel-staging apex-sentinel-staging Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apex Sentinel: 1 new finding on 572b141. The verdict and the full list are in the summary comment.

The companion refused every absolute relayed path, including one on the
local base origin that it served before. Compare the resolved origin only,
which still refuses another origin, absolute or scheme-relative.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@apex-sentinel-staging

This comment has been minimized.

@thymikee

Copy link
Copy Markdown
Member Author

Live check on a physical iPhone over Wi-Fi only, at 071e33c (the simplified fetch-based head).

  • devicectl reports Transport Type localNetwork. The tunnel address fd4f:f141:1a80::1 is inside fd00::/8 and didn't change during the run.
  • open com.apple.Preferences, snapshot -i, press on Battery (the Battery page opened), back, and a final snapshot -i (back on the Settings root) all exited 0.
  • During the run, lsof on the daemon showed [fd4f:f141:1a80::2]:57878 -> [fd4f:f141:1a80::1]:57830 ESTABLISHED. So the runner was reached over plain http through fetch, on the CoreDevice tunnel.
  • No timeouts and no insecure_credential_transport refusal.

The route isn't logged, so the route evidence comes from the socket check.

@thymikee

Copy link
Copy Markdown
Member Author

The code at 071e33c fixes most of the earlier findings on 3e9aeb4, but three redirect and relay problems need changes before merge.

Now fixed: credential headers on relayed HTTP requests are checked for the named headers and other origins are refused, proxy refusals keep their transport reason, a companion transport refusal fails the worker, Metro bridge POSTs follow same-origin redirects for up to three hops, compressed responses are decoded again, and the shared helper now applies the transport rule itself. The Wi-Fi-only iPhone route is covered by the reported live run. The localhost lookup ask is closed by the narrowed scope.

A second independent pass found that a refused Limrun download redirect likely discloses the signed URL. When a signed HTTPS download answers with a 307 to plain HTTP off loopback, nothing is sent to that destination, but the helper returns the 307. The download treats it as an ordinary HTTP error and puts the original URL and its signature in details.url, and a response preview in details.body, which can hold the refused destination or an echoed bearer. At 3e9aeb4 the refusal canceled the body and reported only status and reason. Any redirect that the download receives unfollowed should be handled before httpFailure: cancel the body and report only the status with a fixed reason and message. A test with that 307 should show no URL, Location or body in the error.

A second independent pass found that safe Limrun download chains likely stop after three redirects. With four same-origin HTTPS redirects before a 200, the base branch succeeds and 3e9aeb4 allowed five hops, but the shared hop limit now stops at the fourth 3xx, so the download fails and the destination file is removed. Every download request should keep the base fetch hop limit for chains that pass the same origin and transport checks, while cloud auth keeps its limit of three. A test with the four-redirect chain should end with the downloaded file.

A second independent pass found that the companion's relayed WebSocket can likely send a signed path over plain ws off loopback. With a LAN dev server as localBaseUrl, a relayed path with a handshake ticket in its query stays on the configured origin, so it is admitted, changed to ws and sent. The existing socket check covers only the bridge connection. The relay protocol does not say which paths carry a credential, so every relayed WebSocket URL should pass assertSecureCredentialSocket on its resolved form before the socket is built. A test with a LAN base should show the typed refusal and no connection.

Could relayedLocation be deleted, since the daemon sends no Location and the base header allowlist already relays its 308? Could fetchWithCredential also drop followHttpsOffOrigin and the per-hop re-check? Both are optional follow-ups.

These open threads no longer apply and can be resolved: test server redirect, because the test server sets Location only from a test-supplied value on a fixed path; dropped client signal, because the code it describes is deleted and the default upstream request carries the client signal; same-origin absolute path, because a same-origin absolute path is served again and has a test.

The only check that does not pass is Body rules, which was cancelled. It validates the PR description, no file in the diff is on its route, and it passed on an earlier head after a rerun.

Not verified here: no repository tests were run, and the only local run was an inline Node 26.11.1 experiment on cross-origin redirect header stripping in fetch, so Node 22 and 24 behavior is assumed from undici. The live iPhone run rests on the author's report, which does not say whether pnpm build and node bin/agent-device.mjs were used, and its route evidence comes from lsof because the route is not logged. The source of the artifact URL in remote/artifact-download.ts (unchanged base code) was not traced. The env-proxy claim was not checked and is outside the narrowed scope. It was not checked whether the companion's bridgeScope body carries a secret, which matters only to the optional simplification.

Before merge, the three fixes are needed and Body rules must be rerun and pass.

- Report a Limrun download redirect that is not followed with its status
  only: no URL, Location or body.
- Give Limrun downloads their own 20-hop limit, the one fetch applies.
  Fetch's own follow is not used there: it follows https to plain http.
- Check every relayed Metro WebSocket URL before the socket is built.
- Delete fetchWithCredential. Cloud profile and Metro bridge requests use
  fetch's redirect follow, which drops Authorization on another origin.
  Cloud auth keeps its same-origin loop because a 307 resends the body.
  The companion follows no redirect on relayed requests because custom
  headers survive a cross-origin follow.
- Delete the proxy's relayed Location. The daemon sends none.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@thymikee

Copy link
Copy Markdown
Member Author

Re: review of 071e33c, addressed at 8a7acf1.

Fixed

  • A Limrun download redirect that is not followed now cancels the body and reports only the status, with a fixed message and reason: no URL, Location or body.
  • Limrun downloads have their own limit of 20 hops, as fetch does. They keep a small loop because fetch follows https to plain http, which would send a signed target in cleartext. Cloud auth keeps three.
  • Every relayed WebSocket URL passes assertSecureCredentialSocket before the socket is built. With a LAN http dev server, relayed sockets are now refused.

Simplified

  • relayedLocation and its module are deleted; the daemon sends no Location. The proxy relays a 3xx status with the base header allowlist.
  • fetchWithCredential, followHttpsOffOrigin and the per-hop re-check are deleted.
    • Cloud profile, Metro bridge and companion register/unregister use fetch's follow, which drops Authorization cross-origin. Their non-token bodies can follow a 307 or 308.
    • Cloud auth is back to its same-origin loop from main plus one transport check, because its body would survive a cross-origin 307.
    • Relayed companion requests use redirect: 'manual', because custom headers survive a cross-origin follow.

The redirect experiment output is in the PR description. The changed test files pass; CI is pending.

@blacksmith-sh

This comment has been minimized.

thymikee and others added 3 commits November 28, 2026 11:18
…quests

A followed redirect forwarded the bridge body cross-origin and accepted an
https-to-http hop. redirect: 'manual' turns a redirect into the existing
non-retryable HTTP failure.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@apex-sentinel-staging

Copy link
Copy Markdown

Apex Sentinel · ✅ Approve · review of 98a5c09

Since the review of 071e33c: 1 new · 0 still open · 0 no longer raised

1 finding(s): 1 minor.

🟡 Minor (1)

Where Finding
packages/react-native/src/companion/client-companion-local-relay.ts:27 🆕 Metro bridge relay still serves a LAN http dev server; only the socket is refused

Reviewed with this repository's own Sentinel configuration (e52cd292f50f).

💬 Talking to Sentinel

In a finding's thread, reply with:

Command What it does
@apex-sentinel-staging note <context> Adds context; Sentinel re-checks the cited code
@apex-sentinel-staging pivot <why> Says the finding is wrong; Sentinel re-checks the cited code
@apex-sentinel-staging like Marks the finding as useful
@apex-sentinel-staging dislike <why> Marks it as not useful, so it is not raised again

On this conversation, comment @apex-sentinel-staging review to run a full review once again.

@apex-sentinel-staging apex-sentinel-staging Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apex Sentinel: 1 new finding on 98a5c09. The verdict and the full list are in the summary comment.

@thymikee

Copy link
Copy Markdown
Member Author

The three blocking points from the earlier review of 071e33c are closed at 98a5c09, but five same-origin redirect cases need a fix before merge. The rule: each credentialed request or relayed request below should follow a bounded same-origin redirect with the existing handling, check the initial transport, and never send to another origin. The security docs currently describe the refusal as intended for profile, bridge and registration requests and for dev server redirects, so please confirm that choice if a case should stay as it is, or update those lines with the fix. For each route, a test should show that a same-origin 307 reaches the final endpoint and that an off-origin redirect receives no request.

A second independent pass found that the cloud profile GET likely fails on a same-origin HTTPS 307. The JSON reader rejects the response before it reads the profile, so cloud connect fails. The base code followed the redirect and saved the profile, and the earlier head also supported it. The GET should follow it, keep the initial transport check, and refuse an origin change before sending.

A second independent pass found that the Metro bridge POST likely fails when /api/metro/bridge answers with a same-origin 307 to its canonical path. Prepare then exits without a bridge descriptor, although the earlier review confirmed that this redirect worked. The POST should follow it and keep the method, bearer and body on 307 and 308.

A second independent pass found that companion registration likely treats an ordinary same-origin 307 as a terminal failure. The worker never opens the WebSocket, so the companion never registers. The base worker followed this redirect. The registration POST should do the same and still validate where the bearer goes.

A second independent pass found that companion unregister likely ignores a same-origin 307. Shutdown then clears the local state, and the server registration stays in place without any signal. The unregister POST should reach the final endpoint during the existing shutdown call.

A second independent pass found that the Metro relay likely returns a same-origin 307 and its Location to the bridge, with no bundle bytes. The base worker followed it and returned the 200 with the bundle. The same-origin test case confirms the changed behavior. The relay should follow it, keep the initial credential transport check, and return any off-origin redirect unfollowed.

Not blocking: these notes can be taken or left: if refusing every redirect on the cloud profile GET, bridge POST and companion register or unregister calls is kept on purpose, the "Breaking:" paragraph could say that same-origin redirects now fail too (the PR table already names this), and if the base behavior is preferred instead, fetch's default redirect: "follow" is the other option for those calls.

One open thread on relayed HTTP does not apply and can be resolved: a request without the listed credential headers carries no header credential and stays pinned to the local base origin, so refusing all LAN HTTP would break Metro on a LAN IP for no security gain.

All 26 checks pass, and the required evidence is in place. The five redirect cases are what remains before merge.

Not verified here: no tests were run, and regression test validity was judged only by reading the 071e33c code against each new test. Whether any real cloud or bridge deployment sends a same-origin redirect on the profile, bridge or register paths was not checked, so the real-world impact is not measured. The 20-redirect limit in undici was not measured on Node 22 or 24; it comes from the fetch spec and the PR author's note. The Apple runner route is unchanged since the earlier review, and its live evidence is still the author's report on 678a0c6, accepted at 071e33c.

@thymikee

Copy link
Copy Markdown
Member Author

Closing in favour of a smaller design, decided with the maintainer and recorded as ADR 0041 (credential transport). The rule: before sending a first-party credential to an operator-configured URL, require https or loopback http. 0.21.x warns, 0.22 refuses, and AGENT_DEVICE_ALLOW_INSECURE_TRANSPORT=1 is the override. It checks the daemon, cloud, Metro bridge and proxy upstream URLs and upload tickets. There is no redirect handling, no Metro relay rules and no provider URL checks. The rule helper, loopback classifier and focused tests from this branch are reused in the new PR. Thanks to everyone who reviewed it; the review rounds are what showed the scope had to shrink.

@thymikee thymikee closed this Nov 28, 2026
@thymikee
thymikee deleted the t3/reject-insecure-remote-daemon branch November 28, 2026 13:00
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.

2 participants