The host page trusts messages from the sandbox iframes in @enclave-vm/browser
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.
- Messages were not validated. The host took a message by its
typefield and called the application's tool handler with whatever tool name and arguments it carried. The schemas iniframe-protocol.tswere never applied (and did not describe the real messages), although the documentation said every message is validated. maxToolCallswas enforced only inside the sandbox, in the realm the script runs in. The host counted nothing.- Tool arguments kept
__proto__,constructorandprototypekeys. 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/corestrips these keys; the browser library did not. - 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.