From fa7f8a50e66e5fb67232ea3b368da55bdd02fb2d Mon Sep 17 00:00:00 2001 From: Varshith Puli Date: Sat, 7 Nov 2026 14:05:43 +0000 Subject: [PATCH 01/11] fix(web): launch Chromium with its sandbox on by default The web engine launched Chromium without chromiumSandbox, so Playwright added --no-sandbox to every browser process. The agent can follow the app to another origin, so a renderer exploit on a page it reaches ran unsandboxed as the user running e2e run, with the checkout, .env, and model keys in reach. Chromium now launches with chromiumSandbox: true unless the config opts out with web({ chromiumSandbox: false }) or the run environment sets E2E_CHROMIUM_SANDBOX=0, for hosts where the sandbox cannot start (root, containers, Ubuntu 23.10+ with the AppArmor user-namespace restriction). Firefox and WebKit never receive the option. The flag resolves from the option, then the run's environment, then on; the process environment never decides a launch, per the EngineInitInfo.env contract. CI opts out explicitly because the ubuntu-2404 runners restrict unprivileged user namespaces. Docs updated next to the no-origin-allowlist note (docs/reference/web.mdx, docs/security.mdx, SECURITY.md, skills/e2e/references/setup.md) with a .changeset entry. The smol VM's --no-sandbox is unchanged: the VM is the boundary there. Verified: pnpm check green; web unit 354/354; web integration 379 passed with 3 known load flakes that pass in isolation; testbed CLI 6/6 fail with "Chromium sandboxing failed!" by default and 6/6 pass with the opt-out on this host. Fixes #1613 Signed-off-by: Varshith Puli --- .changeset/chromium-sandbox-default.md | 5 + .github/workflows/agent.yml | 5 + .github/workflows/benchmark.yml | 5 + .github/workflows/examples.yml | 5 + .github/workflows/spec.yml | 5 + SECURITY.md | 6 +- docs/reference/web.mdx | 23 ++++ docs/security.mdx | 6 +- .../tests/integration/mcp-test-run.test.ts | 4 +- packages/web/src/browser-connection.ts | 27 ++++- packages/web/src/engine.ts | 12 ++ packages/web/src/surface.ts | 45 ++++++- packages/web/tests/helpers/environment.ts | 10 ++ .../web/tests/integration/app-log.test.ts | 5 +- .../web/tests/integration/cdp-attach.test.ts | 7 +- .../tests/integration/cdp-recovery.test.ts | 3 +- .../tests/integration/clear-cookies.test.ts | 3 +- .../closed-shadow-locators.test.ts | 3 +- .../integration/concurrent-observe.test.ts | 3 +- .../web/tests/integration/evaluate.test.ts | 3 +- .../tests/integration/hidden-frames.test.ts | 3 +- .../web/tests/integration/hung-page.test.ts | 3 +- .../integration/icon-glyph-names.test.ts | 3 +- .../tests/integration/init-scripts.test.ts | 7 +- .../integration/keyboard-shadow-focus.test.ts | 3 +- .../web/tests/integration/keyboard.test.ts | 3 +- .../integration/label-composition.test.ts | 3 +- .../web/tests/integration/lifecycle.test.ts | 3 +- packages/web/tests/integration/media.test.ts | 3 +- .../tests/integration/nested-frames.test.ts | 3 +- .../web/tests/integration/permissions.test.ts | 3 +- .../tests/integration/protected-app.test.ts | 3 +- .../integration/provider-downloads.test.ts | 7 +- packages/web/tests/integration/routes.test.ts | 3 +- .../integration/screenshot-caret.test.ts | 4 +- .../integration/screenshot-navigation.test.ts | 3 +- .../integration/semantic-fallback.test.ts | 5 +- .../tests/integration/stalled-frame.test.ts | 4 +- .../integration/wait-for-response.test.ts | 3 +- packages/web/tests/types/connection.ts | 4 + packages/web/tests/unit/artifact-path.test.ts | 15 +++ .../web/tests/unit/browser-connection.test.ts | 6 +- .../unit/chromium-sandbox-surface.test.ts | 85 +++++++++++++ .../web/tests/unit/chromium-sandbox.test.ts | 114 ++++++++++++++++++ .../tests/unit/protected-app-options.test.ts | 2 +- .../web/tests/unit/surface-lifecycle.test.ts | 3 +- plugins/e2e/skills/e2e/references/setup.md | 1 + skills/e2e/references/setup.md | 1 + 48 files changed, 438 insertions(+), 47 deletions(-) create mode 100644 .changeset/chromium-sandbox-default.md create mode 100644 packages/web/tests/helpers/environment.ts create mode 100644 packages/web/tests/unit/chromium-sandbox-surface.test.ts create mode 100644 packages/web/tests/unit/chromium-sandbox.test.ts diff --git a/.changeset/chromium-sandbox-default.md b/.changeset/chromium-sandbox-default.md new file mode 100644 index 0000000000..7c25b6da87 --- /dev/null +++ b/.changeset/chromium-sandbox-default.md @@ -0,0 +1,5 @@ +--- +"@e2e-dev/web": patch +--- + +Chromium launches with its OS sandbox on by default, so a renderer exploit on a page the agent reaches stays contained instead of running as the user running `e2e run`. `web({ chromiumSandbox: false })` or `E2E_CHROMIUM_SANDBOX=0` turns it off on a host where the sandbox cannot start. diff --git a/.github/workflows/agent.yml b/.github/workflows/agent.yml index 4f16e23388..b3b75133ce 100644 --- a/.github/workflows/agent.yml +++ b/.github/workflows/agent.yml @@ -36,6 +36,11 @@ on: # The repository's own runs are not usage: the CLI sends no telemetry from CI here. env: E2E_TELEMETRY_DISABLED: '1' + # The ubuntu-2404 runners restrict unprivileged user namespaces, so + # Chromium cannot start with its sandbox on; the web engine defaults to + # sandboxed launches, and CI opts out explicitly rather than failing at + # browser launch. + E2E_CHROMIUM_SANDBOX: '0' permissions: contents: read diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index c228dbd097..be2b6d406b 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -32,6 +32,11 @@ on: # The repository's own runs are not usage: the CLI sends no telemetry from CI here. env: E2E_TELEMETRY_DISABLED: '1' + # The ubuntu-2404 runners restrict unprivileged user namespaces, so + # Chromium cannot start with its sandbox on; the web engine defaults to + # sandboxed launches, and CI opts out explicitly rather than failing at + # browser launch. + E2E_CHROMIUM_SANDBOX: '0' permissions: contents: read diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml index 760a0dbcd8..f3355132f1 100644 --- a/.github/workflows/examples.yml +++ b/.github/workflows/examples.yml @@ -35,6 +35,11 @@ on: env: # The repository's own runs are not usage: the CLI sends no telemetry from CI here. E2E_TELEMETRY_DISABLED: '1' + # The ubuntu-2404 runners restrict unprivileged user namespaces, so + # Chromium cannot start with its sandbox on; the web engine defaults to + # sandboxed launches, and CI opts out explicitly rather than failing at + # browser launch. + E2E_CHROMIUM_SANDBOX: '0' permissions: contents: read diff --git a/.github/workflows/spec.yml b/.github/workflows/spec.yml index b6285d43ef..28004f5066 100644 --- a/.github/workflows/spec.yml +++ b/.github/workflows/spec.yml @@ -17,6 +17,11 @@ on: # The repository's own runs are not usage: the CLI sends no telemetry from CI here. env: E2E_TELEMETRY_DISABLED: '1' + # The ubuntu-2404 runners restrict unprivileged user namespaces, so + # Chromium cannot start with its sandbox on; the web engine defaults to + # sandboxed launches, and CI opts out explicitly rather than failing at + # browser launch. + E2E_CHROMIUM_SANDBOX: '0' permissions: contents: read diff --git a/SECURITY.md b/SECURITY.md index 912e28a0b1..cc7dca50b1 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -74,7 +74,11 @@ against a model mistake at the cost of configuring every sign-in flow that leaves the app's domain. Treat a target whose app can send the agent elsewhere as one the agent may follow there, with the secrets the step was given. If a threat model ever calls for an origin allowlist again, it comes -back as an opt-in. +back as an opt-in. Chromium launches with its OS sandbox on, so a renderer +exploit on a page the agent reaches stays contained by the sandbox instead +of running as the user running `e2e run`; `web({ chromiumSandbox: false })` +or `E2E_CHROMIUM_SANDBOX=0` turns it off on a host where the sandbox cannot +start. Child frames off the site of the target's `url`, its registrable domain, are dropped from observations. The browser engine's `headers` and `basicAuth` diff --git a/docs/reference/web.mdx b/docs/reference/web.mdx index 375a9bbb56..42a1f64384 100644 --- a/docs/reference/web.mdx +++ b/docs/reference/web.mdx @@ -48,6 +48,7 @@ web({ viewport: { width: 390, height: 844 }, locale: 'de-DE' }); | Option | Type | Default | | --- | --- | --- | | [`browser`](#browser) | `BrowserName \| BrowserProvider` | `'chromium'` | +| [`chromiumSandbox`](#chromiumsandbox) | `boolean` | `true` | | [`viewport`](#viewport) | `ViewportSize \| null` | 1280 by 720 | | [`screencast`](#screencast) | `WebScreencastOptions` | the viewport's size | | [`connect`](#connect) | `WebConnectOptions` | launches locally | @@ -98,6 +99,28 @@ web({ browser: 'firefox' }); // default: 'chromium' | --- | --- | | `INVALID_CONFIG` | `browser: provider` together with `connect`. | +#### `chromiumSandbox` + +Whether Chromium launches with its OS sandbox on. + +```ts +web({ chromiumSandbox: false }); // default: true +``` + +- The agent can follow the app to another origin, so a renderer exploit on a + page it reaches stays contained by the sandbox instead of running as the + user running `e2e run`. +- Set `false` only on a host where the sandbox cannot start (root, a + container, or Ubuntu 23.10+ with `kernel.apparmor_restrict_unprivileged_userns=1`): + leaving it on there fails the launch with Playwright's "Chromium sandboxing failed!" + error. `E2E_CHROMIUM_SANDBOX=0` in the environment is the same + opt-out; an explicit option wins over the variable. +- Firefox and WebKit ignore it. + +| Throws | When | +| --- | --- | +| `INVALID_CONFIG` | Any value that is not a boolean, at config load. | + #### `viewport` The initial viewport of every attempt's page. diff --git a/docs/security.mdx b/docs/security.mdx index f916632533..29b3e93375 100644 --- a/docs/security.mdx +++ b/docs/security.mdx @@ -57,7 +57,11 @@ The model acts only through tools. The runner checks each call against a closed schema before it runs, and never evaluates model text as code. A call that breaks a rule, such as a navigation to `file:`, fails with `POLICY_DENIED`. There is no origin allowlist: the agent can follow the app -to another site and use the step's secrets there. +to another site and use the step's secrets there. Chromium launches with its +OS sandbox on, so a renderer exploit on a page the agent reaches stays +contained by the sandbox instead of running as the user running `e2e run`; +`web({ chromiumSandbox: false })` or `E2E_CHROMIUM_SANDBOX=0` turns it off on +a host where the sandbox cannot start. ## What runs with your permissions diff --git a/packages/e2e/tests/integration/mcp-test-run.test.ts b/packages/e2e/tests/integration/mcp-test-run.test.ts index b6f3bccebd..1a55e2ea93 100644 --- a/packages/e2e/tests/integration/mcp-test-run.test.ts +++ b/packages/e2e/tests/integration/mcp-test-run.test.ts @@ -391,7 +391,9 @@ describe('open_session {test}', { timeout: 120_000 }, () => { configPath, }), loadEngineConfig: () => Promise.reject(new Error('these sessions open on the config')), - env: {}, + // The run's environment carries the sandbox flag: on a host whose + // sandbox cannot start, the workflow sets E2E_CHROMIUM_SANDBOX=0. + env: { E2E_CHROMIUM_SANDBOX: process.env['E2E_CHROMIUM_SANDBOX'] }, headed: false, log: () => undefined, }); diff --git a/packages/web/src/browser-connection.ts b/packages/web/src/browser-connection.ts index d3b4958a0b..ff7bba18d6 100644 --- a/packages/web/src/browser-connection.ts +++ b/packages/web/src/browser-connection.ts @@ -38,6 +38,16 @@ export function isBrowserName(name: string): name is BrowserName { */ const RUNNER_OWNS_SIGNALS = { handleSIGINT: false, handleSIGTERM: false } as const; +/** + * The `E2E_CHROMIUM_SANDBOX` flag's value when it is set and not blank, + * lowercased; undefined otherwise. `0` and `false` turn the sandbox off, the + * same way `CI` is read; anything else leaves it on. + */ +export function readChromiumSandboxFlag(env: Readonly>): string | undefined { + const value = env['E2E_CHROMIUM_SANDBOX']?.trim().toLowerCase(); + return value !== undefined && value !== '' ? value : undefined; +} + /** * Launching a browser process costs hundreds of milliseconds; per-attempt * isolation lives in browser contexts, so every attempt a worker runs can @@ -53,19 +63,23 @@ export class BrowserConnection { * When `connect` is given the connection attaches to a remote browser through it * instead of launching a local one; `connect` is re-invoked on a relaunch, * so a caller that resolves a fresh per-run endpoint reconnects cleanly - * after a dropped session. + * after a dropped session. `chromiumSandbox` is Chromium's sandbox, and + * the caller passes the resolved value: the `web({ chromiumSandbox })` + * option, the run's environment, or on. Only a Chromium launch takes it, + * and a relaunch keeps the value the first launch used. */ async acquire( name: BrowserName, headed: boolean, timeoutMs: number, + chromiumSandbox: boolean, connect?: () => Promise, ): Promise { const cached = this.pending; if (cached !== undefined) { const browser = await cached.catch(() => null); if (browser !== null && browser.isConnected()) return browser; - if (this.pending !== cached) return this.acquire(name, headed, timeoutMs, connect); + if (this.pending !== cached) return this.acquire(name, headed, timeoutMs, chromiumSandbox, connect); this.pending = undefined; } // Set before anything awaits: the first call loads Playwright, and a `dispose` @@ -74,7 +88,14 @@ export class BrowserConnection { const launching = registerSelectorEngines().then(() => connect !== undefined ? connect() - : browserType(name).then((type) => type.launch({ headless: !headed, timeout: timeoutMs, ...RUNNER_OWNS_SIGNALS })), + : browserType(name).then((type) => + type.launch({ + headless: !headed, + timeout: timeoutMs, + ...RUNNER_OWNS_SIGNALS, + ...(name === 'chromium' ? { chromiumSandbox } : {}), + }), + ), ); this.pending = launching; try { diff --git a/packages/web/src/engine.ts b/packages/web/src/engine.ts index 76106754ce..c0c0ae0ec6 100644 --- a/packages/web/src/engine.ts +++ b/packages/web/src/engine.ts @@ -86,6 +86,7 @@ export function web(options: WebOptions = {}): EngineHandle { if (options.basicAuth !== undefined) validateBasicAuth(options.basicAuth); if (options.credentialOrigins !== undefined) validateCredentialOrigins(options); if (options.testIdAttribute !== undefined) validateTestIdAttribute(options.testIdAttribute); + if (options.chromiumSandbox !== undefined) validateChromiumSandbox(options.chromiumSandbox); if (options.userAgent !== undefined) validateUserAgent(options.userAgent, options.headers); if (options.locale !== undefined) validateLocale(options.locale, options.headers); if (options.timezoneId !== undefined) validateTimezoneId(options.timezoneId); @@ -167,6 +168,7 @@ export function web(options: WebOptions = {}): EngineHandle { /** Every option `web()` takes, kept equal to `WebOptions` by the compiler. */ const WEB_OPTION_KEYS: readonly string[] = Object.keys({ browser: true, + chromiumSandbox: true, viewport: true, screencast: true, connect: true, @@ -428,6 +430,16 @@ function validateTestIdAttribute(attribute: unknown): void { } } +/** Refuses a sandbox opt-out that is not a boolean, at config load. */ +function validateChromiumSandbox(chromiumSandbox: unknown): void { + if (typeof chromiumSandbox !== 'boolean') { + throw new ConfigurationError( + 'INVALID_CONFIG', + `web({ chromiumSandbox }) must be a boolean, got ${JSON.stringify(chromiumSandbox)}`, + ); + } +} + /** * A browser target opens a URL: without `app.url` there is nothing for * `app.open()` to open, and the fields that describe an installed device app diff --git a/packages/web/src/surface.ts b/packages/web/src/surface.ts index 2bde0c5b4f..3c35286128 100644 --- a/packages/web/src/surface.ts +++ b/packages/web/src/surface.ts @@ -43,7 +43,7 @@ import { } from 'e2e/engine'; import { matchesText } from 'e2e/engine'; import { classifyActionError, classifyInputError, dispatchLocatorAction, dispatchPointerAction } from './actions.ts'; -import { BrowserConnection, connectCdp, type BrowserName } from './browser-connection.ts'; +import { BrowserConnection, connectCdp, readChromiumSandboxFlag, type BrowserName } from './browser-connection.ts'; import { AttemptSession, type AttemptTab, type StorageState } from './attempt-session.ts'; import type { CdpEndpointResolver } from './cdp-recovery.ts'; import { LeasedBrowsers, type BrowserProvider, type LeaseDownloads } from './provider.ts'; @@ -174,6 +174,19 @@ export interface WebOptions { * provider implies chromium and excludes `connect`. */ readonly browser?: BrowserName | BrowserProvider; + /** + * Whether Chromium launches with its OS sandbox on, `true` by default. + * The agent can follow the app to another origin, so a renderer exploit + * on a page it reaches stays contained by the sandbox instead of running + * as the user running `e2e run`. Set `false` only on a host where the + * sandbox cannot start (root, a container, or Ubuntu 23.10+ with + * `kernel.apparmor_restrict_unprivileged_userns=1`): leaving it on there + * fails the launch with Playwright's "Chromium sandboxing failed!" error. + * The same opt-out is `E2E_CHROMIUM_SANDBOX=0` in the run's environment, + * and an explicit option wins over the variable. Firefox and WebKit + * ignore it. + */ + readonly chromiumSandbox?: boolean; /** * Initial viewport of every attempt's page; default 1280 by 720. `null` * emulates no size: the page fills the browser window, whatever size the @@ -283,6 +296,22 @@ export interface WebOptions { /** The test-id attribute when the options name none. */ const DEFAULT_TEST_ID_ATTRIBUTE = 'data-testid'; +/** + * Whether Chromium launches with its sandbox on: an explicit option wins, + * then the run's environment, then on. The run's environment is the only + * environment read here: an in-process worker shares its process with the + * runner and every other target, so the process environment never decides + * a launch. + */ +function resolveChromiumSandbox( + configured: boolean | undefined, + env: Readonly>, +): boolean { + if (configured !== undefined) return configured; + const value = readChromiumSandboxFlag(env); + return value === undefined || (value !== '0' && value !== 'false'); +} + export class PlaywrightSurface { /** * Errors raised where nobody awaits them (dialog routing, route handlers) @@ -293,6 +322,10 @@ export class PlaywrightSurface { private readonly browserName: BrowserName; private readonly connection = new BrowserConnection(); + /** The sandbox opt-out the options name, if any; the run's environment decides the rest at `init`. */ + private readonly configuredChromiumSandbox: boolean | undefined; + /** Whether the shared Chromium launches with its sandbox on, resolved at `init`. */ + private chromiumSandbox = true; private readonly connect: WebConnectOptions | undefined; /** The provider's browsers, when `browser` names one; the runner and worker halves of the lease bookkeeping. */ private readonly leases: LeasedBrowsers | undefined; @@ -336,6 +369,7 @@ export class PlaywrightSurface { constructor(options: WebOptions) { this.browserName = typeof options.browser === 'string' ? options.browser : 'chromium'; + this.configuredChromiumSandbox = options.chromiumSandbox; this.leases = typeof options.browser === 'object' && options.browser !== null ? new LeasedBrowsers(options.browser) : undefined; this.connect = options.connect; this.viewport = options.viewport === undefined ? DEFAULT_VIEWPORT : options.viewport; @@ -394,6 +428,7 @@ export class PlaywrightSurface { this.credentialScope = credentialOrigins(info.app.origin, this.credentialOrigins); this.projectRoot = info.projectRoot; this.headed = info.headed; + this.chromiumSandbox = resolveChromiumSandbox(this.configuredChromiumSandbox, info.env); this.leases?.init(info); // The browser was installed in `prepare`; a launch or attach is the one // boot step left that can outlive a launch budget, and it honours the @@ -422,7 +457,13 @@ export class PlaywrightSurface { if (signal.aborted) throw cancelled(`browser ${verb} cancelled`); try { return await raceAbort( - this.connection.acquire(this.browserName, this.headed, BROWSER_LAUNCH_TIMEOUT_MS, this.connector(signal)), + this.connection.acquire( + this.browserName, + this.headed, + BROWSER_LAUNCH_TIMEOUT_MS, + this.chromiumSandbox, + this.connector(signal), + ), signal, `browser ${verb}`, ); diff --git a/packages/web/tests/helpers/environment.ts b/packages/web/tests/helpers/environment.ts new file mode 100644 index 0000000000..ae45a282e7 --- /dev/null +++ b/packages/web/tests/helpers/environment.ts @@ -0,0 +1,10 @@ +/** + * The environment a test that launches a real browser hands to `init`: + * only the sandbox flag, forwarded from the ambient shell. The engine + * reads the flag from the run's environment only, so the workflow opt-out + * (`E2E_CHROMIUM_SANDBOX=0` on a host whose sandbox cannot start) reaches + * the launch this way; nothing else from the process environment leaks in. + */ +export function browserTestEnv(): Record { + return { E2E_CHROMIUM_SANDBOX: process.env['E2E_CHROMIUM_SANDBOX'] }; +} diff --git a/packages/web/tests/integration/app-log.test.ts b/packages/web/tests/integration/app-log.test.ts index 5727205844..c88ca575f8 100644 --- a/packages/web/tests/integration/app-log.test.ts +++ b/packages/web/tests/integration/app-log.test.ts @@ -17,6 +17,7 @@ import { afterAll, beforeAll, describe, expect, it } from 'vitest'; import type { AppLogEntry, EngineCleanupContext, EngineFixtureContext, EngineSnapshot, OperationContext } from 'e2e/engine'; import { createBrowserFixture } from '../../src/browser.ts'; import { PlaywrightSurface } from '../../src/surface.ts'; +import { browserTestEnv } from '../helpers/environment.ts'; import { ignoreTrace, noSecrets } from '../helpers/secrets.ts'; const PAGE = `

Todos