diff --git a/docs/experiments/remote-web-public-network-confinement.md b/docs/experiments/remote-web-public-network-confinement.md new file mode 100644 index 00000000000..18c723f8415 --- /dev/null +++ b/docs/experiments/remote-web-public-network-confinement.md @@ -0,0 +1,220 @@ +# Remote web public-network confinement + +## Status + +Design proposal. Remote tenant web commands stay refused with +`remote_web_public_network_unenforced` until this contract has an implementation and end-to-end +evidence. + +## Security invariant + +A browser that belongs to a request with `internal.publicNetworkOnly` must not create a network +connection to an address that is not globally reachable. This rule applies to every browser-created +connection for the session. It is not limited to the URL supplied to `open`. + +The enforcement point must select and connect the destination IP address. A URL check, a DNS check +followed by a browser connection, or inspection after a request cannot enforce the invariant. + +## Required boundary + +Use one daemon-owned explicit forward proxy for confined web sessions. Start the proxy before the +first browser process for a confined session. Keep it alive until that browser is closed. Configure +the browser with a fixed proxy and no direct fallback. + +The proxy must apply these rules: + +1. Accept connections only on a loopback listener. Apply global and per-session connection limits, + because another local user can discover and use a TCP listener. +2. Accept only HTTP proxy requests and HTTP `CONNECT` requests. +3. Parse the authority once. Reject user information, malformed ports, IP zone identifiers, and + non-canonical or ambiguous IP address forms. +4. Permit only `http`, `https`, `ws`, and `wss` browser traffic. Treat every other external protocol + as denied unless a later design names its enforcement path. +5. Resolve a hostname for each new upstream connection. Never reuse a browser-supplied resolution. +6. Classify every resolved address. Reject the request when any answer is unspecified, loopback, + link-local, private, carrier-grade NAT, documentation, benchmarking, multicast, reserved, or + otherwise non-unicast. Also reject every address assigned to a current daemon-host network + interface, including a publicly routed address. Apply IPv4 classification and local-interface + comparison to IPv4-mapped IPv6 addresses. Reject IPv4-embedded IPv6 answers, including DNS64 + synthesis under a network-specific Pref64, unless the proxy can prove the embedded IPv4 + destination is public and the translated peer is not on a local interface. If the prefix cannot + be identified and checked, refuse the answer set. +7. Connect to one admitted numeric address from that resolution result. Do not resolve the hostname + again in the connection API. Preserve the original hostname only for the HTTP `Host` field and + TLS server name that pass through the tunnel. +8. Apply the same resolution and connection rule to an absolute-form HTTP request and to `CONNECT`. +9. Re-resolve on a new connection, including after redirects, connection failure, proxy retry, and + keep-alive expiry. A previously admitted address does not admit a different address. +10. Bound request headers, connection count, DNS time, connect time, idle time, and bytes buffered + before either side applies backpressure. +11. Require absolute-form targets for ordinary HTTP. Treat the parsed target as the only authority, + and overwrite `Host` from that authority after admission. +12. Reject conflicting or ambiguous `Content-Length`, `Transfer-Encoding`, and upgrade framing. + Remove proxy credentials and hop-by-hop headers before forwarding. Preserve only the one valid + WebSocket upgrade shape. +13. Emit typed refusal details without returning resolved private addresses to the remote caller. + +The browser launch must use the fixed proxy as its only network route. It must set +`--proxy-bypass-list="<-loopback>"`; an empty bypass list retains Chromium's implicit direct rules +for localhost, link-local, and unspecified addresses. Chromium documents `<-loopback>` as the +subtractive rule for those implicit bypasses in +[Proxy support in Chrome](https://chromium.googlesource.com/chromium/src/+/master/net/docs/proxy.md#proxy-config-url-patterns_subtract-implicit-rules). +The launch must also disable QUIC and non-proxied WebRTC UDP. The launch owner must replace +conflicting caller-supplied proxy, bypass, QUIC, and WebRTC arguments. Appending another argument +without proving Chromium's duplicate-argument precedence is not sufficient. + +If Chromium or `agent-browser` can create another external transport that does not use the fixed +proxy, remote web remains refused until that transport is disabled or confined. Examples include +WebTransport, direct sockets exposed by an extension, and a browser feature added after the pinned +backend version. + +## Backend launch and session isolation + +The implementation stack updates the managed backend from `agent-browser` 0.39.0 to 0.42.0 in +#5273. The proxy flags expose a launch seam, but they do not enforce confinement by themselves. + +- `--proxy` and `AGENT_BROWSER_PROXY` become Chromium `--proxy-server`. +- `--proxy-bypass` and `AGENT_BROWSER_PROXY_BYPASS` become Chromium `--proxy-bypass-list`. +- A changed proxy launch setting can relaunch a managed browser. The setting is ignored when the + session attaches through CDP, auto-connect, or a provider. +- Raw launch arguments can disable QUIC. The backend's domain-filter path already removes a caller + WebRTC policy argument before it appends `disable_non_proxied_udp`. + +The managed backend inherits `AGENT_BROWSER_*` connection settings from the daemon host. It also +uses the same socket directory for local and remote web sessions. This layout does not establish +that an existing browser was started under the remote confinement policy. An inherited connection +target can also select an external browser where the proxy setting has no effect. The +[0.42.0 session documentation](https://raw.githubusercontent.com/vercel-labs/agent-browser/v0.42.0/skill-data/core/references/session-management.md) +describes both the ignored proxy setting on external connections and retained settings across +commands and daemon restarts. A successful CLI command does not prove that its browser used the +proxy. + +Route remote sessions through a daemon-owned socket namespace separate from local sessions. Preserve +the ADR 0037 backend key and socket path limits. Remove inherited connection targets, profiles, +extensions, restore and state inputs, raw startup arguments, and conflicting proxy settings before +launch. Reject a remote command if the backend can still attach through CDP, auto-connect, or a +provider. Start a fresh managed Chromium browser under the confined policy, and verify that the +backend applied the proxy setting before accepting the session. Apply the same policy to every +later command that can launch or relaunch a browser. Keep the proxy alive through the browser's +life and close the browser if the matching proxy cannot be recovered. + +## Coverage table + +| Traffic source | Required enforcement | +| --- | --- | +| Initial `open` URL | Scheme admission plus the proxy's resolution and pinned numeric connection | +| HTTP redirect | The redirected request returns through the proxy and receives a fresh connection admission | +| HTML subresource, worker, service worker, `fetch`, and XHR | The browser has no direct route, so every external connection returns through the proxy | +| WebSocket | `ws` uses an absolute-form proxy request and `wss` uses `CONNECT`; both use the same admission | +| DNS rebinding | The proxy connects only to an address from its own current result and never asks the socket layer to resolve again | +| DNS64/NAT64 answer | The proxy identifies the synthesis prefix and classifies the embedded IPv4 destination before connecting, or refuses the answer set | +| HTTP keep-alive and HTTP/2 inside `CONNECT` | The admitted numeric peer stays fixed for the life of that connection | +| QUIC and WebTransport over HTTP/3 | Disabled unless the confinement owner later provides a UDP enforcement path | +| WebRTC | Non-proxied UDP disabled. A test must prove that the pinned Chromium build does not reach a private peer through another candidate type | +| `file`, `ftp`, `gopher`, custom handlers, and extension protocols | Refused before navigation or disabled at browser launch; no claim relies only on the current CLI URL parser | +| `data`, `blob`, `about`, and `view-source` | Local rendering may run, but any external connection that it initiates still uses the proxy | +| Browser proxy settings | Conflicting environment and caller arguments are replaced. The bypass list is exactly `<-loopback>`, not empty. Page content cannot change the fixed browser proxy | +| Prior local session or inherited connection target | Remote socket namespace is separate. CDP, auto-connect, and provider attachments are rejected before navigation | +| Relaunch after a later command or daemon restart | The same confinement policy and live proxy are required before any browser process starts | + +## Trust-boundary case table + +| Case | Who chooses the name | What the kernel resolves | What can change | Where bytes first leave the host | Result | +| --- | --- | --- | --- | --- | --- | +| Public hostname | Remote page or remote caller | Nothing by hostname; the proxy supplies a numeric address | DNS can change before the next connection | Proxy socket to the admitted public address | Accept | +| Public hostname resolves only to a denied address | Remote page or remote caller | No upstream socket is created | DNS can change after refusal | Nowhere | Refuse | +| Mixed public and denied answers | Authoritative DNS | No upstream socket is created | Answer order and TTL can change | Nowhere | Refuse the complete answer set | +| Hostname changes from public to denied | Authoritative DNS | Each connection receives one numeric address | DNS changes between connections | Existing connection stays on its admitted peer; the next connection is refused | Accept existing, refuse new | +| Numeric private address | Remote page or remote caller | Nothing | Text representations can be ambiguous | Nowhere | Refuse | +| Daemon host's public interface address | Remote page or remote caller | Nothing | Interface addresses can change | Nowhere | Refuse | +| Public HTTP redirect to private | Remote server | Nothing by hostname | Redirect target is attacker-controlled | Nowhere for the redirected destination | Refuse redirected connection | +| Public TLS tunnel | Remote page or remote caller | Nothing by hostname; proxy connects to an admitted numeric peer | Bytes inside TLS are opaque | Proxy socket to the admitted public address | Accept | +| Fixed proxy with an empty bypass list | Chromium's implicit rules | Chromium may connect directly to localhost, link-local, or unspecified literals | Browser defaults can change with Chromium | Browser socket bypasses the proxy | Refuse the launch configuration | +| Fixed proxy with bypass list `<-loopback>` | Remote page or remote caller | Proxy resolves and connects as above | Browser defaults can change with Chromium | Proxy socket only | Accept after the host-boundary bypass test passes | +| Proxy unavailable or loses its listener capability | Daemon lifecycle | Nothing | Browser may retry | Nowhere | Fail closed; no direct fallback | +| Existing or externally attached browser ignores proxy settings | Backend session state or inherited host environment | No confined destination is proven | A later command can reuse or relaunch the browser | The external browser can connect directly | Refuse; do not adopt that browser | + +## Lifecycle and ownership + +The confinement proxy belongs beside the managed browser lifecycle in `@agent-device/platform-web`. +The request router supplies the trusted `publicNetworkOnly` fact through request-bound runtime +composition. Page input and command flags must not be able to enable confinement for one call and +then reuse the browser without it, or disable confinement on a browser that was created with it. + +Confinement does not add a suffix or another axis to the device ID or backend key. ADR 0037 derives +`p_`, `w_`, and `t_` keys from session and tenant isolation, independently of `publicNetworkOnly`. +A remote request can therefore use a `p_` or `w_` key, and a local tenant-isolated request can use +a `t_` key. Record the confinement fact on the web session lease and durable process record. Before +an existing session is adopted, compare that fact with the request and refuse a mismatch, regardless +of key prefix. Keep confined browser sockets in a separate namespace from local browser sockets. +The process record also identifies the confined browser's proxy listener. +Startup recovery must close a browser when it cannot prove that the matching proxy listener is live +and owned by this daemon process. The remote socket namespace must remain separate after a daemon +restart. A local session must not be able to reuse its backend key to enter that namespace. + +`close` remains available when proxy startup, proxy recovery, or confinement admission fails. + +## Proof required before enabling remote web + +Focused unit tests must cover the complete IPv4 and IPv6 classification table, authority parsing, +pinned-address connection, limits, and typed refusals. Integration tests with the real pinned +Chromium and managed `agent-browser` must demonstrate denial for initial URLs, redirects, +subresources, workers, service workers, WebSockets, DNS rebinding, loopback bypass, QUIC, WebRTC, +and conflicting browser arguments. + +The browser evidence must observe attempted connections at a host network boundary. A proxy log +alone cannot prove that Chromium had no bypass. Run the same public destinations as positive +controls and prove that normal remote web commands still work. + +Repeat this evidence when the pinned `agent-browser` or Chromium version changes. Keep remote web +fail-closed when the evidence lane is absent or fails. + +## Phased implementation + +Each phase can merge while `assertRemoteWebDeviceAdmitted` still refuses remote web. Remove that +refusal only in the final phase. + +1. Add `publicNetworkOnly?: true` to `PlatformProviderRequestContext`. Populate it only from + `DaemonRequest.internal.publicNetworkOnly`. Forward it to default web provider construction. + Add routing tests that prove nested batch and replay requests cannot clear the fact. +2. Add a private `@agent-device/platform-web` public-destination classifier. Cover every IPv4 and + IPv6 range, IPv4-mapped IPv6, DNS64/NAT64 synthesis, mixed DNS answers, and current host-interface + addresses. Do not export it as a general URL validator. +3. Add the bounded loopback forward proxy. Use Node's HTTP parser for absolute-form HTTP and + `CONNECT`. Resolve all answers, reject the complete set when one answer is denied, and connect + with the admitted numeric address. Add framing, header, timeout, backpressure, cancellation, and + capacity tests at this module boundary. +4. Give the default web provider a confinement-proxy lease keyed by the existing backend key and + recorded confinement fact. Refuse adoption when a request's fact differs from that of the + existing session. Isolate its backend socket namespace from local sessions. Start the proxy + before `open`. + Pass the fixed proxy, the exact `<-loopback>` subtractive bypass rule, `--disable-quic`, and the + enforced WebRTC policy on every backend call. Remove inherited connection targets and reject + external attachments and conflicting host settings. Verify a fresh managed browser received the + proxy policy before navigation. Record proxy ownership beside the managed browser process record. + Close both resources together. +5. Add real Chromium integration evidence for every row in the coverage table. Observe attempted + egress outside the proxy process. Include public positive controls and proxy-death fail-closed + behavior on macOS, Linux, and Windows. +6. Replace `remote_web_public_network_unenforced` admission with a check for a live, matching + confinement lease. Keep `close` independent of that check. Update help and security docs in the + same change. + +The dependency change is optional. The current backend flags can launch a confined browser. A +smaller and safer integration would add an upstream `--public-network-proxy ` mode that rejects +profiles, providers, restore/state, extensions, startup URLs in raw arguments, proxy bypasses, QUIC, +and unsafe WebRTC settings as one atomic launch policy. Without that API, agent-device must pin and +re-audit those launch-option conflicts at each backend upgrade. + +## Rejected partial fixes + +- Checking only the `open` URL misses redirects, subresources, script-created requests, and sockets. +- Resolving before navigation and then passing the hostname to Chromium permits a second DNS lookup + and DNS rebinding. +- Request interception through an `agent-browser` command is unavailable in the managed backend and + would still need proof for workers, WebSockets, service workers, and browser-owned traffic. +- Observing `network requests` after execution detects traffic after the protected service may have + received it. +- An HTTP proxy without browser launch hardening leaves implicit bypasses and UDP transports. +- A DNS server that filters private answers does not pin the address used by the connection and does + not cover numeric destinations. diff --git a/packages/contracts/src/platform-providers.ts b/packages/contracts/src/platform-providers.ts index 7519e10d4d1..a6438392b43 100644 --- a/packages/contracts/src/platform-providers.ts +++ b/packages/contracts/src/platform-providers.ts @@ -24,6 +24,8 @@ export type PlatformProviderRequestContext = Readonly<{ requestId?: string; /** Daemon policy says that the root may construct its managed Web provider for this request. */ useDefaultWebProvider?: boolean; + /** The daemon's trusted remote-tenant policy for this request. */ + publicNetworkOnly?: true; }>; /** The only request-scoped platform value currently consumed by daemon handlers. diff --git a/packages/daemon/src/server/request-platform-provider-context.test.ts b/packages/daemon/src/server/request-platform-provider-context.test.ts index 5c24b640df1..82bf79373d4 100644 --- a/packages/daemon/src/server/request-platform-provider-context.test.ts +++ b/packages/daemon/src/server/request-platform-provider-context.test.ts @@ -76,6 +76,22 @@ test('request provider context preserves an explicitly empty request id', async assert.equal(context?.device.id, IOS_SIMULATOR.id); }); +test('request provider context carries only the daemon-owned network policy', async () => { + const local = await resolvePlatformProviderRequestContext({ + req: request('snapshot'), + existingSession: makeIosSession('ios-session'), + env: process.env, + }); + const remote = await resolvePlatformProviderRequestContext({ + req: { ...request('snapshot'), internal: { publicNetworkOnly: true } }, + existingSession: makeIosSession('ios-session'), + env: process.env, + }); + + assert.equal(local?.publicNetworkOnly, undefined); + assert.equal(remote?.publicNetworkOnly, true); +}); + function request(command: string): DaemonRequest { return { token: 'test-token', diff --git a/packages/daemon/src/server/request-platform-provider-context.ts b/packages/daemon/src/server/request-platform-provider-context.ts index 3784652d663..22704cdc299 100644 --- a/packages/daemon/src/server/request-platform-provider-context.ts +++ b/packages/daemon/src/server/request-platform-provider-context.ts @@ -46,6 +46,7 @@ export async function resolvePlatformProviderRequestContext(params: { } : {}), ...(params.useDefaultWebProvider ? { useDefaultWebProvider: true } : {}), + ...(params.req.internal?.publicNetworkOnly === true ? { publicNetworkOnly: true } : {}), }; } diff --git a/packages/platform-web/src/__tests__/test-utils.ts b/packages/platform-web/src/__tests__/test-utils.ts index b1ce155074d..f93c4c8f7a6 100644 --- a/packages/platform-web/src/__tests__/test-utils.ts +++ b/packages/platform-web/src/__tests__/test-utils.ts @@ -59,6 +59,7 @@ export async function withManagedAgentBrowserProvider( session?: string; openWebSessionNames?: () => readonly string[]; ownedProcessRecords?: OwnedProcessRecordStore; + publicNetworkOnly?: true; }, testFn: (provider: WebProvider) => void | Promise, ): Promise { diff --git a/packages/platform-web/src/agent-browser-provider.test.ts b/packages/platform-web/src/agent-browser-provider.test.ts index e7068257140..dd394df9a56 100644 --- a/packages/platform-web/src/agent-browser-provider.test.ts +++ b/packages/platform-web/src/agent-browser-provider.test.ts @@ -56,6 +56,30 @@ test('agent-browser provider keys its browser on its backend key as given', asyn }); }); +test('a confined remote provider refuses before browser cleanup or backend spawn', async () => { + await withManagedAgentBrowserProvider( + { session: 't_remote-session', publicNetworkOnly: true, openWebSessionNames: () => [] }, + async (provider) => { + const calls: AgentBrowserCall[] = []; + await withCommandExecutorOverride(recordingExecutor(calls), async () => { + await assert.rejects( + provider.open('https://example.test'), + (error: unknown) => + error instanceof AppError && + error.code === 'UNSUPPORTED_OPERATION' && + error.details?.reason === 'remote_web_browser_unconfined', + ); + assert.equal(mockProviderStartupCleanup.mock.calls.length, 0); + await provider.close(); + }); + assert.deepEqual( + calls.map((call) => call.args), + [['close', '--json', '--session', 't_remote-session']], + ); + }, + ); +}); + test('agent-browser provider maps supported operations to session-scoped JSON commands', async () => { await withManagedAgentBrowserProvider({ session: 'web-session' }, async (provider) => { const calls: AgentBrowserCall[] = []; diff --git a/packages/platform-web/src/agent-browser-provider.ts b/packages/platform-web/src/agent-browser-provider.ts index 1d6e2084cd7..6edcae32a0d 100644 --- a/packages/platform-web/src/agent-browser-provider.ts +++ b/packages/platform-web/src/agent-browser-provider.ts @@ -30,6 +30,7 @@ import { import type { WebProvider, WebSnapshotOptions, WebSnapshotResult } from './provider.ts'; import { AGENT_BROWSER_REFUSAL_REASONS, + assertManagedAgentBrowserNetworkPolicy, getManagedAgentBrowserStatus, mapManagedAgentBrowserError, runManagedAgentBrowser, @@ -58,9 +59,10 @@ type AgentBrowserProviderOptions = { /** The backend keys of the published web sessions. */ openWebSessionNames?: () => readonly string[]; ownedProcessRecords?: OwnedProcessRecordStore; + publicNetworkOnly?: true; }; -/** How one backend call is executed: cancellation, plus the work it reads from stdin (`batch`). */ +/** Cancellation and stdin work for one backend call. */ type AgentBrowserRunOptions = { signal?: AbortSignal; stdin?: string; @@ -72,9 +74,8 @@ type AgentBrowserRunOptions = { }; export function createAgentBrowserWebProvider(options: AgentBrowserProviderOptions): WebProvider { - const { session } = options; const runJson = async (args: string[], run?: AgentBrowserRunOptions): Promise => - await runAgentBrowserJson(args, { session, options, ...run }); + await runAgentBrowserJson(args, { session: options.session, options, ...run }); return { async open(target) { @@ -568,15 +569,7 @@ async function runAgentBrowserJson( } /** Detail keys that hold what an executed backend command printed. */ -const BACKEND_OUTPUT_DETAIL_KEYS: ReadonlySet = new Set([ - 'stdout', - 'stderr', - 'agentBrowserError', -]); - -function hasBackendOutput(error: AppError): boolean { - return Object.keys(error.details ?? {}).some((key) => BACKEND_OUTPUT_DETAIL_KEYS.has(key)); -} +const BACKEND_OUTPUT_DETAIL_KEYS = new Set(['stdout', 'stderr', 'agentBrowserError']); function detailsWithoutBackendOutput(error: AppError): Record { return Object.fromEntries( @@ -600,7 +593,11 @@ function withoutBackendAnswer(error: unknown, label: string): unknown { * ran (the backend missing, a cancellation) carries no output and passes through unchanged. */ function withoutBackendOutput(error: unknown): unknown { - if (!(error instanceof AppError) || !hasBackendOutput(error)) return error; + if ( + !(error instanceof AppError) || + !Object.keys(error.details ?? {}).some((key) => BACKEND_OUTPUT_DETAIL_KEYS.has(key)) + ) + return error; return new AppError(error.code, error.message, detailsWithoutBackendOutput(error)); } @@ -610,6 +607,7 @@ async function runAgentBrowserCommand( interpret: (result: { stdout: string; stderr: string; exitCode: number }) => unknown, run: AgentBrowserRunOptions, ): Promise { + assertManagedAgentBrowserNetworkPolicy(cliArgs, options.publicNetworkOnly); let stdout = ''; let stderr = ''; let exitCode = 0; @@ -627,6 +625,7 @@ async function runAgentBrowserCommand( stateDir: options.stateDir, allowFailure: true, timeoutMs: AGENT_BROWSER_TIMEOUT_MS, + ...(options.publicNetworkOnly ? { publicNetworkOnly: true } : {}), signal: run.signal, stdin: run.stdin, }); diff --git a/packages/platform-web/src/agent-browser-tool.ts b/packages/platform-web/src/agent-browser-tool.ts index defd57d917e..59113431d30 100644 --- a/packages/platform-web/src/agent-browser-tool.ts +++ b/packages/platform-web/src/agent-browser-tool.ts @@ -47,6 +47,7 @@ export type ManagedAgentBrowserRunOptions = { timeoutMs: number; allowFailure?: boolean; signal?: AbortSignal; + publicNetworkOnly?: true; /** Written to the backend's stdin, for the command that reads its work from it (`batch`). */ stdin?: string; }; @@ -60,11 +61,23 @@ export async function runManagedAgentBrowser( args: readonly string[], options: ManagedAgentBrowserRunOptions, ): Promise { + assertManagedAgentBrowserNetworkPolicy(args, options.publicNetworkOnly); const status = getManagedAgentBrowserStatus({ host: options.host, stateDir: options.stateDir }); if (!status.installed) throw missingManagedToolError(status); return await spawnManagedAgentBrowser(status, args, options); } +export function assertManagedAgentBrowserNetworkPolicy( + args: readonly string[], + publicNetworkOnly: true | undefined, +): void { + if (!publicNetworkOnly || args[0] === 'close') return; + throw new AppError('UNSUPPORTED_OPERATION', 'Remote web browser network access is unavailable.', { + reason: AGENT_BROWSER_REFUSAL_REASONS.remoteNetworkUnenforced.reason, + retriable: false, + }); +} + export async function setupManagedAgentBrowser(options: { host: HostEnvironment; stateDir?: string; @@ -317,10 +330,11 @@ export function mapManagedAgentBrowserError(error: unknown): AppError { /** * Why the managed `agent-browser` backend's answer cannot be trusted. The backend runs and prints - * JSON; these rows are the shapes that JSON can have which prove the round trip went wrong, and - * the text-entry refusals the entry's own verdict gives. + * JSON; these rows include invalid answers, text-entry refusals, and launch policy refusals. */ export const AGENT_BROWSER_REFUSAL_REASONS = { + // A remote tenant's browser cannot run before its public-network proxy is enforced. + remoteNetworkUnenforced: { reason: 'remote_web_browser_unconfined' }, // The batch call for a text entry answered with something other than its one echoed entry. textEntryResultUnusable: { reason: 'text-entry-result-unusable' }, // The backend ran the fill or type entry and the page refused it. diff --git a/src/commands/schema/cli-help.ts b/src/commands/schema/cli-help.ts index 1bb3c10473a..b54118d046e 100644 --- a/src/commands/schema/cli-help.ts +++ b/src/commands/schema/cli-help.ts @@ -683,7 +683,7 @@ Rules: body: `agent-device help web Use --platform web only for the minimal browser command loop exposed through agent-device. -Managed web sessions run locally. A remote tenant request to a web device is refused with reason remote_web_public_network_unenforced because browser subrequests cannot be confined to public destinations; close remains available for cleanup. +Managed web sessions run locally. A tenant request through the remote proxy or a daemon auth hook is refused with reason remote_web_public_network_unenforced because browser subrequests cannot be restricted to public destinations. A remote request that reaches the managed browser without passing daemon admission is refused with reason remote_web_browser_unconfined; close remains available for cleanup. Dependency: Browser mechanics come from a managed, pinned agent-browser backend. agent-device owns command/session/replay integration, selectors/refs at the command surface, and artifact routing; agent-browser owns browser launch, page control, screenshots, and browser-specific behavior. diff --git a/src/platform-runtime-provider-scope.test.ts b/src/platform-runtime-provider-scope.test.ts index fcb273c7356..70d7e5369e7 100644 --- a/src/platform-runtime-provider-scope.test.ts +++ b/src/platform-runtime-provider-scope.test.ts @@ -1,5 +1,8 @@ import assert from 'node:assert/strict'; import { test } from 'vitest'; +import { AppError } from '@agent-device/kernel/errors'; +import { webSessionDevice } from '@agent-device/kernel/device'; +import { withCommandExecutorOverride } from '@agent-device/host-kit/command'; import type { PlatformProviderRequestContext, RequestPlatformProviderScope, @@ -9,6 +12,8 @@ import { IOS_SIMULATOR, MACOS_DEVICE, WEB_DESKTOP_DEVICE, + bindTestCommandHost, + createTestHostEnvironment, } from '@agent-device/test-kit'; import { createLocalAppleToolProvider, runXcrun } from '@agent-device/platform-apple/tool-provider'; import { buildSimctlArgsForDevice } from '@agent-device/platform-apple/simctl'; @@ -23,6 +28,8 @@ import { type PlatformProviderResolvers, } from './platform-runtime.ts'; +bindTestCommandHost(); + const OTHER_IOS_SIMULATOR = { platform: 'apple', id: 'sim-2', @@ -176,6 +183,40 @@ test('web provider scope uses the context device', async () => { assert.deepEqual(calls, ['web-session:agent-browser-chrome', 'open:https://example.test']); }); +test('default web provider carries remote confinement through composition before browser work', async () => { + const browserCalls: string[] = []; + const providers = createRequestPlatformProviders({ + defaultWebProvider: { + host: createTestHostEnvironment(), + openWebSessionNames: () => [], + }, + }); + const device = webSessionDevice(WEB_DESKTOP_DEVICE, { name: 'remote-web' }); + await withCommandExecutorOverride( + async (cmd) => { + browserCalls.push(cmd); + throw new Error('confined browser must refuse before command execution'); + }, + async () => { + await assert.rejects( + providers.run( + { + ...context(device, 'remote-web'), + useDefaultWebProvider: true, + publicNetworkOnly: true, + }, + async () => await (await scopedWebProvider()).open('https://example.test'), + ), + (error: unknown) => + error instanceof AppError && + error.code === 'UNSUPPORTED_OPERATION' && + error.details?.reason === 'remote_web_browser_unconfined', + ); + }, + ); + assert.deepEqual(browserCalls, []); +}); + test('generic Apple runner provider cannot borrow local recording authority', async () => { await withRequestPlatformProviderScope( context(MACOS_DEVICE, 'macos-session'), diff --git a/src/platform-runtime/request-providers.ts b/src/platform-runtime/request-providers.ts index 7dd3adadd8b..ddbcf8a3fa6 100644 --- a/src/platform-runtime/request-providers.ts +++ b/src/platform-runtime/request-providers.ts @@ -159,6 +159,7 @@ async function providersForContext( stateDir: defaultWebProvider.stateDir, openWebSessionNames: defaultWebProvider.openWebSessionNames, ownedProcessRecords: defaultWebProvider.ownedProcessRecords, + ...(context.publicNetworkOnly === true ? { publicNetworkOnly: true } : {}), }); return { ...providers, diff --git a/website/docs/docs/commands.md b/website/docs/docs/commands.md index 32eb6e85af9..b23e33dff4c 100644 --- a/website/docs/docs/commands.md +++ b/website/docs/docs/commands.md @@ -551,7 +551,7 @@ agent-device close --platform web ``` - Run `web setup` before first use and in CI bootstrap. Web commands never install the backend themselves. `web doctor` verifies the install. -- Managed web sessions require a local daemon. A remote daemon refuses requests that bind a web device with `remote_web_public_network_unenforced`, including requests for an existing web session that omit `--platform web`. `close` remains available to release an existing session. +- Managed web sessions are available to local requests. A tenant request through the remote proxy or a daemon auth hook is refused when it binds a web device with `remote_web_public_network_unenforced`, including requests for an existing web session that omit `--platform web`. A remote request that reaches the managed browser without passing daemon admission is refused with `remote_web_browser_unconfined` because browser subrequests cannot be restricted to public destinations. `close` remains available to release an existing session. - Each web session has its own browser, cookies, and storage. Sessions with different `--session` names run at once. A session name is 1 to 30 letters, digits, `_`, or `-` (1 to 17 under tenant isolation); another name fails with `web_session_name_invalid`. Without `--session`, each workspace gets its own browser. - Supported: URL open, snapshot refs, `get text/attrs`, `is visible/hidden/exists/absent/focused/text`, `find text/selector`, click/press, hover, fill/type, wait, `network dump`, `audio probe`, screenshot, close, and replay scripts made from those commands. - A coordinate or selector `fill` clicks the point and replaces the field's text. When the click does not reach an editable text field, such as a date input or a field in a cross-origin frame, it fails with `text_entry_focus_not_observed` and types nothing. Run `snapshot -i` and fill the field by ref instead. diff --git a/website/docs/docs/error-reasons.md b/website/docs/docs/error-reasons.md index 1909351a8b1..4bd8765a666 100644 --- a/website/docs/docs/error-reasons.md +++ b/website/docs/docs/error-reasons.md @@ -1062,6 +1062,7 @@ These reasons can come from more than one command. | Reason | Meaning | | --- | --- | +| `remote_web_browser_unconfined` | A remote tenant's browser cannot run before its public-network proxy is enforced. | | `text-entry-result-unusable` | The batch call for a text entry answered with something other than its one echoed entry. | | `text-entry-failed` | The backend ran the fill or type entry and the page refused it. | | `snapshot-refs-unmeasurable` | Every snapshot ref failed to measure, so the capture's refs belong to no live nodes. |