From abdc57bd68d13758b8ef4154683079a07571370d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Thu, 3 Dec 2026 08:29:37 +0100 Subject: [PATCH 1/8] fix(daemon): refuse remote web commands that cannot enforce public-network-only --- .../request-router-web-sessions.test.ts | 82 +++++++++++++++++++ .../src/server/remote-host-input-policy.ts | 18 ++++ .../src/server/request-execution-scope.ts | 11 ++- website/docs/docs/error-reasons.md | 1 + website/docs/docs/remote-proxy.md | 2 + 5 files changed, 112 insertions(+), 2 deletions(-) diff --git a/packages/daemon/src/server/__tests__/request-router-web-sessions.test.ts b/packages/daemon/src/server/__tests__/request-router-web-sessions.test.ts index 4d79e2c4ade..0a80c024ccb 100644 --- a/packages/daemon/src/server/__tests__/request-router-web-sessions.test.ts +++ b/packages/daemon/src/server/__tests__/request-router-web-sessions.test.ts @@ -167,6 +167,88 @@ function openWebRequest(session: string): DaemonRequest { }; } +test('remote web open is refused before a browser runtime binds', async () => { + mockResolveTargetDevice.mockImplementation(webSessionResolution); + const store = makeSessionStore('agent-device-remote-web-denied-'); + let binds = 0; + const handler = createOpenHandler(store, new LeaseRegistry(), { + ...lifecycleDeviceRuntimeGateway, + bind: async (request) => { + binds += 1; + return await lifecycleDeviceRuntimeGateway.bind(request); + }, + }); + + const result = await handler({ + ...openWebRequest('remote-web'), + internal: { publicNetworkOnly: true }, + }); + expect(result).toMatchObject({ + ok: false, + error: { + code: 'UNSUPPORTED_OPERATION', + details: { reason: 'remote_web_public_network_unenforced' }, + }, + }); + expect(binds).toBe(0); + expect(store.toArray()).toEqual([]); +}); + +test('remote requests cannot use an existing web session', async () => { + mockResolveTargetDevice.mockImplementation(webSessionResolution); + const store = makeSessionStore('agent-device-remote-web-existing-'); + store.publish('existing-web', makeSession('existing-web', { device: WEB_DESKTOP_DEVICE })); + let binds = 0; + const handler = createOpenHandler(store, new LeaseRegistry(), { + ...lifecycleDeviceRuntimeGateway, + bind: async (request) => { + binds += 1; + return await lifecycleDeviceRuntimeGateway.bind(request); + }, + }); + + const result = await handler({ + token: 'test-token', + session: 'existing-web', + command: 'snapshot', + positionals: [], + flags: {}, + meta: { requestId: 'remote-existing-web', sessionExplicit: true }, + internal: { publicNetworkOnly: true }, + }); + expect(result).toMatchObject({ + ok: false, + error: { details: { reason: 'remote_web_public_network_unenforced' } }, + }); + expect(binds).toBe(0); +}); + +test('remote close can release an existing web session', async () => { + mockResolveTargetDevice.mockImplementation(webSessionResolution); + const store = makeSessionStore('agent-device-remote-web-close-'); + store.publish('existing-web', makeSession('existing-web', { device: WEB_DESKTOP_DEVICE })); + const handler = createOpenHandler(store); + + const result = await handler({ + token: 'test-token', + session: 'existing-web', + command: 'close', + positionals: [], + flags: {}, + meta: { requestId: 'remote-close-web', sessionExplicit: true }, + internal: { publicNetworkOnly: true }, + }); + expect(result).toMatchObject({ ok: true }); + expect(store.get('existing-web')).toBeUndefined(); +}); + +test('local web open is unaffected by the remote web refusal', async () => { + mockResolveTargetDevice.mockImplementation(webSessionResolution); + const store = makeSessionStore('agent-device-local-web-open-'); + const result = await createOpenHandler(store)(openWebRequest('local-web')); + expect(result).toMatchObject({ ok: true }); +}); + test('implicit web sessions isolate workspaces and retain their device on follow-up requests', async () => { mockResolveTargetDevice.mockImplementation(webSessionResolution); const claimsDir = mkdtempForTestSync('agent-device-web-workspace-claims-'); diff --git a/packages/daemon/src/server/remote-host-input-policy.ts b/packages/daemon/src/server/remote-host-input-policy.ts index 623de0ff2ba..9cf920aa10a 100644 --- a/packages/daemon/src/server/remote-host-input-policy.ts +++ b/packages/daemon/src/server/remote-host-input-policy.ts @@ -1,3 +1,4 @@ +import type { DeviceInfo } from '@agent-device/kernel/device'; import { AppError, type ReasonTable } from '@agent-device/kernel/errors'; import { INTERNAL_COMMANDS } from '@agent-device/command-registry/catalog'; import { validateAndNormalizeBatchSteps } from '@agent-device/command-registry/batch'; @@ -9,6 +10,9 @@ const REMOTE_HOST_INPUT_REASONS = { // A remote request supplied a host path or other host input (`details.field`), which a remote // daemon refuses. denied: { reason: 'REMOTE_HOST_INPUT_DENIED' }, + // A remote request targeted the managed web browser, which cannot enforce a public-network-only + // policy on the daemon host. + webPublicNetworkUnenforced: { reason: 'remote_web_public_network_unenforced' }, } as const satisfies ReasonTable<'remote daemon'>; const HOST_PATH_FIELDS = [ @@ -215,3 +219,17 @@ function remoteHostInputDenied(field: string, hint = REMOTE_HOST_INPUT_HINT): Ap hint, }); } + +export function assertRemoteWebDeviceAdmitted(request: DaemonRequest, device: DeviceInfo): void { + if ( + !request.internal?.publicNetworkOnly || + device.platform !== 'web' || + request.command === 'close' + ) + return; + throw new AppError( + 'UNSUPPORTED_OPERATION', + 'The managed web browser cannot enforce public-network-only access for remote requests.', + { reason: REMOTE_HOST_INPUT_REASONS.webPublicNetworkUnenforced.reason, retriable: false }, + ); +} diff --git a/packages/daemon/src/server/request-execution-scope.ts b/packages/daemon/src/server/request-execution-scope.ts index 5df273517d2..d1fe4139d1b 100644 --- a/packages/daemon/src/server/request-execution-scope.ts +++ b/packages/daemon/src/server/request-execution-scope.ts @@ -1,6 +1,9 @@ import { LEASE_REASONS } from '@agent-device/contracts/lease-scope'; import { thrownBeforeDispatch } from '../execution/request-dispatch-disclosure.ts'; -import { restrictRemoteHostInputs } from './remote-host-input-policy.ts'; +import { + assertRemoteWebDeviceAdmitted, + restrictRemoteHostInputs, +} from './remote-host-input-policy.ts'; import type { EnvMap, HostEnvironment } from '@agent-device/kernel/source-value'; import type { DeviceInfo } from '@agent-device/kernel/device'; import { heldKeyedLockKeys } from '@agent-device/kernel/keyed-lock'; @@ -811,8 +814,12 @@ function createRequestDeviceAccess(params: { dispatchLedger: params.dispatchLedger, admitDeviceClaim: claimAdmission.admit, admitDevice: - params.admitDevicePin || daemonPolicy || claimPolicy === 'require-owner' + params.admitDevicePin || + daemonPolicy || + claimPolicy === 'require-owner' || + params.req.internal?.publicNetworkOnly ? (device) => { + assertRemoteWebDeviceAdmitted(params.req, device); params.admitDevicePin?.(device); if (daemonPolicy) { assertDaemonPolicyAdmitsDevice(daemonPolicy, device); diff --git a/website/docs/docs/error-reasons.md b/website/docs/docs/error-reasons.md index 33c3d3f084f..6144f2c572b 100644 --- a/website/docs/docs/error-reasons.md +++ b/website/docs/docs/error-reasons.md @@ -1111,6 +1111,7 @@ These reasons can come from more than one command. | Reason | Meaning | | --- | --- | | `REMOTE_HOST_INPUT_DENIED` | A remote request supplied a host path or other host input (`details.field`), which a remote daemon refuses. | +| `remote_web_public_network_unenforced` | A remote request targeted the managed web browser, which cannot enforce a public-network-only policy on the daemon host. | ### Remote transfer diff --git a/website/docs/docs/remote-proxy.md b/website/docs/docs/remote-proxy.md index bea0453832d..575eca7b38d 100644 --- a/website/docs/docs/remote-proxy.md +++ b/website/docs/docs/remote-proxy.md @@ -409,6 +409,8 @@ daemons omit it. {"ok":true,"service":"agent-device-proxy","version":"0.21.39-dev","rpcProtocolVersion":3,"instanceId":"5f0c2d7e-8a41-4b7e-9c3a-2e6d1f4b8a90","hostArch":"arm64","upstream":{"ok":true,"service":"agent-device-daemon","version":"0.21.39-dev","rpcProtocolVersion":3,"instanceId":"b3e9a6c1-4d2f-4f8e-a0b7-7c5d9e1f2a34","hostArch":"arm64"}} ``` +A remote request cannot use the managed web browser on the daemon host, because that browser could reach the host's private network. Every remote web command except `close` returns `UNSUPPORTED_OPERATION` with `details.reason: "remote_web_public_network_unenforced"`. + ## Clean up Run `agent-device disconnect` when you finish the remote session. Stop the tunnel and the `agent-device proxy` process only when the host should stop accepting remote clients. Restarting the proxy generates a fresh token unless you supplied `--daemon-auth-token` explicitly. From 7d6c9cdc3c6c476b2ef420ce56c95fc6a20a08f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Thu, 3 Dec 2026 09:08:33 +0100 Subject: [PATCH 2/8] fix(daemon): move remote web admission into the input policy --- .../src/server/remote-host-input-policy.ts | 31 ++++++++++--------- .../src/server/request-execution-scope.ts | 14 +++------ website/docs/docs/error-reasons.md | 2 +- website/docs/docs/remote-proxy.md | 2 +- 4 files changed, 23 insertions(+), 26 deletions(-) diff --git a/packages/daemon/src/server/remote-host-input-policy.ts b/packages/daemon/src/server/remote-host-input-policy.ts index 9cf920aa10a..382233415c3 100644 --- a/packages/daemon/src/server/remote-host-input-policy.ts +++ b/packages/daemon/src/server/remote-host-input-policy.ts @@ -10,8 +10,8 @@ const REMOTE_HOST_INPUT_REASONS = { // A remote request supplied a host path or other host input (`details.field`), which a remote // daemon refuses. denied: { reason: 'REMOTE_HOST_INPUT_DENIED' }, - // A remote request targeted the managed web browser, which cannot enforce a public-network-only - // policy on the daemon host. + // A remote request tried to use the managed browser on the daemon host, which cannot enforce a + // public-network-only policy. webPublicNetworkUnenforced: { reason: 'remote_web_public_network_unenforced' }, } as const satisfies ReasonTable<'remote daemon'>; @@ -220,16 +220,19 @@ function remoteHostInputDenied(field: string, hint = REMOTE_HOST_INPUT_HINT): Ap }); } -export function assertRemoteWebDeviceAdmitted(request: DaemonRequest, device: DeviceInfo): void { - if ( - !request.internal?.publicNetworkOnly || - device.platform !== 'web' || - request.command === 'close' - ) - return; - throw new AppError( - 'UNSUPPORTED_OPERATION', - 'The managed web browser cannot enforce public-network-only access for remote requests.', - { reason: REMOTE_HOST_INPUT_REASONS.webPublicNetworkUnenforced.reason, retriable: false }, - ); +export function withRemoteWebAdmission( + request: DaemonRequest, + admitPin: ((device: DeviceInfo) => void) | undefined, +): ((device: DeviceInfo) => void) | undefined { + if (!request.internal?.publicNetworkOnly) return admitPin; + return (device) => { + if (device.platform === 'web' && request.command !== 'close') { + throw new AppError( + 'UNSUPPORTED_OPERATION', + 'The managed web browser cannot enforce public-network-only access for remote requests.', + { reason: REMOTE_HOST_INPUT_REASONS.webPublicNetworkUnenforced.reason, retriable: false }, + ); + } + admitPin?.(device); + }; } diff --git a/packages/daemon/src/server/request-execution-scope.ts b/packages/daemon/src/server/request-execution-scope.ts index d1fe4139d1b..640af7b58bc 100644 --- a/packages/daemon/src/server/request-execution-scope.ts +++ b/packages/daemon/src/server/request-execution-scope.ts @@ -1,9 +1,6 @@ import { LEASE_REASONS } from '@agent-device/contracts/lease-scope'; import { thrownBeforeDispatch } from '../execution/request-dispatch-disclosure.ts'; -import { - assertRemoteWebDeviceAdmitted, - restrictRemoteHostInputs, -} from './remote-host-input-policy.ts'; +import { restrictRemoteHostInputs, withRemoteWebAdmission } from './remote-host-input-policy.ts'; import type { EnvMap, HostEnvironment } from '@agent-device/kernel/source-value'; import type { DeviceInfo } from '@agent-device/kernel/device'; import { heldKeyedLockKeys } from '@agent-device/kernel/keyed-lock'; @@ -806,6 +803,7 @@ function createRequestDeviceAccess(params: { trackDisposal: params.trackClaimRecoveryDisposal, }), }); + const admitPin = withRemoteWebAdmission(params.req, params.admitDevicePin); return { claimAdmission, runtimeBindings: createRequestRuntimeBindings({ @@ -814,13 +812,9 @@ function createRequestDeviceAccess(params: { dispatchLedger: params.dispatchLedger, admitDeviceClaim: claimAdmission.admit, admitDevice: - params.admitDevicePin || - daemonPolicy || - claimPolicy === 'require-owner' || - params.req.internal?.publicNetworkOnly + admitPin || daemonPolicy || claimPolicy === 'require-owner' ? (device) => { - assertRemoteWebDeviceAdmitted(params.req, device); - params.admitDevicePin?.(device); + admitPin?.(device); if (daemonPolicy) { assertDaemonPolicyAdmitsDevice(daemonPolicy, device); } diff --git a/website/docs/docs/error-reasons.md b/website/docs/docs/error-reasons.md index 6144f2c572b..26010845577 100644 --- a/website/docs/docs/error-reasons.md +++ b/website/docs/docs/error-reasons.md @@ -1111,7 +1111,7 @@ These reasons can come from more than one command. | Reason | Meaning | | --- | --- | | `REMOTE_HOST_INPUT_DENIED` | A remote request supplied a host path or other host input (`details.field`), which a remote daemon refuses. | -| `remote_web_public_network_unenforced` | A remote request targeted the managed web browser, which cannot enforce a public-network-only policy on the daemon host. | +| `remote_web_public_network_unenforced` | A remote request tried to use the managed browser on the daemon host, which cannot enforce a public-network-only policy. | ### Remote transfer diff --git a/website/docs/docs/remote-proxy.md b/website/docs/docs/remote-proxy.md index 575eca7b38d..5d77116f5c4 100644 --- a/website/docs/docs/remote-proxy.md +++ b/website/docs/docs/remote-proxy.md @@ -409,7 +409,7 @@ daemons omit it. {"ok":true,"service":"agent-device-proxy","version":"0.21.39-dev","rpcProtocolVersion":3,"instanceId":"5f0c2d7e-8a41-4b7e-9c3a-2e6d1f4b8a90","hostArch":"arm64","upstream":{"ok":true,"service":"agent-device-daemon","version":"0.21.39-dev","rpcProtocolVersion":3,"instanceId":"b3e9a6c1-4d2f-4f8e-a0b7-7c5d9e1f2a34","hostArch":"arm64"}} ``` -A remote request cannot use the managed web browser on the daemon host, because that browser could reach the host's private network. Every remote web command except `close` returns `UNSUPPORTED_OPERATION` with `details.reason: "remote_web_public_network_unenforced"`. +A remote request cannot use the managed browser on the daemon host, because that browser could reach the host's private network. A remote command that would use it returns `UNSUPPORTED_OPERATION` with `details.reason: "remote_web_public_network_unenforced"`. `close` stays allowed. Automating public sites through a remote managed browser is intentionally disabled. ## Clean up From db966c59549dca9d8c5808ca2071ac2de18d4190 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Thu, 3 Dec 2026 10:57:34 +0100 Subject: [PATCH 3/8] fix(daemon): keep the remote web refusal out of the shared device admission guard --- docs/experiments/remote-web-public-network-confinement.md | 2 +- .../server/__tests__/request-router-web-sessions.test.ts | 4 ++-- packages/daemon/src/server/remote-host-input-policy.ts | 2 +- packages/daemon/src/server/request-execution-scope.ts | 6 ++++-- website/docs/docs/error-reasons.md | 2 +- website/docs/docs/remote-proxy.md | 2 +- 6 files changed, 10 insertions(+), 8 deletions(-) diff --git a/docs/experiments/remote-web-public-network-confinement.md b/docs/experiments/remote-web-public-network-confinement.md index 9306f3fe33d..dbb5f4ee51e 100644 --- a/docs/experiments/remote-web-public-network-confinement.md +++ b/docs/experiments/remote-web-public-network-confinement.md @@ -3,7 +3,7 @@ ## Status Design proposal. [#5243](https://github.com/callstack/agent-device/pull/5243) introduces -`remote_web_public_network_unenforced` for remote tenant web commands. +`REMOTE_WEB_PUBLIC_NETWORK_UNENFORCED` for remote tenant web commands. The refusal is absent from the `main` revision that this proposal targets. Land #5243 before landing the confinement implementation. Keep its refusal until the final phase. diff --git a/packages/daemon/src/server/__tests__/request-router-web-sessions.test.ts b/packages/daemon/src/server/__tests__/request-router-web-sessions.test.ts index 0a80c024ccb..ac345404314 100644 --- a/packages/daemon/src/server/__tests__/request-router-web-sessions.test.ts +++ b/packages/daemon/src/server/__tests__/request-router-web-sessions.test.ts @@ -187,7 +187,7 @@ test('remote web open is refused before a browser runtime binds', async () => { ok: false, error: { code: 'UNSUPPORTED_OPERATION', - details: { reason: 'remote_web_public_network_unenforced' }, + details: { reason: 'REMOTE_WEB_PUBLIC_NETWORK_UNENFORCED' }, }, }); expect(binds).toBe(0); @@ -218,7 +218,7 @@ test('remote requests cannot use an existing web session', async () => { }); expect(result).toMatchObject({ ok: false, - error: { details: { reason: 'remote_web_public_network_unenforced' } }, + error: { details: { reason: 'REMOTE_WEB_PUBLIC_NETWORK_UNENFORCED' } }, }); expect(binds).toBe(0); }); diff --git a/packages/daemon/src/server/remote-host-input-policy.ts b/packages/daemon/src/server/remote-host-input-policy.ts index 382233415c3..9c0b3110dbd 100644 --- a/packages/daemon/src/server/remote-host-input-policy.ts +++ b/packages/daemon/src/server/remote-host-input-policy.ts @@ -12,7 +12,7 @@ const REMOTE_HOST_INPUT_REASONS = { denied: { reason: 'REMOTE_HOST_INPUT_DENIED' }, // A remote request tried to use the managed browser on the daemon host, which cannot enforce a // public-network-only policy. - webPublicNetworkUnenforced: { reason: 'remote_web_public_network_unenforced' }, + webPublicNetworkUnenforced: { reason: 'REMOTE_WEB_PUBLIC_NETWORK_UNENFORCED' }, } as const satisfies ReasonTable<'remote daemon'>; const HOST_PATH_FIELDS = [ diff --git a/packages/daemon/src/server/request-execution-scope.ts b/packages/daemon/src/server/request-execution-scope.ts index 640af7b58bc..d438c4b5821 100644 --- a/packages/daemon/src/server/request-execution-scope.ts +++ b/packages/daemon/src/server/request-execution-scope.ts @@ -803,7 +803,7 @@ function createRequestDeviceAccess(params: { trackDisposal: params.trackClaimRecoveryDisposal, }), }); - const admitPin = withRemoteWebAdmission(params.req, params.admitDevicePin); + const admitPin = params.admitDevicePin; return { claimAdmission, runtimeBindings: createRequestRuntimeBindings({ @@ -811,7 +811,8 @@ function createRequestDeviceAccess(params: { scope: platformRequestScope, dispatchLedger: params.dispatchLedger, admitDeviceClaim: claimAdmission.admit, - admitDevice: + admitDevice: withRemoteWebAdmission( + params.req, admitPin || daemonPolicy || claimPolicy === 'require-owner' ? (device) => { admitPin?.(device); @@ -841,6 +842,7 @@ function createRequestDeviceAccess(params: { } } : undefined, + ), }), }; } diff --git a/website/docs/docs/error-reasons.md b/website/docs/docs/error-reasons.md index 26010845577..477193a444f 100644 --- a/website/docs/docs/error-reasons.md +++ b/website/docs/docs/error-reasons.md @@ -1111,7 +1111,7 @@ These reasons can come from more than one command. | Reason | Meaning | | --- | --- | | `REMOTE_HOST_INPUT_DENIED` | A remote request supplied a host path or other host input (`details.field`), which a remote daemon refuses. | -| `remote_web_public_network_unenforced` | A remote request tried to use the managed browser on the daemon host, which cannot enforce a public-network-only policy. | +| `REMOTE_WEB_PUBLIC_NETWORK_UNENFORCED` | A remote request tried to use the managed browser on the daemon host, which cannot enforce a public-network-only policy. | ### Remote transfer diff --git a/website/docs/docs/remote-proxy.md b/website/docs/docs/remote-proxy.md index 5d77116f5c4..4e36b69d6f8 100644 --- a/website/docs/docs/remote-proxy.md +++ b/website/docs/docs/remote-proxy.md @@ -409,7 +409,7 @@ daemons omit it. {"ok":true,"service":"agent-device-proxy","version":"0.21.39-dev","rpcProtocolVersion":3,"instanceId":"5f0c2d7e-8a41-4b7e-9c3a-2e6d1f4b8a90","hostArch":"arm64","upstream":{"ok":true,"service":"agent-device-daemon","version":"0.21.39-dev","rpcProtocolVersion":3,"instanceId":"b3e9a6c1-4d2f-4f8e-a0b7-7c5d9e1f2a34","hostArch":"arm64"}} ``` -A remote request cannot use the managed browser on the daemon host, because that browser could reach the host's private network. A remote command that would use it returns `UNSUPPORTED_OPERATION` with `details.reason: "remote_web_public_network_unenforced"`. `close` stays allowed. Automating public sites through a remote managed browser is intentionally disabled. +A remote request cannot use the managed browser on the daemon host, because that browser could reach the host's private network. A remote command that would use it returns `UNSUPPORTED_OPERATION` with `details.reason: "REMOTE_WEB_PUBLIC_NETWORK_UNENFORCED"`. `close` stays allowed. Automating public sites through a remote managed browser is intentionally disabled. ## Clean up From 76f55119dddddfd27ea3cd884c99d2819c363cdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Thu, 3 Dec 2026 11:18:06 +0100 Subject: [PATCH 4/8] docs(daemon): align remote web refusal docs and assert non-retriable --- .../remote-web-public-network-confinement.md | 12 ++++++------ .../__tests__/request-router-web-sessions.test.ts | 3 ++- website/docs/docs/remote-proxy.md | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/docs/experiments/remote-web-public-network-confinement.md b/docs/experiments/remote-web-public-network-confinement.md index dbb5f4ee51e..684fceeabf1 100644 --- a/docs/experiments/remote-web-public-network-confinement.md +++ b/docs/experiments/remote-web-public-network-confinement.md @@ -2,10 +2,10 @@ ## Status -Design proposal. [#5243](https://github.com/callstack/agent-device/pull/5243) introduces -`REMOTE_WEB_PUBLIC_NETWORK_UNENFORCED` for remote tenant web commands. -The refusal is absent from the `main` revision that this proposal targets. -Land #5243 before landing the confinement implementation. Keep its refusal until the final phase. +Design proposal. [#5348](https://github.com/callstack/agent-device/pull/5348) adds +`REMOTE_WEB_PUBLIC_NETWORK_UNENFORCED` for remote tenant web commands on 0.22. +The proxy-based confinement design is not implemented. #5272 is superseded. +Keep the refusal until the final phase of the confinement implementation. ## Security invariant @@ -185,10 +185,10 @@ fail-closed when the evidence lane is absent or fails. ## Phased implementation -After #5243 lands, each phase can merge while `assertRemoteWebDeviceAdmitted` refuses remote web. +After #5348 lands, each phase can merge while `assertRemoteWebDeviceAdmitted` refuses remote web. Keep that refusal and the independent launch guard until the final phase. -1. Use the `publicNetworkOnly` provider context from #5265, carried by #5243. Preserve the trusted +1. Use the `publicNetworkOnly` provider context from #5265. Preserve the trusted marker through default web provider construction. Prove that nested batch and replay requests cannot clear the marker. 2. Add a private `@agent-device/platform-web` public-destination classifier. Cover every IPv4 and diff --git a/packages/daemon/src/server/__tests__/request-router-web-sessions.test.ts b/packages/daemon/src/server/__tests__/request-router-web-sessions.test.ts index ac345404314..3ce2e9aab06 100644 --- a/packages/daemon/src/server/__tests__/request-router-web-sessions.test.ts +++ b/packages/daemon/src/server/__tests__/request-router-web-sessions.test.ts @@ -187,6 +187,7 @@ test('remote web open is refused before a browser runtime binds', async () => { ok: false, error: { code: 'UNSUPPORTED_OPERATION', + retriable: false, details: { reason: 'REMOTE_WEB_PUBLIC_NETWORK_UNENFORCED' }, }, }); @@ -218,7 +219,7 @@ test('remote requests cannot use an existing web session', async () => { }); expect(result).toMatchObject({ ok: false, - error: { details: { reason: 'REMOTE_WEB_PUBLIC_NETWORK_UNENFORCED' } }, + error: { retriable: false, details: { reason: 'REMOTE_WEB_PUBLIC_NETWORK_UNENFORCED' } }, }); expect(binds).toBe(0); }); diff --git a/website/docs/docs/remote-proxy.md b/website/docs/docs/remote-proxy.md index 4e36b69d6f8..7f40f1c2d48 100644 --- a/website/docs/docs/remote-proxy.md +++ b/website/docs/docs/remote-proxy.md @@ -158,7 +158,7 @@ derive delivery from step results. Remote requests ignore `meta.cwd`. They refuse host tooling paths and `--launch-console` with reason `REMOTE_HOST_INPUT_DENIED`. They also refuse daemon host paths as `install` and `reinstall` binaries, `push` payload files, and xctrace template files. `open` targets and launch -URLs cannot use the `file:` scheme. Serve local web content over HTTP(S) instead. Upload binaries with the +URLs cannot use the `file:` scheme. Remote web browser use is refused, so run web sessions locally. Upload binaries with the client, send `push` payloads as inline JSON, and name xctrace templates. Omit these inputs, or use a local daemon for host tooling. Test suite artifacts also use a daemon-chosen output root. From cc563e64929067b97586bfb73cf7a5cea3ba9f8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Thu, 3 Dec 2026 11:48:42 +0100 Subject: [PATCH 5/8] docs(web): name withRemoteWebAdmission in the confinement plan --- docs/experiments/remote-web-public-network-confinement.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/experiments/remote-web-public-network-confinement.md b/docs/experiments/remote-web-public-network-confinement.md index 684fceeabf1..9a7c9075776 100644 --- a/docs/experiments/remote-web-public-network-confinement.md +++ b/docs/experiments/remote-web-public-network-confinement.md @@ -185,7 +185,7 @@ fail-closed when the evidence lane is absent or fails. ## Phased implementation -After #5348 lands, each phase can merge while `assertRemoteWebDeviceAdmitted` refuses remote web. +After #5348 lands, each phase can merge while `withRemoteWebAdmission` refuses remote web. Keep that refusal and the independent launch guard until the final phase. 1. Use the `publicNetworkOnly` provider context from #5265. Preserve the trusted @@ -211,7 +211,7 @@ Keep that refusal and the independent launch guard until the final phase. 5. Add real Chromium integration evidence for every row in the coverage table. Observe attempted egress outside the proxy process. Include public positive controls, a local listener replacement attempt after proxy death, and fail-closed behavior on macOS, Linux, and Windows. -6. Replace the routing refusal in `assertRemoteWebDeviceAdmitted` with confinement lease admission. +6. Replace the routing refusal in `withRemoteWebAdmission` with confinement lease admission. At launch, keep `remote_web_browser_unconfined` unless the backend can prove it has the matching proxy. Keep `close` available when either check fails. Update help and security docs in the same change. From 30cd7eb5a8ce2302cda2fc83400e163a1bb983b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Thu, 3 Dec 2026 12:33:00 +0100 Subject: [PATCH 6/8] fix(daemon): refuse remote web requests on an existing session at the 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. --- .../remote-web-public-network-confinement.md | 4 +-- .../request-router-web-sessions.test.ts | 28 +++++++++++++++++++ .../src/server/remote-host-input-policy.ts | 18 +++++++----- .../src/server/request-execution-scope.ts | 12 ++++---- 4 files changed, 47 insertions(+), 15 deletions(-) diff --git a/docs/experiments/remote-web-public-network-confinement.md b/docs/experiments/remote-web-public-network-confinement.md index 9a7c9075776..d82cc1c22b8 100644 --- a/docs/experiments/remote-web-public-network-confinement.md +++ b/docs/experiments/remote-web-public-network-confinement.md @@ -185,7 +185,7 @@ fail-closed when the evidence lane is absent or fails. ## Phased implementation -After #5348 lands, each phase can merge while `withRemoteWebAdmission` refuses remote web. +After #5348 lands, each phase can merge while `assertRemoteWebDeviceAdmitted` refuses remote web. Keep that refusal and the independent launch guard until the final phase. 1. Use the `publicNetworkOnly` provider context from #5265. Preserve the trusted @@ -211,7 +211,7 @@ Keep that refusal and the independent launch guard until the final phase. 5. Add real Chromium integration evidence for every row in the coverage table. Observe attempted egress outside the proxy process. Include public positive controls, a local listener replacement attempt after proxy death, and fail-closed behavior on macOS, Linux, and Windows. -6. Replace the routing refusal in `withRemoteWebAdmission` with confinement lease admission. +6. Replace the refusal in `assertRemoteWebDeviceAdmitted` with confinement lease admission. At launch, keep `remote_web_browser_unconfined` unless the backend can prove it has the matching proxy. Keep `close` available when either check fails. Update help and security docs in the same change. diff --git a/packages/daemon/src/server/__tests__/request-router-web-sessions.test.ts b/packages/daemon/src/server/__tests__/request-router-web-sessions.test.ts index 3ce2e9aab06..5284f22a8a2 100644 --- a/packages/daemon/src/server/__tests__/request-router-web-sessions.test.ts +++ b/packages/daemon/src/server/__tests__/request-router-web-sessions.test.ts @@ -25,6 +25,10 @@ import { lifecycleDeviceRuntimeGateway, } from '../../__tests__/support/test-device-runtime-gateway.ts'; import type { DaemonRequest } from '../../core/daemon-request.ts'; +import { + installInteractorResolution, + interactorResolution, +} from '../../core/interactor-resolution.ts'; import { LeaseRegistry } from '../../resources/lease-registry.ts'; import { daemonPlatformServicesFixture } from '../../__tests__/support/platform-services-fixture.ts'; import { resolveCommandDevice } from '../../resources/session-device-resolution.ts'; @@ -224,6 +228,30 @@ test('remote requests cannot use an existing web session', async () => { expect(binds).toBe(0); }); +test('remote replay on an existing web session is refused before any snapshot', async () => { + mockResolveTargetDevice.mockImplementation(webSessionResolution); + const store = makeSessionStore('agent-device-remote-web-replay-'); + store.publish('existing-web', makeSession('existing-web', { device: WEB_DESKTOP_DEVICE })); + const replayPath = path.join(mkdtempForTestSync('agent-device-remote-web-replay-'), 'flow.ad'); + fs.writeFileSync(replayPath, 'context platform=web\nclick "Save"\n'); + const snapshot = vi.fn(async () => ({ nodes: [] })); + const previous = interactorResolution(); + installInteractorResolution({ resolve: async () => ({ snapshot }) as never }); + try { + const result = await createOpenHandler(store)({ + ...freshWebRequest('replay', 'existing-web', replayPath), + internal: { publicNetworkOnly: true }, + }); + expect(result).toMatchObject({ + ok: false, + error: { retriable: false, details: { reason: 'REMOTE_WEB_PUBLIC_NETWORK_UNENFORCED' } }, + }); + expect(snapshot).not.toHaveBeenCalled(); + } finally { + installInteractorResolution(previous); + } +}); + test('remote close can release an existing web session', async () => { mockResolveTargetDevice.mockImplementation(webSessionResolution); const store = makeSessionStore('agent-device-remote-web-close-'); diff --git a/packages/daemon/src/server/remote-host-input-policy.ts b/packages/daemon/src/server/remote-host-input-policy.ts index 9c0b3110dbd..ccc89ceafb6 100644 --- a/packages/daemon/src/server/remote-host-input-policy.ts +++ b/packages/daemon/src/server/remote-host-input-policy.ts @@ -220,19 +220,23 @@ function remoteHostInputDenied(field: string, hint = REMOTE_HOST_INPUT_HINT): Ap }); } +export function assertRemoteWebDeviceAdmitted(request: DaemonRequest, device: DeviceInfo): void { + if (!request.internal?.publicNetworkOnly) return; + if (device.platform !== 'web' || request.command === 'close') return; + throw new AppError( + 'UNSUPPORTED_OPERATION', + 'The managed web browser cannot enforce public-network-only access for remote requests.', + { reason: REMOTE_HOST_INPUT_REASONS.webPublicNetworkUnenforced.reason, retriable: false }, + ); +} + export function withRemoteWebAdmission( request: DaemonRequest, admitPin: ((device: DeviceInfo) => void) | undefined, ): ((device: DeviceInfo) => void) | undefined { if (!request.internal?.publicNetworkOnly) return admitPin; return (device) => { - if (device.platform === 'web' && request.command !== 'close') { - throw new AppError( - 'UNSUPPORTED_OPERATION', - 'The managed web browser cannot enforce public-network-only access for remote requests.', - { reason: REMOTE_HOST_INPUT_REASONS.webPublicNetworkUnenforced.reason, retriable: false }, - ); - } + assertRemoteWebDeviceAdmitted(request, device); admitPin?.(device); }; } diff --git a/packages/daemon/src/server/request-execution-scope.ts b/packages/daemon/src/server/request-execution-scope.ts index d438c4b5821..0302822a07e 100644 --- a/packages/daemon/src/server/request-execution-scope.ts +++ b/packages/daemon/src/server/request-execution-scope.ts @@ -1,6 +1,6 @@ import { LEASE_REASONS } from '@agent-device/contracts/lease-scope'; import { thrownBeforeDispatch } from '../execution/request-dispatch-disclosure.ts'; -import { restrictRemoteHostInputs, withRemoteWebAdmission } from './remote-host-input-policy.ts'; +import * as remoteInput from './remote-host-input-policy.ts'; import type { EnvMap, HostEnvironment } from '@agent-device/kernel/source-value'; import type { DeviceInfo } from '@agent-device/kernel/device'; import { heldKeyedLockKeys } from '@agent-device/kernel/keyed-lock'; @@ -230,7 +230,7 @@ export async function createRequestExecutionScope(params: { }): Promise { const { sessionStore, leaseRegistry } = params; // Bound here, before this request takes a lock. - const unscopedReq = restrictRemoteHostInputs(params.req); + const unscopedReq = remoteInput.restrictRemoteHostInputs(params.req); const tenantScopedReq = scopeRequestSession(unscopedReq); // A nested batch or replay step arrives with the identity of the request that spawned it, and its // own name is already the store key. @@ -630,6 +630,7 @@ export async function createRequestExecutionScope(params: { try { const existingRef = resolveRequestSessionRef(scopedReq, addressed, leaseRegistry); const existingDevice = existingRef?.session.device; + if (existingDevice) remoteInput.assertRemoteWebDeviceAdmitted(scopedReq, existingDevice); if (isAndroidSessionObservation(scopedReq, existingDevice)) return await runObservation(existingDevice); const session = existingRef?.session; @@ -803,7 +804,6 @@ function createRequestDeviceAccess(params: { trackDisposal: params.trackClaimRecoveryDisposal, }), }); - const admitPin = params.admitDevicePin; return { claimAdmission, runtimeBindings: createRequestRuntimeBindings({ @@ -811,11 +811,11 @@ function createRequestDeviceAccess(params: { scope: platformRequestScope, dispatchLedger: params.dispatchLedger, admitDeviceClaim: claimAdmission.admit, - admitDevice: withRemoteWebAdmission( + admitDevice: remoteInput.withRemoteWebAdmission( params.req, - admitPin || daemonPolicy || claimPolicy === 'require-owner' + params.admitDevicePin || daemonPolicy || claimPolicy === 'require-owner' ? (device) => { - admitPin?.(device); + params.admitDevicePin?.(device); if (daemonPolicy) { assertDaemonPolicyAdmitsDevice(daemonPolicy, device); } From e43a25ebcd4e099b90a90cb1e684a6ac78ea7190 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Thu, 3 Dec 2026 13:23:33 +0100 Subject: [PATCH 7/8] fix(daemon): apply the early remote web refusal only to requests that 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. --- .../src/daemon-command-descriptor.ts | 2 + packages/command-registry/src/registry.ts | 2 + .../src/core/daemon-command-registry.ts | 5 +++ .../request-router-web-sessions.test.ts | 43 +++++++++++++++++++ .../src/server/remote-host-input-policy.ts | 16 +++++++ .../src/server/request-execution-scope.ts | 2 +- 6 files changed, 69 insertions(+), 1 deletion(-) diff --git a/packages/command-registry/src/daemon-command-descriptor.ts b/packages/command-registry/src/daemon-command-descriptor.ts index 5637ae6ee5d..37643137969 100644 --- a/packages/command-registry/src/daemon-command-descriptor.ts +++ b/packages/command-registry/src/daemon-command-descriptor.ts @@ -48,6 +48,8 @@ export type DaemonCommandDescriptor = { * that session and stays refused. */ ignoresSessionLease?: boolean; + /** This request reads only session metadata or its own lease scope, never the session's device. */ + detachedFromSessionDevice?: (req: TRequest) => boolean; /** * packages/daemon/docs/remote-device-lease-contracts.md: this command may run under a `macos-app` lease, or on a daemon whose policy requires * one. A command without it is refused there, `leaseAdmissionExempt` or not, so a command diff --git a/packages/command-registry/src/registry.ts b/packages/command-registry/src/registry.ts index 21b14465b67..172237c8326 100644 --- a/packages/command-registry/src/registry.ts +++ b/packages/command-registry/src/registry.ts @@ -232,6 +232,7 @@ export const RAW_COMMAND_DESCRIPTORS = [ daemon: { route: 'lease', refFrameEffect: 'preserve', + detachedFromSessionDevice: () => true, ...ADMISSION_AND_LOCK_EXEMPT, }, timeoutPolicy: DEFAULT_TIMEOUT_POLICY, @@ -349,6 +350,7 @@ export const RAW_COMMAND_DESCRIPTORS = [ sessionKind: 'inventory', lockPolicySelectorOverride: true, allowSessionlessDefaultDevice: allowAnyDeviceSessionless, + detachedFromSessionDevice: (req) => req.flags?.remote === true, ...REQUEST_EXECUTION_EXEMPT, }, timeoutPolicy: DEFAULT_TIMEOUT_POLICY, diff --git a/packages/daemon/src/core/daemon-command-registry.ts b/packages/daemon/src/core/daemon-command-registry.ts index 64e56b0e815..c4af3e76784 100644 --- a/packages/daemon/src/core/daemon-command-registry.ts +++ b/packages/daemon/src/core/daemon-command-registry.ts @@ -71,6 +71,11 @@ export function ignoresSessionLease(command: string): boolean { return getDaemonCommandDescriptor(command)?.ignoresSessionLease === true; } +export function isDetachedFromSessionDevice(req: DaemonRequest): boolean { + const entry = getDaemonCommandDescriptor(req.command); + return entry?.ignoresSessionLease === true || entry?.detachedFromSessionDevice?.(req) === true; +} + export function isAppLeaseAllowed(command: string): boolean { return getDaemonCommandDescriptor(command)?.appLease === 'allowed'; } diff --git a/packages/daemon/src/server/__tests__/request-router-web-sessions.test.ts b/packages/daemon/src/server/__tests__/request-router-web-sessions.test.ts index 5284f22a8a2..bb978d30520 100644 --- a/packages/daemon/src/server/__tests__/request-router-web-sessions.test.ts +++ b/packages/daemon/src/server/__tests__/request-router-web-sessions.test.ts @@ -8,6 +8,7 @@ import { type WebSessionIdentity, } from '@agent-device/kernel/device'; import { + ANDROID_DEVICE, WEB_DESKTOP_DEVICE, closeLoopbackServer, createTestHostEnvironment, @@ -271,6 +272,48 @@ test('remote close can release an existing web session', async () => { expect(store.get('existing-web')).toBeUndefined(); }); +const androidSerial = { platform: 'android' as const, serial: ANDROID_DEVICE.id }; +test.each([ + { command: 'devices', flags: {}, refused: false }, + { command: 'session_list', flags: {}, refused: false }, + { command: 'lease_allocate', flags: {}, refused: false }, + { command: 'artifacts', flags: {}, refused: false }, + { command: 'doctor', flags: { remote: true }, leased: true, refused: false }, + { command: 'capabilities', flags: androidSerial, refused: false }, + { command: 'apps', flags: androidSerial, refused: false }, + { command: 'doctor', flags: {}, leased: true, refused: true }, + { command: 'capabilities', flags: {}, refused: true }, +])('remote $command $flags at a web session address: refused=$refused', async (row) => { + mockResolveTargetDevice.mockImplementation(async (flags, options) => + (flags as { serial?: string }).serial ? ANDROID_DEVICE : webSessionResolution(flags, options), + ); + const store = makeSessionStore('agent-device-remote-web-detached-'); + const leaseRegistry = new LeaseRegistry(); + const lease = row.leased ? leaseRegistry.allocateLease({ tenantId: 't', runId: 'r' }) : undefined; + store.publish( + 'existing-web', + makeSession('existing-web', { + device: WEB_DESKTOP_DEVICE, + sessionScope: { kind: 'named-local' }, + ...(lease && { lease }), + }), + ); + const result = await createOpenHandler( + store, + leaseRegistry, + )({ + token: 'test-token', + session: 'existing-web', + command: row.command, + positionals: [], + flags: row.flags, + meta: { requestId: `remote-${row.command}`, sessionExplicit: true, leaseId: lease?.leaseId }, + internal: { publicNetworkOnly: true }, + }); + const reason = result.ok ? undefined : result.error.details?.reason; + expect(reason === 'REMOTE_WEB_PUBLIC_NETWORK_UNENFORCED').toBe(row.refused); +}); + test('local web open is unaffected by the remote web refusal', async () => { mockResolveTargetDevice.mockImplementation(webSessionResolution); const store = makeSessionStore('agent-device-local-web-open-'); diff --git a/packages/daemon/src/server/remote-host-input-policy.ts b/packages/daemon/src/server/remote-host-input-policy.ts index ccc89ceafb6..c08acbb2b7d 100644 --- a/packages/daemon/src/server/remote-host-input-policy.ts +++ b/packages/daemon/src/server/remote-host-input-policy.ts @@ -4,6 +4,13 @@ import { INTERNAL_COMMANDS } from '@agent-device/command-registry/catalog'; import { validateAndNormalizeBatchSteps } from '@agent-device/command-registry/batch'; import { DEFAULT_BATCH_MAX_STEPS } from '@agent-device/contracts/command'; import type { DaemonRequest } from '../core/daemon-request.ts'; +import type { SessionState } from '../core/session-state.ts'; +import { listSessionSelectorConflicts } from '../core/session-selector.ts'; +import { hasExplicitDeviceSelector } from '../core/device/device-selector-intent.ts'; +import { + isDetachedFromSessionDevice, + shouldPreferExplicitDeviceOverExistingSession, +} from '../core/daemon-command-registry.ts'; import { remoteScriptOpen } from '../core/session-script-publication-capability.ts'; const REMOTE_HOST_INPUT_REASONS = { @@ -230,6 +237,15 @@ export function assertRemoteWebDeviceAdmitted(request: DaemonRequest, device: De ); } +export function assertRemoteWebSessionAdmitted(req: DaemonRequest, session?: SessionState): void { + if (!session || !req.internal?.publicNetworkOnly || isDetachedFromSessionDevice(req)) return; + const selectsOtherDevice = + shouldPreferExplicitDeviceOverExistingSession(req) && + hasExplicitDeviceSelector(req.flags) && + listSessionSelectorConflicts(session, req.flags).length > 0; + if (!selectsOtherDevice) assertRemoteWebDeviceAdmitted(req, session.device); +} + export function withRemoteWebAdmission( request: DaemonRequest, admitPin: ((device: DeviceInfo) => void) | undefined, diff --git a/packages/daemon/src/server/request-execution-scope.ts b/packages/daemon/src/server/request-execution-scope.ts index 0302822a07e..1accd3fbcd2 100644 --- a/packages/daemon/src/server/request-execution-scope.ts +++ b/packages/daemon/src/server/request-execution-scope.ts @@ -629,8 +629,8 @@ export async function createRequestExecutionScope(params: { let admissionCompleted = false; try { const existingRef = resolveRequestSessionRef(scopedReq, addressed, leaseRegistry); + remoteInput.assertRemoteWebSessionAdmitted(scopedReq, existingRef?.session); const existingDevice = existingRef?.session.device; - if (existingDevice) remoteInput.assertRemoteWebDeviceAdmitted(scopedReq, existingDevice); if (isAndroidSessionObservation(scopedReq, existingDevice)) return await runObservation(existingDevice); const session = existingRef?.session; From 52126c9a00df5c3e6f4327d4758045910d392e18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Thu, 3 Dec 2026 13:28:08 +0100 Subject: [PATCH 8/8] refactor(daemon): keep the remote web device check module-private --- packages/daemon/src/server/remote-host-input-policy.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/daemon/src/server/remote-host-input-policy.ts b/packages/daemon/src/server/remote-host-input-policy.ts index c08acbb2b7d..b94eba1c8f8 100644 --- a/packages/daemon/src/server/remote-host-input-policy.ts +++ b/packages/daemon/src/server/remote-host-input-policy.ts @@ -227,7 +227,7 @@ function remoteHostInputDenied(field: string, hint = REMOTE_HOST_INPUT_HINT): Ap }); } -export function assertRemoteWebDeviceAdmitted(request: DaemonRequest, device: DeviceInfo): void { +function assertRemoteWebDeviceAdmitted(request: DaemonRequest, device: DeviceInfo): void { if (!request.internal?.publicNetworkOnly) return; if (device.platform !== 'web' || request.command === 'close') return; throw new AppError(