Closed Bug 2059668 Opened 2 months ago Closed 1 month ago

Add sandbox option to evaluate_script

Categories

(Developer Infrastructure :: Firefox MCP, enhancement)

enhancement

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: r.majdodin, Unassigned)

References

(Blocks 1 open bug)

Details

Attachments

(1 file)

evaluate_script always evaluates in the page's own realm: script.ts sends
target: { context } and never the optional "sandbox" field that WebDriver
BiDi's script.callFunction target already accepts.

That has two costs for an agent debugging a page:

  1. Inspection can be defeated by the page. If the page has overwritten
    querySelector, a getter, or Array.prototype methods - deliberately or as
    part of the bug under investigation - every evaluate_script result is
    filtered through the tampered code. Verified on Firefox 153: against a
    page that replaces document.querySelector, evaluate_script returns the
    replacement's answers.

  2. Evaluation is invasive. Anything the function leaves on the global leaks
    into the page and can perturb the behavior being debugged.

Firefox already implements the remedy: target: { context, sandbox: "name" }
makes the Remote Agent evaluate in a sandbox realm
(remote/shared/Realm.sys.mjs - Cu.Sandbox over the window with
wantXrays: true). Same principal as the page, so no privilege change - but
Xray wrappers show the native view of the DOM, and writes stay invisible to
the page. The same name reuses the realm across calls, so state persists;
different names are mutually isolated. This is the engine's equivalent of
the "isolated world" other DevTools stacks expose.

Proposal: an optional "sandbox" string parameter on evaluate_script, passed
through to the BiDi target. Omitted, behavior is unchanged.

Related: bug 2057981 (raw BiDi command escape hatch) would also reach
sandbox realms, but a first-class parameter keeps the common case - reading
a page without trusting or disturbing it - one tool call with no protocol
knowledge required.

Status: UNCONFIRMED → RESOLVED
Closed: 1 month ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: