Skip to content

fix(daemon): refuse remote web commands that cannot enforce public-network-only - #5348

Open
thymikee wants to merge 8 commits into
0.22from
fix/remote-web-refusal-022
Open

thymikee wants to merge 8 commits into
0.22from
fix/remote-web-refusal-022

Conversation

@thymikee

@thymikee thymikee commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

Summary

A remote tenant request (internal publicNetworkOnly) cannot use the managed web browser on the daemon host, because that browser could reach the host's private network. A remote command that would use it is refused with UNSUPPORTED_OPERATION, reason REMOTE_WEB_PUBLIC_NETWORK_UNENFORCED, retriable: false. close stays allowed for cleanup. Local web sessions are unaffected.

The dispatch seam (runAdmitted) checks an existing session's device before composite resource admission, lease admission, the session journal and any handler. Device admission checks devices resolved later, such as a fresh open. The early check skips commands that do not use the session device: commands that ignore the session lease (devices, session_list, lease operations), and the new registry field detachedFromSessionDevice (artifacts, doctor --remote). capabilities and apps with an explicit device selector keep explicit-device precedence. This replaces the web part of #5272 and #5343.

Before / after

  • Remote snapshot on an existing web session: base runs it on the host browser; head refuses with REMOTE_WEB_PUBLIC_NETWORK_UNENFORCED before any handler.
  • Remote devices with a web session open: base and head list devices.
  • Local web snapshot: no observable change.

Validation

Head e43a25e; CI pending.
pnpm vitest run packages/daemon/src/server/__tests__/request-router-web-sessions.test.ts: 30 passed. Removing the detached check fails 4 rows; removing the explicit-selector check fails 2; breaking the doctor field fails 1.
Production delta versus 0.22: about +53 lines. request-execution-scope.ts is 999 lines, under the 1000 cap.
Residual risk: no platform-web launch guard. publicNetworkOnly does not reach platform-web on 0.22.

@github-actions

github-actions Bot commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Size Report

Metric Base Current Diff
Installed (including dependencies) 5.29 MB 5.29 MB +806 B
Package (unpacked) 5.28 MB 5.29 MB +806 B
Package (download) 1.62 MB 1.62 MB +292 B

Startup median (7 runs, lower is better):

Scenario Base Current Diff
CLI --version 17.1 ms 18.7 ms +1.6 ms
CLI --help 27.9 ms 28.9 ms +1.1 ms

@apex-sentinel-staging

This comment has been minimized.

@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 46ec0c3. The verdict and the full list are in the summary comment.

@thymikee
thymikee force-pushed the fix/remote-web-refusal-022 branch from 46ec0c3 to 7d6c9cd Compare December 3, 2026 09:14
@apex-sentinel-staging

This comment has been minimized.

@thymikee
thymikee marked this pull request as ready for review December 3, 2026 10:11

@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 6 files

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

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

Comment thread website/docs/docs/remote-proxy.md Resolved
@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 76f5511. The verdict and the full list are in the summary comment.

@thymikee

thymikee commented Dec 3, 2026

Copy link
Copy Markdown
Member Author

The code at cc563e6 does not yet hold the public-network-only rule on every route that reaches an existing web session. A remote caller can still drive the host browser through replay.

An authenticated public-network-only caller can send replay with an inline script against a named, locally opened web session. The child step is refused, but the failure path still captures the session for the divergence report: session-replay-divergence.ts:103 runs the capture, the fact probe throws the web refusal, and observation-capture.ts:77 turns it into a retryable failure. The empty binding makes session-replay-command.ts:431 fall back to the legacy interactor capture, which calls the web provider without admission. Target verification takes the same capture path before dispatch. The caller gets the page accessibility tree in the divergence response instead of a refusal, and the new sentences at remote-proxy.md:161 and :412 promise a refusal. Please make this rule hold: a public-network-only request on an existing session whose device platform is web, and whose command is not close, is refused before any handler runs. Device admission still covers devices resolved later, such as a fresh open. Please add a router test where a remote replay of a one-step script on an existing web session returns the typed refusal and a fake interactor records zero snapshot calls.

A second independent pass found that record stop has the same gap. A proxy client bound to the same session and tenant can stop a live daemon-owned recording on an unleased web session (record-runtime.ts:519). The stored handle stops the managed browser recorder without a runtime bind, and the reply can publish the recording at :469. The rule above covers it if it is enforced on the resolved session before the record plan, manifest checks or handle use. Close teardown can stay on its cleanup path.

A second independent pass found that reopen renews the device claim before it refuses. A proxy caller reopening an unleased local web session with an HTTP(S) target writes a fresh claim timestamp (session-open.ts:300, device-claims.ts:758) before the refusal at :315, so a refused reopen keeps the local claim alive. The same early check should run before the claim write.

A second independent pass found that a refused snapshot is not side-effect free. The journal starts before runtime inspection refuses the request (request-execution-scope.ts:600), and :715 still writes lastActivityAtMs, which the idle reaper reads (session-idle-expiry.ts:66). A refused remote snapshot can keep an idle claimed web session alive. The refusal should come before the journal starts and before the request counts as activity.

A second independent pass found that a duration-only wait skips admission. On a reachable local web session it returns success and records a wait action (wait-runtime.ts:58, selector-recording.ts:155). A batch wait step takes the same branch. The same session-level refusal should apply before that branch.

Same size or smaller: could one exported assertion, for example assertRemoteWebDeviceAdmitted(req, device) in remote-host-input-policy.ts, cover all of this? It would be called at two sites: in runAdmitted on existingRef.session.device right after request-execution-scope.ts:631, before composite resource admission and lease admission, and inside withRemoteWebAdmission for devices resolved later. That would close replay, record stop, trace, wait and the bookkeeping order without a guard in each handler. remote-host-input-policy.ts is at 999 lines, so the file needs to stay under 1000.

Not blocking, and each can be taken or left: record stop, trace and runtime reads are covered by the session-level check above; a bounded batch with a web audio probe step meets the composite resource refusal before the web refusal, which the earlier check order fixes; sensitive-fill redaction can rewrite part of details.reason when the caller's own marked text overlaps it, which could go in a follow-up issue; the open help, web topic and commands.md carry no remote caveat, and remote-proxy.md does not cover auth-hook daemons or an SDK embedder's webProvider behind a remote daemon; and REMOTE_HOST_INPUT_REASONS now holds a reason that is not about host input, so a rename such as REMOTE_DAEMON_REASONS would fit, and the PR body line count (997) is stale against the 999-line file.

The earlier inline thread on remote-proxy.md:161 still applies, because that sentence is false for replay until the fix lands: #5348 (comment). No lower-priority threads still apply. These look fixed at cc563e6 and can be resolved: the predecessor guard wrapper in request-execution-scope.ts (#5348 (comment)), the reason name REMOTE_WEB_PUBLIC_NETWORK_UNENFORCED (#5348 (comment)), the experiments doc naming #5348 (#5348 (comment)), the retriable: false assertions (#5348 (comment)), and the withRemoteWebAdmission references in the experiments doc (#5348 (comment)).

Not verified here: any behavior by running it. No test was run, and the replay route was traced by reading code. Not verified here: whether the web interactor without a request provider snapshots the session's own browser or starts the default one; either way it drives a managed browser on the daemon host. Not verified here: whether tenant namespacing stops an auth-hook tenant from naming an unleased local session in production, which the PR's own existing-session test assumes. Not verified here: every handler that skips device binding; only replay, record stop, trace, runtime, journal and bounded audio were checked.

CI is pending: 17 checks pass at cc563e6, and one other check is still queued. It is a review check, not a test job. No conflicts are known. Before merge, a remote request on an existing web session needs to be refused before any handler runs, with the router test that shows zero snapshot calls on remote replay.

@apex-sentinel-staging

This comment has been minimized.

… dispatch seam

assertRemoteWebDeviceAdmitted now runs in runAdmitted on the resolved session device, before
composite resource admission, lease admission, the journal, and any handler. This closes replay
divergence capture, record stop, reopen claim renewal, duration wait, and the idle activity stamp.
@thymikee

thymikee commented Dec 3, 2026

Copy link
Copy Markdown
Member Author

Answers to the review at 30cd7eb:

  1. Added exported assertRemoteWebDeviceAdmitted(req, device) in remote-host-input-policy.ts (now 242 lines); withRemoteWebAdmission calls it, and runAdmitted calls it on existingRef.session.device right after existingRef, before composite resource admission and admitLease.
  2. Every request, nested batch and replay steps included, reaches handlers only through runLocked/runAdmitted -> prepareLockedRequestScope -> bindSession, so replay capture, record stop, reopen claim renewal, the journal start and idle stamp, and duration wait are all refused first; the only earlier return is the Android-only detached observation.
  3. Added a dispatch-seam test in request-router-web-sessions.test.ts: remote replay of a one-step script on an existing web session returns the typed refusal with zero fake-interactor snapshot calls; with the runAdmitted call removed it fails (snapshot called 1 time).

@apex-sentinel-staging

This comment has been minimized.

@thymikee

thymikee commented Dec 3, 2026

Copy link
Copy Markdown
Member Author

The five problems from the earlier review (#5348 (comment)) are fixed at 30cd7eb: replay capture, record stop, reopen claim renewal, journal and idle stamp, and duration wait are all refused by the new check in request-execution-scope.ts:633, and the requested router replay test is present. A second independent pass found three regressions in that same check: it refuses requests that never use a browser.

A second independent pass found that an authenticated remote caller on a token-authenticated daemon without tenant isolation now gets REMOTE_WEB_PUBLIC_NETWORK_UNENFORCED from devices and session_list when the session address is held by an unleased local web session. Both commands are marked ignoresSessionLease (request-admission.ts:161), so the lookup still returns the unleased web ref. On the base, devices returned inventory and session_list returned the visibility-filtered list (inventory.ts:95, :118, :161). The owner of a retained leased web session who sends its lease ID also loses doctor --remote, which returned connection and session checks before any device probe (session-doctor.ts:69, :85). The rule: the web admission check applies only to requests that use a web session. Route devices and session_list without a browser session binding, and let the remote-only doctor branch read authorized session metadata without binding the browser.

A second independent pass found that lease operations and artifact listing hit the same collision. A remote caller with a valid daemon token who uses an address held by an unleased web session cannot allocate a native-device lease, or heartbeat or release one it already holds. These commands ignore the session's lease (registry.ts:168, :186, :205) and act on the caller's lease scope (lease.ts:101, :120, :213, :402). artifacts listing of already published daemon artifacts is refused too (lease.ts:103, :509, :537). The rule: lease lifecycle operations and artifact metadata reads stay detached from the addressed browser and keep their own authorization. Keep the early refusal for browser work and the later device-admission guard.

A second independent pass found that an explicit device selector loses its precedence. An authenticated remote caller sends capabilities or apps with an explicit Android serial and a session address held by an unleased web session. The declarations give explicit device identity priority (registry.ts:310, :360), and the base selects the Android target (inventory.ts:463, session-device-resolution.ts:62). At this head the web session's device triggers the refusal first. The rule: the early check honors the existing explicit-device precedence, the runtime guard applies to the device actually selected, and the early refusal stays when the command uses the existing web device.

For validation, a router test per route is enough: an unleased web session at the address, then devices, session_list, a lease allocate, capabilities with an Android serial, and doctor --remote with a lease ID. Each must reach its handler and not return REMOTE_WEB_PUBLIC_NETWORK_UNENFORCED. A web command at the same address must still be refused.

The six earlier inline threads no longer apply, because each is fixed at this head, and the author can resolve them: remote-proxy.md now says remote web browser use is refused (#5348 (comment)); the predecessor guard wrapper is gone (#5348 (comment)); the reason is now REMOTE_WEB_PUBLIC_NETWORK_UNENFORCED (#5348 (comment)); the experiments doc status names #5348 (#5348 (comment)); the router tests assert retriable: false (#5348 (comment)); and assertRemoteWebDeviceAdmitted exists as the experiments doc says (#5348 (comment)). No high-priority or lower-priority threads still apply.

The checks at 30cd7eb show 18 passing and one cancelled, "Body rules", which lints PR text and not code, so it is likely unrelated. There are no conflicts. Before merge, the three regressions above need a fix and the router tests described above need to pass in CI. Not verified here: that the replay test fails without the new check, and whether an auth-hook tenant can name an unleased local web session in production. No test was run for this review.

… use the session device

Commands that ignore the session lease (devices, session_list, lease operations) already declare
that they do not use the session device. artifacts and doctor --remote now declare it with
detachedFromSessionDevice. capabilities and apps with an explicit device selector keep
explicit-device precedence. The dispatch seam checks only the device the command uses.
@thymikee

thymikee commented Dec 3, 2026

Copy link
Copy Markdown
Member Author

Addressed in e43a25e:

  • devices, session_list, doctor --remote: the early check now skips commands that ignore the session lease, and doctor declares detachedFromSessionDevice when --remote is set, so all three reach their handlers.
  • Lease allocate/heartbeat/release and artifacts: lease operations already ignore the session lease, and artifacts declares detachedFromSessionDevice, so they stay detached from the addressed web session.
  • capabilities/apps with an explicit selector: the early check honors preferExplicitDeviceOverExistingSession and skips when the selector names a different device; device admission still checks the selected device, and capabilities without a selector is still refused.
  • Tests: one table test at the dispatch seam covers each route above plus refused rows (capabilities without a selector, non-remote doctor); removing each gate turns its rows red.

@apex-sentinel-staging

Copy link
Copy Markdown

Apex Sentinel · ✅ Approve · review of 52126c9

Since the review of 30cd7eb: 0 new · 0 still open · 0 no longer raised

No open findings.

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

💬 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.

@thymikee

thymikee commented Dec 3, 2026

Copy link
Copy Markdown
Member Author

The three findings from the earlier review are fixed at 52126c9, and the new changes add no problems. The early check now lives at remote-host-input-policy.ts:240 and runs from request-execution-scope.ts:632. The refusal reason is REMOTE_WEB_PUBLIC_NETWORK_UNENFORCED with retriable: false, and the docs now match.

All six open inline threads are fixed at this head, so the author can resolve them: predecessor guard, reason code, remote-proxy.md, experiments doc status, retriable in tests, and assertRemoteWebDeviceAdmitted.

CI is green at 52126c9: 18 checks, none failing. Not verified here: tests were not run locally, and the red-without-fix result for each test row is inferred from reading the early check at 30cd7eb, not from a mutation run. release_materialized_paths (session-operations.ts:341) skips the early check. It only releases on-disk paths and never binds a device, and any device binding would still pass withRemoteWebAdmission, so no route to the browser was found. Nothing else stands in the way of maintainer review.

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Dec 3, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-human Valid work that needs human implementation, judgment, or maintainer merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant