Skip to main content
Menu
Advisories

The host page trusts messages from the sandbox iframes in @enclave-vm/browser

GHSA-RC2W-F9QG-WP4XPublished Updated GitHub

Description

@enclave-vm/browser runs a script in an inner iframe inside an outer iframe. The host page acted on messages from the outer iframe without checking them and enforced none of the limits itself, so every limit was only as strong as the sandbox it was meant to contain, and tool handlers received argument objects with prototype keys in them.

Details

All references are to v2.18.0, libs/browser/src/adapters/iframe-adapter.ts and iframe-protocol.ts.

  1. Messages were not validated. The host took a message by its type field and called the application's tool handler with whatever tool name and arguments it carried. The schemas in iframe-protocol.ts were never applied (and did not describe the real messages), although the documentation said every message is validated.
  2. maxToolCalls was enforced only inside the sandbox, in the realm the script runs in. The host counted nothing.
  3. Tool arguments kept __proto__, constructor and prototype keys. After a JSON round trip these are own properties. A handler that merges its arguments into another object can have its prototype changed by them. @enclave-vm/core strips these keys; the browser library did not.
  4. Results were passed on as they arrived. The returned value, the error text, the statistics and the console lines went to the caller and to the page's console without a bound on size or shape.

The fix: every message from the outer iframe is checked against the protocol and a message that does not match ends the execution (PROTOCOL_VIOLATION); the host counts tool calls and applies the configured tool-name patterns itself; a handler gets a copy of its arguments without those keys; a result is copied into plain data within the configured depth and property limits; error text, statistics and console output are bounded on the host.

Proof of concept

No reproduction is given here. Regression tests, in the private repository agentfront/enclave-security-tests: ATK-IFRAME-01 to 13 (specs/browser/host-boundary.spec.ts).

Impact

A script whose tool call carries prototype keys can change the behaviour of a tool handler that merges its arguments, in the application's own page. A script that gets control of the sandbox iframe, which the limits exist for, was not held by any of them: it could call tools without limit and with any name and arguments, and return values of any size and shape to the page.

Patches

Fixed in 2.19.0.

Workarounds

Validate tool names and arguments in the tool handler, copy arguments without __proto__, constructor and prototype keys before merging them, and count tool calls in the handler.

Affected versions

References

GitHub · agentfront/enclave