Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/actions/setup-node-pnpm/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ runs:
id: package-manager
run: |
set -euo pipefail
spec="$(node -p "require('$GITHUB_WORKSPACE/package.json').packageManager ?? ''")"
spec="$(node -p "require(require('node:path').join(process.env.GITHUB_WORKSPACE, 'package.json')).packageManager ?? ''")"
case "$spec" in
pnpm@[0-9]*) ;;
*)
Expand Down
43 changes: 43 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -467,3 +467,46 @@ jobs:
if-no-files-found: ignore
path: |
test/artifacts/web/**

web-confinement-platforms:
name: Web Confinement (${{ matrix.os }})
runs-on: ${{ matrix.os }}
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
os: [macos-26, windows-latest]
steps:
- name: Checkout
uses: useblacksmith/checkout@2b9fe87d796feea153b455ec2f3125b471a7b0e7 # v1.8.2

- name: Setup toolchain
uses: ./.github/actions/setup-node-pnpm

- name: Fetch the PR base for web smoke selection
if: github.event_name == 'pull_request'
shell: bash
env:
BASE_SHA: ${{ github.event.pull_request.base.sha }}
run: git fetch origin "$BASE_SHA" --depth=1 || echo "Base fetch failed; web smoke selection will fail open."

- name: Select web smoke tests
id: web-impact
shell: bash
env:
BASE_SHA: ${{ github.event.pull_request.base.sha }}
run: node --experimental-strip-types scripts/device-lane-impact.ts web-smoke

- name: Run confined browser host-boundary smoke
if: steps.web-impact.outputs.run != 'false' && matrix.os != 'windows-latest'
shell: bash
env:
AGENT_DEVICE_WEB_E2E: '1'
run: pnpm test:smoke:web

- name: Prove Windows remote web refusal
if: steps.web-impact.outputs.run != 'false' && matrix.os == 'windows-latest'
shell: bash
env:
AGENT_DEVICE_WEB_E2E: '1'
run: node --test packages/platform-web/test/integration/smoke-web-confinement.test.ts
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@
"test:fixture-cache": "node --experimental-strip-types scripts/node-test-tmpdir.ts --test test/ci/trusted-fixture-artifact.test.mjs",
"test:fixture-fallback": "sh ./test/scripts/setup-fixture-app-fallback-smoke.sh",
"test:output-economy": "vitest run --project output-economy",
"test:smoke:web": "pnpm build && node --experimental-strip-types scripts/node-test-tmpdir.ts --test test/integration/smoke-web-platform.test.ts",
"test:smoke:web": "pnpm build && node --experimental-strip-types scripts/node-test-tmpdir.ts --test --test-concurrency=1 test/integration/smoke-web-platform.test.ts packages/platform-web/test/integration/smoke-web-confinement.test.ts",
"test:smoke": "node --experimental-strip-types scripts/node-test-tmpdir.ts --test test/integration/smoke-*.test.ts",
"test:integration:node": "node --experimental-strip-types scripts/node-test-tmpdir.ts --test --experimental-test-isolation=none test/integration/*.test.ts",
"test:integration:macos-coverage": "node --experimental-strip-types scripts/node-test-tmpdir.ts --test test/integration/smoke-macos-coverage.test.ts",
Expand Down
1 change: 1 addition & 0 deletions packages/contracts/src/managed-web-backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export type ManagedWebBackendStatus = Readonly<{
homeDir: string;
runtimeHomeDir: string;
socketDir: string;
publicNetworkOnly?: true;
installed: boolean;
nodeMajor: number;
nodeSupported: boolean;
Expand Down
2 changes: 2 additions & 0 deletions packages/contracts/src/platform-providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type { SessionSurface } from './session-surface.ts';
export type PlatformProviderRequestSession = Readonly<{
name: string;
device: DeviceInfo;
webConfinement?: 'public-network';
appBundleId?: string;
appName?: string;
surface?: SessionSurface;
Expand All @@ -22,6 +23,7 @@ export type PlatformProviderRequestContext = Readonly<{
session?: PlatformProviderRequestSession;
requestedSession?: string;
requestId?: string;
command?: 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. */
Expand Down
1 change: 1 addition & 0 deletions packages/daemon/src/core/platform-resource-cleanup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export type PlatformResourceCleanup = Readonly<{
params: Readonly<{
/** The web session device whose browser closes; its id carries the backend key. */
device: DeviceInfo;
publicNetworkOnly?: true;
stateDir: string;
/** The backend keys of the published web sessions. */
openSessionNames: () => readonly string[];
Expand Down
2 changes: 2 additions & 0 deletions packages/daemon/src/core/session-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ export type SessionRef = Readonly<{

export type SessionState = {
name: string;
/** Managed browser network policy fixed when this web session was opened. */
webConfinement?: 'public-network';
sessionScope?: SessionScope;
lease?: {
leaseId: string;
Expand Down
4 changes: 4 additions & 0 deletions packages/daemon/src/core/session-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ export class SessionStore {
return next;
}

setWebConfinement(ref: SessionRef, confinement: SessionState['webConfinement']): void {
this.update(ref, { webConfinement: confinement });
}

retire(ref: SessionRef, options: { retainExecutionHost?: boolean } = {}): boolean {
const session = this.resolveCurrent(ref);
if (!session) return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import fs from 'node:fs';
import path from 'node:path';
import { beforeEach, expect, test, vi } from 'vitest';
import { createTestDeviceInventoryGateways } from '@agent-device/device-selection/inventory-gateways-fixtures';
import { AppError } from '@agent-device/kernel/errors';
import {
webSessionDevice,
type DeviceInfo,
Expand Down Expand Up @@ -194,7 +195,99 @@ test('remote web open is refused before a browser runtime binds', async () => {
expect(store.toArray()).toEqual([]);
});

test('remote requests cannot use an existing web session without a platform flag', async () => {
test('remote web open remains refused with a configured provider scope', async () => {
mockResolveTargetDevice.mockImplementation(webSessionResolution);
const store = makeSessionStore('agent-device-remote-web-confined-');
const handler = createRequestHandler({
host: createTestHostEnvironment(),
createCommandSurface: fakeCreateCommandSurface,
logPath: path.join(mkdtempForTestSync('daemon'), 'daemon.log'),
token: 'test-token',
sessionStore: store,
leaseRegistry: new LeaseRegistry(),
deviceRuntimeGateway: lifecycleDeviceRuntimeGateway,
deviceInventoryGateways: createTestDeviceInventoryGateways(),
trackDownloadableArtifact: () => 'artifact-id',
requestPlatformProviders: {
hasConfiguredResolvers: true,
run: async (_context, task) => await task({}),
},
});
const result = await handler({
...openWebRequest('remote-web-confined'),
internal: { publicNetworkOnly: true },
});
expect(result).toMatchObject({
ok: false,
error: {
code: 'UNSUPPORTED_OPERATION',
details: { reason: 'remote_web_public_network_unenforced' },
},
});
expect(store.toArray()).toEqual([]);
});

test('remote reads of an existing confined session remain refused', async () => {
const store = makeSessionStore('agent-device-confined-web-read-denied-');
store.publish('confined-web', {
...makeSession('confined-web', { device: WEB_DESKTOP_DEVICE }),
webConfinement: 'public-network',
});
const bind = vi.fn(lifecycleDeviceRuntimeGateway.bind);
const handler = createOpenHandler(store, new LeaseRegistry(), {
...lifecycleDeviceRuntimeGateway,
bind,
});
const result = await handler({
...openWebRequest('confined-web'),
command: 'snapshot',
positionals: [],
flags: {},
internal: { publicNetworkOnly: true },
});
expect(result).toMatchObject({
ok: false,
error: {
code: 'UNSUPPORTED_OPERATION',
details: { reason: 'remote_web_public_network_unenforced' },
},
});
expect(bind).not.toHaveBeenCalled();
expect(store.get('confined-web')).toBeDefined();
});

test('a confined session remains available for a retried close after backend failure', async () => {
const store = makeSessionStore('agent-device-confined-web-close-retry-');
const name = 'confined-web';
store.publish(name, {
...makeSession(name, { device: WEB_DESKTOP_DEVICE }),
webConfinement: 'public-network',
});
const closeApplication = vi.fn(async () => {});
closeApplication.mockRejectedValueOnce(new AppError('COMMAND_FAILED', 'Close unconfirmed'));
const handler = createOpenHandler(store, new LeaseRegistry(), {
...lifecycleDeviceRuntimeGateway,
bind: async (request) => {
const bound = await lifecycleDeviceRuntimeGateway.bind(request);
return { ...bound, operations: { ...bound.operations, closeApplication } };
},
});
const request = {
...openWebRequest(name),
command: 'close',
positionals: [],
flags: {},
internal: { publicNetworkOnly: true },
} satisfies DaemonRequest;

expect(await handler(request)).toMatchObject({ ok: false });
expect(store.get(name)).toMatchObject({ webConfinement: 'public-network' });
expect(await handler(request)).toMatchObject({ ok: true });
expect(closeApplication).toHaveBeenCalledTimes(2);
expect(store.get(name)).toBeUndefined();
});

test('remote requests cannot adopt an existing local 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 }));
Expand Down Expand Up @@ -223,6 +316,87 @@ test('remote requests cannot use an existing web session without a platform flag
expect(binds).toBe(0);
});

test('local requests cannot adopt an existing confined web session', async () => {
mockResolveTargetDevice.mockImplementation(webSessionResolution);
const store = makeSessionStore('agent-device-confined-web-existing-');
store.publish('confined-web', {
...makeSession('confined-web', { device: WEB_DESKTOP_DEVICE }),
webConfinement: 'public-network',
});
const handler = createOpenHandler(store);
const result = await handler({
token: 'test-token',
session: 'confined-web',
command: 'snapshot',
positionals: [],
flags: {},
meta: { requestId: 'local-existing-confined-web', sessionExplicit: true },
});
expect(result).toMatchObject({
ok: false,
error: { details: { reason: 'remote_web_session_confinement_mismatch' } },
});
});

test('a queued remote request cannot adopt a local session published while it waits', async () => {
mockResolveTargetDevice.mockImplementation(webSessionResolution);
const store = makeSessionStore('agent-device-confined-web-race-');
let releaseOpen!: () => void;
let signalOpenBound!: () => void;
let firstBind = true;
const openBound = new Promise<void>((resolve) => {
signalOpenBound = resolve;
});
const holdOpen = new Promise<void>((resolve) => {
releaseOpen = resolve;
});
const handler = createRequestHandler({
host: createTestHostEnvironment(),
createCommandSurface: fakeCreateCommandSurface,
logPath: path.join(mkdtempForTestSync('daemon'), 'daemon.log'),
token: 'test-token',
sessionStore: store,
leaseRegistry: new LeaseRegistry(),
deviceRuntimeGateway: {
...lifecycleDeviceRuntimeGateway,
bind: async (request) => {
if (firstBind) {
firstBind = false;
signalOpenBound();
await holdOpen;
}
return await lifecycleDeviceRuntimeGateway.bind(request);
},
},
deviceInventoryGateways: createTestDeviceInventoryGateways(),
trackDownloadableArtifact: () => 'artifact-id',
requestPlatformProviders: {
hasConfiguredResolvers: true,
run: async (_context, task) => await task({}),
},
});
const opening = handler({
...openWebRequest('raced-web'),
meta: { requestId: 'local-open', sessionExplicit: true },
});
await openBound;
const remote = handler({
token: 'test-token',
session: 'raced-web',
command: 'snapshot',
positionals: [],
flags: {},
meta: { requestId: 'remote-after-open', sessionExplicit: true },
internal: { publicNetworkOnly: true },
});
releaseOpen();
expect(await opening).toMatchObject({ ok: true });
expect(await remote).toMatchObject({
ok: false,
error: { details: { reason: 'remote_web_public_network_unenforced' } },
});
});

test('remote close can release an existing web session', async () => {
mockResolveTargetDevice.mockImplementation(webSessionResolution);
const store = makeSessionStore('agent-device-remote-web-close-');
Expand Down
25 changes: 22 additions & 3 deletions packages/daemon/src/server/remote-host-input-policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,30 @@ 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' },
// The managed browser cannot confine a remote tenant's requests to public destinations.
// Remote web admission lacks verified browser-lifetime confinement.
webNetworkUnenforced: { reason: 'remote_web_public_network_unenforced' },
// A request tried to reuse a web session opened under the other browser network policy.
webConfinementMismatch: { reason: 'remote_web_session_confinement_mismatch' },
} as const satisfies ReasonTable<'remote daemon'>;

/** Remote browser traffic cannot be restricted at connection time by the managed web backend. */
export function assertWebSessionConfinement(
request: DaemonRequest,
device: DeviceInfo,
existing: { webConfinement?: 'public-network' } | undefined,
): void {
if (device.platform !== 'web' || request.command === 'close' || !existing) return;
if (
(existing.webConfinement === 'public-network') ===
(request.internal?.publicNetworkOnly === true)
)
return;
throw new AppError('UNSUPPORTED_OPERATION', 'The web session has a different network policy.', {
reason: REMOTE_HOST_INPUT_REASONS.webConfinementMismatch.reason,
retriable: false,
});
}

/** Refuse remote web admission until browser-lifetime confinement is verified. */
export function assertRemoteWebDeviceAdmitted(request: DaemonRequest, device: DeviceInfo): void {
if (
!request.internal?.publicNetworkOnly ||
Expand All @@ -26,7 +45,7 @@ export function assertRemoteWebDeviceAdmitted(request: DaemonRequest, device: De
}
throw new AppError(
'UNSUPPORTED_OPERATION',
'Remote web sessions are unavailable because the managed browser cannot enforce public-network access.',
'Remote web sessions are disabled until browser-lifetime network confinement is verified.',
{ reason: REMOTE_HOST_INPUT_REASONS.webNetworkUnenforced.reason, retriable: false },
);
}
Expand Down
Loading
Loading