Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

fix(cua-driver): reject malformed tool arguments found by fuzzing (#3777)

Francesco Bonacci38f56e4ae5c0
diff --git a/.github/workflows/fuzz-cua-driver.yml b/.github/workflows/fuzz-cua-driver.yml
new file mode 100644
index 0000000000..a8a0afdc15
--- /dev/null
+++ b/.github/workflows/fuzz-cua-driver.yml
@@ -0,0 +1,124 @@
+name: "Fuzz: Cua Driver tool-call boundary"
+
+# Coverage-guided fuzzing of the transport-free MCP tool-call boundary in
+# cua-driver-core. The target bodies live in cua_driver_testkit::boundary_fuzz
+# and also run as bounded smoke tests in the ordinary Rust CI; this workflow
+# gives libFuzzer a real time budget and surfaces any crash as a failed job
+# with the reproducing input attached. See libs/cua-driver/rust/fuzz/README.md.
+
+on:
+ pull_request:
+ paths:
+ - "libs/cua-driver/rust/Cargo.toml"
+ - "libs/cua-driver/rust/Cargo.lock"
+ - "libs/cua-driver/rust/crates/cua-driver-contract/**"
+ - "libs/cua-driver/rust/crates/cua-driver-core/**"
+ - "libs/cua-driver/rust/crates/cua-driver-testkit/**"
+ - "libs/cua-driver/rust/fuzz/**"
+ - ".github/workflows/fuzz-cua-driver.yml"
+ schedule:
+ # Nightly long run against main.
+ - cron: "17 3 * * *"
+ workflow_dispatch:
+ inputs:
+ max_total_time:
+ description: "Seconds of fuzzing per target"
+ default: "600"
+ required: false
+
+permissions:
+ contents: read
+
+concurrency:
+ group: fuzz-cua-driver-${{ github.workflow }}-${{ github.ref }}
+ cancel-in-progress: true
+
+jobs:
+ fuzz:
+ name: ${{ matrix.target }}
+ runs-on: ubuntu-latest
+ timeout-minutes: 45
+ strategy:
+ fail-fast: false
+ matrix:
+ target:
+ - mcp_request
+ - tool_arguments
+ - typed_input_json
+ - registry_invoke
+ env:
+ # Pull requests get a short budget so the check stays fast; the nightly
+ # schedule and manual dispatch run longer.
+ MAX_TOTAL_TIME: >-
+ ${{ github.event_name == 'pull_request' && '120'
+ || github.event_name == 'workflow_dispatch' && inputs.max_total_time
+ || '900' }}
+ steps:
+ - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
+ - uses: dtolnay/rust-toolchain@stable
+ - uses: Swatinem/rust-cache@9d47c6ad4b02e050fd481d890b2ea34778fd09d6 # v2
+ with:
+ workspaces: |
+ libs/cua-driver/rust -> target
+ libs/cua-driver/rust/fuzz -> target
+ - name: Install cargo-fuzz
+ run: cargo install cargo-fuzz --locked
+
+ - name: Build fuzz target
+ working-directory: libs/cua-driver/rust
+ # The workspace pins a stable toolchain; sanitizers need nightly, but
+ # libFuzzer's coverage instrumentation does not.
+ run: cargo fuzz build --fuzz-dir fuzz --sanitizer none ${{ matrix.target }}
+
+ - name: Run libFuzzer
+ id: run
+ working-directory: libs/cua-driver/rust
+ run: |
+ set -o pipefail
+ mkdir -p "fuzz/work/${{ matrix.target }}"
+ cargo fuzz run --fuzz-dir fuzz --sanitizer none ${{ matrix.target }} \
+ "fuzz/work/${{ matrix.target }}" "fuzz/corpus/${{ matrix.target }}" \
+ -- -max_total_time="$MAX_TOTAL_TIME" -max_len=4096 -print_final_stats=1 \
+ 2>&1 | tee "fuzz/${{ matrix.target }}.log"
+
+ - name: Summarise result
+ if: always()
+ working-directory: libs/cua-driver/rust
+ env:
+ OUTCOME: ${{ steps.run.outcome }}
+ run: |
+ {
+ echo "## ${{ matrix.target }}: $OUTCOME"
+ echo
+ if [[ -f "fuzz/${{ matrix.target }}.log" ]]; then
+ echo '```text'
+ grep -E "^#[0-9]+\s+DONE|Done [0-9]+ runs|stat::" "fuzz/${{ matrix.target }}.log" | tail -n 8 || true
+ echo '```'
+ fi
+ if [[ "$OUTCOME" != "success" ]]; then
+ echo
+ echo "### Finding"
+ echo
+ echo '```text'
+ grep -E -A 2 "panicked at|ERROR: libFuzzer|Test unit written to" "fuzz/${{ matrix.target }}.log" | head -n 40 || true
+ echo '```'
+ echo
+ echo "Reproduce locally with the crash file from the uploaded artifact:"
+ echo
+ echo '```bash'
+ echo "cd libs/cua-driver/rust"
+ echo "cargo fuzz run --fuzz-dir fuzz --sanitizer none ${{ matrix.target }} fuzz/artifacts/${{ matrix.target }}/<crash-file>"
+ echo '```'
+ fi
+ } >> "$GITHUB_STEP_SUMMARY"
+
+ - name: Upload crash artifacts
+ if: failure()
+ uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
+ with:
+ name: fuzz-${{ matrix.target }}-artifacts
+ path: |
+ libs/cua-driver/rust/fuzz/artifacts/${{ matrix.target }}/
+ libs/cua-driver/rust/fuzz/${{ matrix.target }}.log
+ if-no-files-found: warn
+ retention-days: 14
diff --git a/libs/cua-driver/docs/2026-09-04-tool-call-boundary-fuzzing-design.md b/libs/cua-driver/docs/2026-09-04-tool-call-boundary-fuzzing-design.md
new file mode 100644
index 0000000000..cdec20fa48
--- /dev/null
+++ b/libs/cua-driver/docs/2026-09-04-tool-call-boundary-fuzzing-design.md
@@ -0,0 +1,221 @@
+# Tool call boundary fuzzing
+
+Status: design accepted 2026-09-04, implemented in the same change.
+
+## Problem
+
+Every MCP client, the CLI, and the same-process SDK reach platform behaviour
+through one chain in `cua-driver-core`:
+
+```text
+JSON-RPC bytes
+ -> protocol::Request (serde)
+ -> Request::tool_call() name + arguments
+ -> server::handle_request_inner reserved-arg strip, policy pre-check,
+ transport session stamping
+ -> ToolRegistry::invoke_authorized strip again, alias, delivery-mode and
+ target normalisation, hard invariants,
+ risk classification, session namespace
+ -> tool_args::parse_typed_input / projection serde into the contract input types
+```
+
+Everything above the platform adapters is pure Rust over `serde_json::Value`
+and runs on every platform. It is also where untrusted input is turned into
+trusted arguments, so a panic, an unexpected `expect`, or a parser that accepts
+something the published schema does not are all boundary bugs. The chain has
+good example-based tests but nothing that explores the input space.
+
+## Goals
+
+- Fuzz the chain above with coverage-guided fuzzing (`cargo fuzz`) without
+ touching any platform adapter, display, or OS input queue.
+- Run the same target bodies as bounded smoke tests in ordinary `cargo test`
+ so they compile on the pinned stable toolchain, run in existing CI and in the
+ Nix unit check, and catch regressions without anyone remembering to fuzz.
+- Keep `arbitrary` and `libfuzzer-sys` out of the shipped dependency graph.
+
+Non-goals: fuzzing platform crates, the HTTP transport framing, or the
+recording and video pipeline. Those are separate boundaries.
+
+## Approaches considered
+
+1. **`cargo-fuzz` crate only.** Standard layout, best exploration, but the
+ targets need nightly for sanitizers, never run in CI, and rot silently.
+2. **Property tests only (`proptest`).** Runs in CI, but hand-written
+ strategies explore far less than libFuzzer and a second generator has to be
+ maintained beside the fuzz targets.
+3. **Shared target bodies, two drivers.** (chosen) Target bodies live in the
+ dev-only `cua-driver-testkit` crate as `fn(&[u8])` functions built on
+ `arbitrary::Unstructured`. A detached `fuzz/` crate wraps them in
+ `fuzz_target!`. Smoke tests in the testkit feed the same bodies a checked-in
+ seed corpus plus a deterministic pseudo-random byte stream.
+
+Approach 3 costs one new dev-only dependency edge (`testkit -> core`) and gives
+both continuous coverage and real fuzzing from one definition of each target.
+
+## Design
+
+### Where the code lives
+
+```text
+libs/cua-driver/rust/
+ crates/cua-driver-testkit/src/boundary_fuzz.rs target bodies + JSON generator
+ crates/cua-driver-testkit/tests/tool_boundary_fuzz_smoke.rs
+ fuzz/Cargo.toml detached workspace, libfuzzer-sys
+ fuzz/fuzz_targets/{mcp_request,tool_arguments,typed_input_json,registry_invoke}.rs
+ fuzz/corpus/<target>/ checked-in seeds only
+ fuzz/.gitignore target/, artifacts/, coverage/
+```
+
+The testkit is already described as dev-dependency only and never shipped, so
+`cua-driver-core`, `cua-driver-contract`, `arbitrary`, and `tokio` can join
+its dependency list without changing what `cua-driver` distributes.
+
+### Targets and invariants
+
+Each body returns normally on every input. A panic anywhere is the finding.
+
+**`mcp_request(bytes)`** parses the bytes as a JSON-RPC `Request`. On success
+it drives `server::handle_request` and `handle_request_with_transport_session`
+against a recording `ToolProvider` stub. Invariants:
+
+- the `Response` serialises and carries `jsonrpc: "2.0"`;
+- for `tools/call`, the provider only ever receives underscore-prefixed
+ arguments that the transport itself stamps (`_session_id`,
+ `_transport_session_id`, the browser-download host approval flag), so a
+ forged reserved argument never survives ingress;
+- `_session_id` equals the caller's non-empty `session` string when present
+ and otherwise the transport session.
+
+**`tool_arguments(bytes)`** picks a tool name (a published contract name, a
+runtime-only name, or an arbitrary string) and generates a bounded JSON value.
+It runs `sanitize_reserved_args`, `normalize_action_target`,
+`authorize_tool_call_with_context` under an unrestricted in-process context,
+`classify_tool_call`, and, for names that own a contract input type,
+`parse_typed_input` and `parse_typed_projection`. Invariants:
+
+- sanitised objects contain no underscore-prefixed key;
+- after a successful `normalize_action_target` no `target` key remains;
+- a typed input that parses re-serialises to a value that parses again to the
+ same serialisation (normalisation is idempotent).
+
+**`typed_input_json(bytes)`** treats the bytes as JSON text and offers it to
+every contract input type through `parse_typed_input`. This exercises serde
+edge cases (numbers, escapes, duplicate keys, deep nesting) that a structured
+generator rarely reaches. Invariant: the same idempotent re-serialisation rule,
+plus the canonical re-serialised form of every accepted value validates
+structurally against `T::input_schema()` (types, required keys, enums,
+unknown properties), so the driver never normalises to a shape the
+published contract does not advertise. Range and length keywords are
+ignored for now; see the findings below for why. The raw input is not validated: serde
+is allowed to be more lenient than the schema (an explicit `null` for an
+optional field, unknown keys on types without `deny_unknown_fields`).
+
+**`registry_invoke(bytes)`** builds a `ToolRegistry` whose tools are stubs
+named after every published contract tool, then calls
+`invoke_with_context` with an arbitrary name and generated arguments under an
+unrestricted context. This covers alias resolution, delivery-mode and target
+normalisation, hard invariants, the runtime session namespace, ended-session
+refusals, and result post-processing. Invariants: the call returns a
+`ToolResult`; an unregistered name yields an error result.
+
+Session lifecycle tools are deliberately not registered so a fuzz input cannot
+suspend the shared runtime scope and starve later inputs.
+
+### Determinism
+
+The registry, contexts, and provider are built per call from explicit
+constructors (`SessionAuthorizationRegistry::with_ceiling`,
+`compatibility_context`) so no environment variable or policy file is read.
+The unrestricted ceiling is the same one the in-crate dispatch tests use.
+
+### Smoke tests
+
+`tests/tool_boundary_fuzz_smoke.rs` runs each body over the seed corpus and
+over a few thousand inputs from a seeded xorshift generator with lengths from
+0 to 4 KiB. The seeds are also the fuzz corpus, so anything that reproduces a
+past finding stays a regression test.
+
+### Running the fuzzers
+
+The workspace pins a stable toolchain, and `cargo-fuzz` wants nightly only for
+sanitizers. With `--sanitizer none` it builds on stable, so:
+
+```bash
+cd libs/cua-driver/rust
+nix shell nixpkgs#cargo nixpkgs#rustc nixpkgs#cargo-fuzz --command \
+ cargo fuzz run --fuzz-dir fuzz --sanitizer none mcp_request \
+ fuzz/work/mcp_request fuzz/corpus/mcp_request -- -max_total_time=300
+```
+
+libFuzzer stores discovered inputs in the first corpus directory, so the
+ignored `fuzz/work/<target>` directory keeps generated entries out of the
+committed seeds. A crash file under `fuzz/artifacts/<target>/` reproduces with
+`cargo fuzz run ... <target> <file>`; copy it into `fuzz/corpus/<target>/` once
+fixed so the smoke test keeps it.
+
+### Continuous fuzzing
+
+`.github/workflows/fuzz-cua-driver.yml` builds each target with
+`--sanitizer none` on the stable toolchain and runs it for two minutes on pull
+requests touching the boundary crates, fifteen minutes nightly, and a chosen
+budget on manual dispatch. A crash fails the target's job, writes the panic
+message and reproduce command to the job summary, and uploads the crash file
+and log. Discovered inputs go to an ignored `fuzz/work/<target>` directory so
+the committed seed corpus stays hand-picked.
+
+## First results
+
+The first smoke run of `registry_invoke` found a real crash: a non-object
+`arguments` value (for example `true`) for any registered tool reached the
+session-stamping index assignment in `ToolRegistry::invoke_authorized` and
+panicked. The stdio proxy dispatches inline, so one malformed request from an
+MCP client terminated the driver process. The fix rejects non-object
+arguments at the dispatch boundary with an `invalid_arguments` refusal, with a
+regression test in `crates/cua-driver-core/tests/tool_arguments_boundary.rs`
+and a seed in `fuzz/corpus/mcp_request/bool_arguments.json`.
+
+The same run also showed that serde accepts an explicit `null` for optional
+contract fields that the published schema types as plain strings
+(`get_session.session` and its siblings). That is benign leniency rather than
+drift, and it is why the schema invariant validates the canonical form.
+
+The first libFuzzer runs (90 seconds per target, `--sanitizer none`, stable
+toolchain) found one more contract drift within seconds on both argument
+targets: `HotkeyInput` advertised `minItems: 2` for `keys`, and every platform
+runtime refuses fewer than two keys, but the contract parser accepted
+`{"keys": []}` and `{"keys": ["ctrl"]}`. The parser now enforces the minimum
+through a `deserialize_with` check, with a unit test in the contract crate and
+the crash inputs kept as seeds. `mcp_request` and `registry_invoke` ran clean
+for their full budget.
+
+The re-run after that fix immediately found the same class again on
+`set_agent_cursor_theme.theme_id` (schema `minLength: 1`, parser accepts
+`""`). This is systemic rather than a one-off: the contract schemas advertise
+numeric range and length bounds that the typed parser does not enforce and
+the platform runtimes check later. Affected fields:
+
+| Tool | Field | Advertised bound |
+| ------------------------ | --------------------------- | -------------------- |
+| `escalate_session` | `detail` | `maxLength: 200` |
+| `set_agent_cursor_theme` | `theme_id` | length 1 to 200 |
+| `set_window_frame` | `pid`, `window_id` | `minimum: 1` |
+| `set_window_frame` | `width`, `height` | `minimum: 1` |
+| `invoke_menu` | `pid`, `window_id` | `minimum: 1` |
+| `invoke_menu` | `path` | 1 to 16 items, each 1 to 200 chars |
+| `click` | `count` | 1 to 3 |
+| `drag` | `duration_ms`, `steps` | 0 to 10000, 1 to 200 |
+| `scroll` | `amount` | 1 to 50 |
+
+The fuzz invariant therefore checks structural agreement only (types,
+required keys, enums, unknown properties) and ignores range and length
+keywords. Enforcing those bounds in the contract parser, the way `hotkey.keys`
+now is, is a follow-up; once it lands, drop the keyword filter in
+`boundary_fuzz::is_value_bound_error` so the fuzzer guards the full schema.
+
+## Out of scope for this change
+
+- Enforcing the remaining advertised range and length bounds in the
+ contract parser (listed under findings). Once they are enforced, drop the
+ keyword filter in `boundary_fuzz::is_value_bound_error` so the fuzzer
+ guards the full schema.
diff --git a/libs/cua-driver/docs/test-harnesses-guide.md b/libs/cua-driver/docs/test-harnesses-guide.md
index d567bbf0d4..a839ff4f9b 100644
--- a/libs/cua-driver/docs/test-harnesses-guide.md
+++ b/libs/cua-driver/docs/test-harnesses-guide.md
@@ -226,11 +226,19 @@ These run without a repo-local GUI application and normally run without
| `schema_*_test.rs` | Shared schema and backend consistency |
| `transport_config_persistence_test.rs` | CLI configuration persistence across processes |
| `protocol_element_token_test.rs` | Element-token protocol behavior |
+| `tool_boundary_fuzz_smoke.rs` | Tool-call boundary fuzz targets over seeds and random bytes |
These tests should be fast, deterministic, and safe to run on ordinary CI
workers. They do not prove that a real click, key, scroll, or background input
reached an application.
+The fuzz smoke test drives the target bodies in
+`cua_driver_testkit::boundary_fuzz` (JSON-RPC parsing, reserved-argument
+stripping, argument normalisation, authorization, typed contract inputs, and
+`ToolRegistry` dispatch against stubs). The same bodies run under libFuzzer
+from `rust/fuzz/`; see `rust/fuzz/README.md` and
+`docs/2026-09-04-tool-call-boundary-fuzzing-design.md`.
+
### Harness E2E Tests
These are Rust integration tests in their own crate:
diff --git a/libs/cua-driver/rust/Cargo.lock b/libs/cua-driver/rust/Cargo.lock
index 2b04685eed..c8de306c98 100644
--- a/libs/cua-driver/rust/Cargo.lock
+++ b/libs/cua-driver/rust/Cargo.lock
@@ -169,6 +169,12 @@ dependencies = [
"security-framework",
]
+[[package]]
+name = "arbitrary"
+version = "1.4.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c3d036a3c4ab069c7b410a2ce876bd74808d2d0888a82667669f8e783a898bf1"
+
[[package]]
name = "arrayref"
version = "0.3.9"
@@ -1351,13 +1357,19 @@ dependencies = [
name = "cua-driver-testkit"
version = "0.30.2"
dependencies = [
+ "arbitrary",
+ "async-trait",
"core-foundation",
+ "cua-driver-contract",
+ "cua-driver-core",
"image",
+ "jsonschema",
"libc",
"objc2-app-kit 0.2.2",
"serde",
"serde_json",
"tempfile",
+ "tokio",
"windows 0.61.3",
"x11rb",
]
diff --git a/libs/cua-driver/rust/crates/cua-driver-contract/src/inputs.rs b/libs/cua-driver/rust/crates/cua-driver-contract/src/inputs.rs
index 9adb6ec7fa..b4d780099e 100644
--- a/libs/cua-driver/rust/crates/cua-driver-contract/src/inputs.rs
+++ b/libs/cua-driver/rust/crates/cua-driver-contract/src/inputs.rs
@@ -920,7 +920,12 @@ impl ToolInput for PressKeyInput {
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, PartialEq, uniffi::Record)]
#[serde(deny_unknown_fields)]
pub struct HotkeyInput {
+ // Enforced by the parser as well as the schema so a typed input can never
+ // carry a combination the platform runtimes would refuse. Not a doc
+ // comment: that would become a schema description and change the
+ // published contract.
#[schemars(length(min = 2))]
+ #[serde(deserialize_with = "at_least_two_keys")]
pub keys: Vec<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub target: Option<ActionTarget>,
@@ -939,12 +944,45 @@ impl ToolInput for HotkeyInput {
const TOOL_NAME: &'static str = "hotkey";
}
+fn at_least_two_keys<'de, D: serde::Deserializer<'de>>(
+ deserializer: D,
+) -> Result<Vec<String>, D::Error> {
+ let keys = Vec::<String>::deserialize(deserializer)?;
+ if keys.len() < 2 {
+ return Err(serde::de::Error::custom(
+ "hotkey.keys must contain at least two keys",
+ ));
+ }
+ Ok(keys)
+}
+
#[cfg(test)]
mod tests {
use serde_json::json;
use super::*;
+ /// Found by the tool-call boundary fuzzer: the published schema and every
+ /// platform runtime require at least two keys, but the contract parser
+ /// accepted any count, so `{"keys": []}` passed typed validation.
+ #[test]
+ fn hotkey_parser_enforces_the_published_two_key_minimum() {
+ for keys in [json!([]), json!(["ctrl"])] {
+ let error = serde_json::from_value::<HotkeyInput>(json!({"keys": keys}))
+ .expect_err("fewer than two keys must be rejected");
+ assert!(
+ error.to_string().contains("at least two keys"),
+ "unexpected error for {keys}: {error}"
+ );
+ }
+ let parsed: HotkeyInput = serde_json::from_value(json!({"keys": ["ctrl", "c"]})).unwrap();
+ assert_eq!(parsed.keys, vec!["ctrl", "c"]);
+ assert_eq!(
+ HotkeyInput::input_schema()["properties"]["keys"]["minItems"],
+ 2
+ );
+ }
+
#[test]
fn typed_click_round_trips_flat_native_wire_and_exact_window_id() {
for position in [
diff --git a/libs/cua-driver/rust/crates/cua-driver-core/src/tool.rs b/libs/cua-driver/rust/crates/cua-driver-core/src/tool.rs
index 3c7ff8ac7b..298d85b622 100644
--- a/libs/cua-driver/rust/crates/cua-driver-core/src/tool.rs
+++ b/libs/cua-driver/rust/crates/cua-driver-core/src/tool.rs
@@ -1108,6 +1108,22 @@ impl ToolRegistry {
return ToolResult::error(format!("Unknown tool: {name}"));
};
+ // MCP types `arguments` as an object and transports substitute `{}`
+ // when it is absent, but a client can still send any JSON value.
+ // Everything below indexes into the object (session stamping,
+ // protected-resource fingerprints, replay rewrites), so refuse other
+ // shapes here instead of panicking the dispatcher on a caller's input.
+ if !args.is_object() {
+ return ToolResult::error(format!(
+ "{resolved_name}: invalid arguments: expected a JSON object"
+ ))
+ .with_structured(serde_json::json!({
+ "code": "invalid_arguments",
+ "tool": resolved_name,
+ "detail": "arguments must be a JSON object",
+ }));
+ }
+
// Normalize deprecated public argument spellings before any policy,
// consent, recording, or implementation layer interprets the call.
normalize_delivery_mode_args(tool.def(), &mut args);
diff --git a/libs/cua-driver/rust/crates/cua-driver-core/tests/tool_arguments_boundary.rs b/libs/cua-driver/rust/crates/cua-driver-core/tests/tool_arguments_boundary.rs
new file mode 100644
index 0000000000..bcf4e558bb
--- /dev/null
+++ b/libs/cua-driver/rust/crates/cua-driver-core/tests/tool_arguments_boundary.rs
@@ -0,0 +1,111 @@
+//! Regression coverage for the canonical dispatch boundary's handling of
+//! malformed `arguments` values.
+//!
+//! The MCP contract types `arguments` as an object and `Request::tool_call`
+//! substitutes `{}` when it is absent, but a client can still send any JSON
+//! value. Found by the `registry_invoke` fuzz target: a non-object value for a
+//! session-selecting tool reached an index assignment inside
+//! `ToolRegistry::invoke_authorized` and panicked the dispatcher.
+
+use cua_driver_core::authorization::PermissionMode;
+use cua_driver_core::protocol::ToolResult;
+use cua_driver_core::session_authorization::{
+ EffectiveAuthorizationContext, SessionAuthorizationRegistry, SessionModeCeiling,
+};
+use cua_driver_core::tool::{Tool, ToolDef, ToolRegistry};
+use serde_json::{json, Value};
+use std::sync::Arc;
+use std::time::Duration;
+
+struct Stub(ToolDef);
+
+#[async_trait::async_trait]
+impl Tool for Stub {
+ fn def(&self) -> &ToolDef {
+ &self.0
+ }
+
+ async fn invoke(&self, _args: Value) -> ToolResult {
+ ToolResult::text("stub")
+ }
+}
+
+fn unrestricted_context() -> Arc<EffectiveAuthorizationContext> {
+ let ceiling = SessionModeCeiling::for_trusted_sessions(
+ [PermissionMode::Unrestricted],
+ true,
+ Duration::from_secs(60),
+ Duration::from_secs(30),
+ )
+ .unwrap();
+ SessionAuthorizationRegistry::with_ceiling(ceiling)
+ .compatibility_context(PermissionMode::Unrestricted, None)
+ .unwrap()
+}
+
+fn registry_with(name: &str) -> Arc<ToolRegistry> {
+ let mut registry = ToolRegistry::new();
+ registry.register(Box::new(Stub(ToolDef {
+ name: name.to_owned(),
+ description: "stub".to_owned(),
+ input_schema: json!({"type": "object", "properties": {}}),
+ read_only: true,
+ destructive: false,
+ idempotent: true,
+ open_world: false,
+ })));
+ let registry = Arc::new(registry);
+ registry.init_self_weak();
+ registry
+}
+
+#[tokio::test]
+async fn non_object_arguments_for_a_session_selecting_tool_are_rejected_not_panicked() {
+ let registry = registry_with("get_session");
+ for arguments in [
+ json!(true),
+ json!(null),
+ json!(7),
+ json!("s"),
+ json!([1, 2]),
+ ] {
+ let result = registry
+ .invoke_with_context("get_session", arguments.clone(), unrestricted_context())
+ .await;
+ assert_eq!(
+ result.is_error,
+ Some(true),
+ "arguments {arguments} were accepted"
+ );
+ let structured = result.structured_content.expect("structured refusal");
+ assert_eq!(
+ structured["code"], "invalid_arguments",
+ "arguments {arguments}"
+ );
+ assert_eq!(structured["tool"], "get_session");
+ }
+}
+
+#[tokio::test]
+async fn non_object_arguments_for_an_ordinary_tool_are_rejected_before_dispatch() {
+ let registry = registry_with("get_screen_size");
+ let result = registry
+ .invoke_with_context("get_screen_size", json!("nope"), unrestricted_context())
+ .await;
+ assert_eq!(result.is_error, Some(true));
+ assert_eq!(
+ result.structured_content.unwrap()["code"],
+ "invalid_arguments"
+ );
+}
+
+#[tokio::test]
+async fn unknown_tool_still_wins_over_malformed_arguments() {
+ let registry = registry_with("get_screen_size");
+ let result = registry
+ .invoke_with_context("no_such_tool", json!(true), unrestricted_context())
+ .await;
+ assert_eq!(result.is_error, Some(true));
+ let text = serde_json::to_string(&result.content).unwrap();
+ assert!(text.contains("Unknown tool"), "{text}");
+}
diff --git a/libs/cua-driver/rust/crates/cua-driver-testkit/Cargo.toml b/libs/cua-driver/rust/crates/cua-driver-testkit/Cargo.toml
index eb36a7f29c..617bf5df87 100644
--- a/libs/cua-driver/rust/crates/cua-driver-testkit/Cargo.toml
+++ b/libs/cua-driver/rust/crates/cua-driver-testkit/Cargo.toml
@@ -13,6 +13,18 @@ serde = { workspace = true }
serde_json = { workspace = true }
image = { workspace = true }
tempfile = "3"
+# Tool-call boundary fuzz target bodies (`boundary_fuzz`). The testkit is the
+# only in-workspace home that never ships, so the fuzz-only crates and the
+# core/contract path dependencies they exercise live here rather than behind a
+# feature in `cua-driver-core`.
+cua-driver-core = { path = "../cua-driver-core" }
+cua-driver-contract = { path = "../cua-driver-contract" }
+arbitrary = "1"
+async-trait = "0.1"
+tokio = { workspace = true }
+# Same version `cua-driver-core` already uses in its own tests, so the fuzz
+# schema-agreement check reuses that build.
+jsonschema = { version = "0.46", default-features = false }
[target.'cfg(unix)'.dependencies]
libc = "0.2"
diff --git a/libs/cua-driver/rust/crates/cua-driver-testkit/src/boundary_fuzz.rs b/libs/cua-driver/rust/crates/cua-driver-testkit/src/boundary_fuzz.rs
new file mode 100644
index 0000000000..206c884d5b
--- /dev/null
+++ b/libs/cua-driver/rust/crates/cua-driver-testkit/src/boundary_fuzz.rs
@@ -0,0 +1,612 @@
+//! Fuzz target bodies for the transport-free MCP tool-call boundary.
+//!
+//! Each public `fn(&[u8])` here is one libFuzzer target (see `fuzz/`) and is
+//! also driven by `tests/tool_boundary_fuzz_smoke.rs` over the seed corpus
+//! plus a deterministic byte stream. A body must return normally on every
+//! input; any panic is a finding. The bodies never reach a platform adapter,
+//! display, or input device: every tool behind the boundary is a stub.
+//!
+//! The chain under test, all inside `cua-driver-core`:
+//!
+//! ```text
+//! bytes -> protocol::Request -> Request::tool_call
+//! -> server::handle_request (reserved-arg strip, session stamping)
+//! -> ToolRegistry::invoke_with_context (alias, normalisation, authorization)
+//! -> tool_args::parse_typed_input (serde into contract input types)
+//! ```
+//!
+//! Environment-driven globals (`CUA_DRIVER_*` policy and permission-mode
+//! variables) are deliberately not consulted by `tool_arguments` and
+//! `registry_invoke`, which build their authorization context from explicit
+//! constructors. `mcp_request` goes through the public `handle_request`
+//! entry point, which does read the process defaults once; keep those
+//! variables unset when fuzzing so runs stay reproducible.
+
+use arbitrary::Unstructured;
+use cua_driver_contract::{
+ ClickInput, ClipboardReadInput, ClipboardWriteInput, DragInput, EndSessionInput,
+ EscalateSessionInput, GetAgentCursorStateInput, GetCursorPositionInput, GetDesktopStateInput,
+ GetScreenSizeInput, GetSessionInput, GetSessionStateInput, HotkeyInput, InvokeMenuInput,
+ ListSessionsInput, MoveCursorInput, PressKeyInput, ScrollInput, SetAgentCursorEnabledInput,
+ SetAgentCursorMotionInput, SetAgentCursorThemeInput, SetWindowFrameInput, StartSessionInput,
+ ToolInput, TypeTextInput, VerifyStateInput,
+};
+use cua_driver_core::authorization::PermissionMode;
+use cua_driver_core::protocol::{Request, Response, ToolResult};
+use cua_driver_core::server::{
+ handle_request, handle_request_with_transport_session, ToolProvider,
+};
+use cua_driver_core::session_authorization::{
+ EffectiveAuthorizationContext, SessionAuthorizationRegistry, SessionModeCeiling,
+};
+use cua_driver_core::tool::{Tool, ToolDef, ToolRegistry};
+use serde_json::{Map, Value};
+use std::sync::{Arc, Mutex, OnceLock};
+use std::time::Duration;
+
+/// Every target with its name, in the order the fuzz crate registers them.
+pub const TARGETS: &[(&str, fn(&[u8]))] = &[
+ ("mcp_request", mcp_request),
+ ("tool_arguments", tool_arguments),
+ ("typed_input_json", typed_input_json),
+ ("registry_invoke", registry_invoke),
+];
+
+/// Reserved arguments the MCP ingress itself is allowed to stamp onto a call.
+/// Anything else with a leading underscore reaching a provider was forged by
+/// the caller and survived sanitisation.
+const TRANSPORT_STAMPED_RESERVED: &[&str] = &[
+ "_session_id",
+ "_transport_session_id",
+ cua_driver_core::browser::download::MCP_HOST_DOWNLOAD_APPROVAL_ARG,
+];
+
+const TRANSPORT_SESSION: &str = "fuzz-transport";
+
+/// Argument names the boundary treats specially. Drawing keys from this pool
+/// keeps random objects landing on real normalisation and policy branches.
+const INTERESTING_KEYS: &[&str] = &[
+ "session",
+ "pid",
+ "window_id",
+ "element_index",
+ "x",
+ "y",
+ "text",
+ "key",
+ "keys",
+ "button",
+ "target",
+ "kind",
+ "display_id",
+ "scope",
+ "delivery_mode",
+ "dispatch",
+ "count",
+ "direction",
+ "amount",
+ "reason",
+ "mode",
+ "timeout_ms",
+ "profile",
+ "strategy",
+ "dir",
+ "delay_ms",
+ "_session_id",
+ "_transport_session_id",
+ "_observation_only",
+ "_protected_process_fingerprint",
+ "_cua_browser_download_mcp_host_approved",
+];
+
+const INTERESTING_STRINGS: &[&str] = &[
+ "",
+ "window",
+ "desktop",
+ "foreground",
+ "Foreground",
+ "background",
+ "left",
+ "right",
+ "middle",
+ "up",
+ "down",
+ "main",
+ "existing_profile",
+ "isolated_new",
+ "\u{0}",
+ "\u{1F600}",
+ "implicit-direct",
+];
+
+/// Runtime-only tool names that never appear in the published contract but do
+/// hit dedicated boundary branches (aliases, host-approval stamping, replay).
+const RUNTIME_ONLY_TOOLS: &[&str] = &[
+ "type_text_chars",
+ "browser_download",
+ "browser_prepare",
+ "replay_trajectory",
+ "get_window_state",
+ "list_windows",
+ "kill_app",
+ "set_value",
+ "page",
+ "start_recording",
+ "revoke_all",
+];
+
+fn contract_tool_names() -> &'static [String] {
+ static NAMES: OnceLock<Vec<String>> = OnceLock::new();
+ NAMES.get_or_init(|| {
+ cua_driver_contract::manifest()
+ .tools
+ .into_iter()
+ .map(|tool| tool.name)
+ .collect()
+ })
+}
+
+fn runtime() -> &'static tokio::runtime::Runtime {
+ static RUNTIME: OnceLock<tokio::runtime::Runtime> = OnceLock::new();
+ RUNTIME.get_or_init(|| {
+ tokio::runtime::Builder::new_current_thread()
+ .enable_all()
+ .build()
+ .expect("fuzz runtime")
+ })
+}
+
+/// Unrestricted in-process context built from explicit trusted-host
+/// constructors, mirroring the registry dispatch tests in `cua-driver-core`.
+fn unrestricted_context() -> Arc<EffectiveAuthorizationContext> {
+ static CONTEXT: OnceLock<Arc<EffectiveAuthorizationContext>> = OnceLock::new();
+ CONTEXT
+ .get_or_init(|| {
+ let ceiling = SessionModeCeiling::for_trusted_sessions(
+ [PermissionMode::Unrestricted],
+ true,
+ Duration::from_secs(3600),
+ Duration::from_secs(1800),
+ )
+ .expect("fuzz ceiling");
+ SessionAuthorizationRegistry::with_ceiling(ceiling)
+ .compatibility_context(PermissionMode::Unrestricted, None)
+ .expect("fuzz context")
+ })
+ .clone()
+}
+
+// ── Generators ───────────────────────────────────────────────────────────────
+
+fn pick<'a>(u: &mut Unstructured<'_>, pool: &'a [&str]) -> &'a str {
+ u.choose(pool).copied().unwrap_or("")
+}
+
+fn arbitrary_string(u: &mut Unstructured<'_>) -> String {
+ if u.ratio(3, 4).unwrap_or(true) {
+ pick(u, INTERESTING_STRINGS).to_owned()
+ } else {
+ u.arbitrary::<String>().unwrap_or_default()
+ }
+}
+
+fn arbitrary_number(u: &mut Unstructured<'_>) -> Value {
+ match u.int_in_range(0..=7u8).unwrap_or(0) {
+ 0 => Value::from(u.arbitrary::<i64>().unwrap_or(0)),
+ 1 => Value::from(u.arbitrary::<u64>().unwrap_or(0)),
+ 2 => Value::from(u.int_in_range(0..=64u8).unwrap_or(0)),
+ 3 => Value::from(u.arbitrary::<f64>().unwrap_or(0.0)),
+ 4 => Value::from(u32::MAX),
+ 5 => Value::from(u64::from(u32::MAX) + 1),
+ 6 => Value::from(-1),
+ _ => Value::from(i64::from(std::process::id())),
+ }
+}
+
+/// Bounded-depth JSON value biased toward the shapes the boundary inspects.
+pub fn arbitrary_json(u: &mut Unstructured<'_>, depth: u8) -> Value {
+ let choice = u.int_in_range(0..=9u8).unwrap_or(0);
+ match choice {
+ 0 => Value::Null,
+ 1 => Value::Bool(u.arbitrary().unwrap_or(false)),
+ 2 | 3 => arbitrary_number(u),
+ 4 | 5 => Value::String(arbitrary_string(u)),
+ 6 if depth > 0 => {
+ let len = u.int_in_range(0..=4usize).unwrap_or(0);
+ Value::Array((0..len).map(|_| arbitrary_json(u, depth - 1)).collect())
+ }
+ _ if depth > 0 => arbitrary_object(u, depth - 1),
+ _ => Value::String(arbitrary_string(u)),
+ }
+}
+
+fn arbitrary_object(u: &mut Unstructured<'_>, depth: u8) -> Value {
+ let len = u.int_in_range(0..=6usize).unwrap_or(0);
+ let mut object = Map::new();
+ for _ in 0..len {
+ let key = if u.ratio(4, 5).unwrap_or(true) {
+ pick(u, INTERESTING_KEYS).to_owned()
+ } else {
+ u.arbitrary::<String>().unwrap_or_default()
+ };
+ object.insert(key, arbitrary_json(u, depth));
+ }
+ Value::Object(object)
+}
+
+/// Tool arguments: usually an object, sometimes trailing raw JSON text from
+/// the input so libFuzzer can splice in real payloads, occasionally a
+/// non-object so the "arguments must be an object" branches run.
+fn arbitrary_arguments(u: &mut Unstructured<'_>) -> Value {
+ match u.int_in_range(0..=5u8).unwrap_or(0) {
+ 0 => {
+ let rest = u.bytes(u.len()).unwrap_or(&[]);
+ serde_json::from_slice(rest).unwrap_or_else(|_| Value::Object(Map::new()))
+ }
+ 1 => arbitrary_json(u, 2),
+ _ => arbitrary_object(u, 3),
+ }
+}
+
+fn arbitrary_tool_name(u: &mut Unstructured<'_>) -> String {
+ match u.int_in_range(0..=7u8).unwrap_or(0) {
+ 0 => pick(u, RUNTIME_ONLY_TOOLS).to_owned(),
+ 1 => u.arbitrary::<String>().unwrap_or_default(),
+ _ => u.choose(contract_tool_names()).cloned().unwrap_or_default(),
+ }
+}
+
+// ── mcp_request ──────────────────────────────────────────────────────────────
+
+#[derive(Default)]
+struct RecordingProvider {
+ calls: Mutex<Vec<(String, Value)>>,
+}
+
+#[async_trait::async_trait]
+impl ToolProvider for RecordingProvider {
+ fn tools_list(&self) -> Value {
+ serde_json::json!({"tools": []})
+ }
+
+ async fn invoke_tool(&self, name: &str, arguments: Value) -> Result<Value, String> {
+ self.calls
+ .lock()
+ .unwrap()
+ .push((name.to_owned(), arguments));
+ Ok(serde_json::json!({"content": [], "isError": false}))
+ }
+}
+
+fn check_stamped_arguments(
+ caller_args: &Value,
+ delivered: &Value,
+ transport_session: Option<&str>,
+) {
+ let Some(delivered) = delivered.as_object() else {
+ return;
+ };
+ for key in delivered.keys().filter(|key| key.starts_with('_')) {
+ assert!(
+ TRANSPORT_STAMPED_RESERVED.contains(&key.as_str()),
+ "forged reserved argument {key:?} reached the provider"
+ );
+ }
+ let public_session = caller_args
+ .get("session")
+ .and_then(Value::as_str)
+ .filter(|session| !session.is_empty());
+ let expected_session = public_session.or(transport_session);
+ assert_eq!(
+ delivered.get("_session_id").and_then(Value::as_str),
+ expected_session,
+ "_session_id must come from the public session or the transport"
+ );
+ let expected_owner = transport_session.or(public_session);
+ assert_eq!(
+ delivered
+ .get("_transport_session_id")
+ .and_then(Value::as_str),
+ expected_owner,
+ "_transport_session_id must come from the transport or the public session"
+ );
+}
+
+fn caller_arguments(request: &Request) -> Value {
+ request
+ .params
+ .as_ref()
+ .and_then(|params| params.get("arguments"))
+ .cloned()
+ .unwrap_or_else(|| Value::Object(Map::new()))
+}
+
+fn drive_request(request: Request, provider: &dyn ToolProvider, transport_session: Option<&str>) {
+ let id = request.id.clone().unwrap_or(Value::Null);
+ let response: Response = runtime().block_on(async {
+ match transport_session {
+ Some(session) => {
+ handle_request_with_transport_session(request, id, provider, session).await
+ }
+ None => handle_request(request, id, provider).await,
+ }
+ });
+ let encoded = serde_json::to_value(&response).expect("response serialises");
+ assert_eq!(encoded["jsonrpc"], "2.0");
+}
+
+/// Ingress with a recording provider, so the arguments handed past the
+/// transport boundary can be checked for forged reserved fields.
+fn drive_recorded(data: &[u8], transport_session: Option<&str>) {
+ let Ok(request) = serde_json::from_slice::<Request>(data) else {
+ return;
+ };
+ let is_tool_call = request.method == "tools/call";
+ let caller_args = caller_arguments(&request);
+ let provider = RecordingProvider::default();
+ drive_request(request, &provider, transport_session);
+ if is_tool_call {
+ for (_, delivered) in provider.calls.lock().unwrap().iter() {
+ check_stamped_arguments(&caller_args, delivered, transport_session);
+ }
+ }
+}
+
+/// Raw bytes as a JSON-RPC request through both public ingress entry points,
+/// first against a recording provider and then end to end into the stub
+/// `ToolRegistry`, which is the path a real MCP client's call takes.
+pub fn mcp_request(data: &[u8]) {
+ let Ok(request) = serde_json::from_slice::<Request>(data) else {
+ return;
+ };
+ let _ = request.is_notification();
+ let _ = request.initialize_metadata();
+ let _ = request.tool_call();
+ drive_request(request, stub_registry().as_ref(), Some(TRANSPORT_SESSION));
+ drive_recorded(data, None);
+ drive_recorded(data, Some(TRANSPORT_SESSION));
+}
+
+// ── typed inputs ─────────────────────────────────────────────────────────────
+
+fn sanitized(args: &Value) -> Value {
+ let mut copy = args.clone();
+ cua_driver_core::tool_args::sanitize_reserved_args(&mut copy);
+ copy
+}
+
+fn input_schema_validator<T: ToolInput>() -> &'static jsonschema::Validator {
+ // One validator per input type. A `static` inside a generic fn is shared
+ // across every `T`, so key the cache by tool name instead of relying on
+ // monomorphisation.
+ static VALIDATORS: OnceLock<Mutex<Vec<(&'static str, &'static jsonschema::Validator)>>> =
+ OnceLock::new();
+ let validators = VALIDATORS.get_or_init(|| Mutex::new(Vec::new()));
+ let mut guard = validators.lock().unwrap();
+ if let Some((_, validator)) = guard.iter().find(|(name, _)| *name == T::TOOL_NAME) {
+ return validator;
+ }
+ let validator = jsonschema::validator_for(&T::input_schema()).expect("valid input schema");
+ let validator: &'static jsonschema::Validator = Box::leak(Box::new(validator));
+ guard.push((T::TOOL_NAME, validator));
+ validator
+}
+
+/// Numeric range and length keywords. The published schemas advertise these
+/// (`minimum: 1` on pids, `minItems` on key lists, `maxLength` on labels) but
+/// the contract types enforce only some of them; the rest are checked by the
+/// platform runtimes after typed parsing. Until every bound is enforced in the
+/// parser, treat them as advertised-but-runtime-enforced and keep the fuzz
+/// invariant on structural agreement (types, required keys, enums, unknown
+/// properties). See the design note for the list of affected fields.
+fn is_value_bound_error(error: &jsonschema::ValidationError<'_>) -> bool {
+ use jsonschema::error::ValidationErrorKind as Kind;
+ matches!(
+ error.kind(),
+ Kind::Minimum { .. }
+ | Kind::Maximum { .. }
+ | Kind::ExclusiveMinimum { .. }
+ | Kind::ExclusiveMaximum { .. }
+ | Kind::MinLength { .. }
+ | Kind::MaxLength { .. }
+ | Kind::MinItems { .. }
+ | Kind::MaxItems { .. }
+ )
+}
+
+/// Offer `args` to one typed input. When the parser accepts the value, its
+/// canonical re-serialised form must validate structurally against the
+/// published schema and re-serialising must be idempotent, so SDK clients and
+/// the live parser agree on the canonical form.
+///
+/// The raw input is deliberately not validated: serde is allowed to be more
+/// lenient than the schema (an explicit `null` for an optional field, unknown
+/// keys on types without `deny_unknown_fields`). What matters is that every
+/// value the driver normalises to is one the contract advertises.
+fn check_typed_input<T: ToolInput>(args: &Value) {
+ let Ok(parsed) = cua_driver_core::tool_args::parse_typed_input::<T>(T::TOOL_NAME, args.clone())
+ else {
+ return;
+ };
+ let once = serde_json::to_value(&parsed).expect("typed input serialises");
+ let shape_errors: Vec<String> = input_schema_validator::<T>()
+ .iter_errors(&once)
+ .filter(|error| !is_value_bound_error(error))
+ .map(|error| error.to_string())
+ .collect();
+ assert!(
+ shape_errors.is_empty(),
+ "{}: parser accepted {} and canonicalised it to {once}, which the published input schema rejects: {shape_errors:?}",
+ T::TOOL_NAME,
+ sanitized(args)
+ );
+ let reparsed: T = serde_json::from_value(once.clone()).unwrap_or_else(|error| {
+ panic!(
+ "{}: serialised typed input {once} does not parse again: {error}",
+ T::TOOL_NAME
+ )
+ });
+ let twice = serde_json::to_value(&reparsed).expect("typed input serialises");
+ assert_eq!(
+ once,
+ twice,
+ "{}: typed input normalisation is not idempotent",
+ T::TOOL_NAME
+ );
+ let _ = cua_driver_core::tool_args::parse_typed_projection::<T>(T::TOOL_NAME, args);
+}
+
+macro_rules! typed_inputs {
+ ($($ty:ty),* $(,)?) => {
+ fn check_typed_input_for_tool(tool: &str, args: &Value) {
+ $(if tool == <$ty as ToolInput>::TOOL_NAME { check_typed_input::<$ty>(args); })*
+ }
+
+ fn check_every_typed_input(args: &Value) {
+ $(check_typed_input::<$ty>(args);)*
+ }
+ };
+}
+
+typed_inputs!(
+ StartSessionInput,
+ EscalateSessionInput,
+ GetSessionStateInput,
+ GetSessionInput,
+ ListSessionsInput,
+ SetAgentCursorEnabledInput,
+ SetAgentCursorMotionInput,
+ SetAgentCursorThemeInput,
+ GetAgentCursorStateInput,
+ EndSessionInput,
+ GetDesktopStateInput,
+ GetScreenSizeInput,
+ GetCursorPositionInput,
+ SetWindowFrameInput,
+ InvokeMenuInput,
+ MoveCursorInput,
+ ClickInput,
+ DragInput,
+ ScrollInput,
+ TypeTextInput,
+ ClipboardReadInput,
+ ClipboardWriteInput,
+ PressKeyInput,
+ HotkeyInput,
+ VerifyStateInput,
+);
+
+/// Raw bytes as JSON text offered to every typed contract input.
+pub fn typed_input_json(data: &[u8]) {
+ let Ok(value) = serde_json::from_slice::<Value>(data) else {
+ return;
+ };
+ check_every_typed_input(&value);
+}
+
+// ── tool_arguments ───────────────────────────────────────────────────────────
+
+/// A tool name plus generated arguments through every pure pre-dispatch step.
+pub fn tool_arguments(data: &[u8]) {
+ let mut u = Unstructured::new(data);
+ let tool = arbitrary_tool_name(&mut u);
+ let args = arbitrary_arguments(&mut u);
+
+ let clean = sanitized(&args);
+ if let Some(object) = clean.as_object() {
+ assert!(
+ object.keys().all(|key| !key.starts_with('_')),
+ "sanitize_reserved_args left a reserved key in {clean}"
+ );
+ }
+
+ let mut normalised = clean.clone();
+ if cua_driver_core::action_target::normalize_action_target(&tool, &mut normalised).is_ok() {
+ if let Some(object) = normalised.as_object() {
+ assert!(
+ !object.contains_key("target"),
+ "normalize_action_target accepted {clean} but left a target key"
+ );
+ }
+ }
+ let _ = cua_driver_core::action_target::supports_typed_target(&tool);
+
+ let context = unrestricted_context();
+ let _ = cua_driver_core::authorization::authorize_tool_call_with_context(
+ &tool,
+ &normalised,
+ context.as_ref(),
+ );
+ let _ = cua_driver_core::authorization::classify_tool_call(&tool, &normalised);
+ let _ = cua_driver_core::tool::advertised_capabilities_for(&tool, &Value::Null);
+
+ check_typed_input_for_tool(&tool, &args);
+}
+
+// ── registry_invoke ──────────────────────────────────────────────────────────
+
+struct StubTool {
+ def: ToolDef,
+}
+
+#[async_trait::async_trait]
+impl Tool for StubTool {
+ fn def(&self) -> &ToolDef {
+ &self.def
+ }
+
+ async fn invoke(&self, _args: Value) -> ToolResult {
+ ToolResult::text("stub")
+ }
+}
+
+/// One registry of stubs named after every published contract tool. Session
+/// lifecycle tools are intentionally absent so no input can suspend the shared
+/// runtime scope and starve later inputs.
+fn stub_registry() -> Arc<ToolRegistry> {
+ static REGISTRY: OnceLock<Arc<ToolRegistry>> = OnceLock::new();
+ REGISTRY
+ .get_or_init(|| {
+ let mut registry = ToolRegistry::new();
+ for contract in cua_driver_contract::manifest().tools {
+ // Not `ToolDef::from_contract`: that bridge refuses portable
+ // subset contracts, and stubs only need the advertised schema
+ // so delivery-mode and capability logic sees realistic input.
+ registry.register(Box::new(StubTool {
+ def: ToolDef {
+ name: contract.name.clone(),
+ description: contract.description.clone(),
+ input_schema: contract.input_schema.clone(),
+ read_only: contract.annotations.read_only,
+ destructive: contract.annotations.destructive,
+ idempotent: contract.annotations.idempotent,
+ open_world: contract.annotations.open_world,
+ },
+ }));
+ }
+ let registry = Arc::new(registry);
+ registry.init_self_weak();
+ registry
+ })
+ .clone()
+}
+
+/// A tool name plus generated arguments through `ToolRegistry` dispatch.
+pub fn registry_invoke(data: &[u8]) {
+ let mut u = Unstructured::new(data);
+ let tool = arbitrary_tool_name(&mut u);
+ let args = arbitrary_arguments(&mut u);
+ let registry = stub_registry();
+ let known = registry.get_def(&tool).is_some() || tool == "type_text_chars";
+
+ let result =
+ runtime().block_on(registry.invoke_with_context(&tool, args, unrestricted_context()));
+ let _ = serde_json::to_value(&result).expect("tool result serialises");
+ if !known {
+ assert_eq!(
+ result.is_error,
+ Some(true),
+ "unregistered tool {tool:?} did not produce an error result"
+ );
+ }
+}
diff --git a/libs/cua-driver/rust/crates/cua-driver-testkit/src/lib.rs b/libs/cua-driver/rust/crates/cua-driver-testkit/src/lib.rs
index 81e51fc24d..63921466e5 100644
--- a/libs/cua-driver/rust/crates/cua-driver-testkit/src/lib.rs
+++ b/libs/cua-driver/rust/crates/cua-driver-testkit/src/lib.rs
@@ -38,6 +38,7 @@
//! into a panic, so a gate cannot pass without exercising the driver.
pub mod ax;
+pub mod boundary_fuzz;
mod browser_fixture;
mod cli;
mod daemon;
diff --git a/libs/cua-driver/rust/crates/cua-driver-testkit/tests/tool_boundary_fuzz_smoke.rs b/libs/cua-driver/rust/crates/cua-driver-testkit/tests/tool_boundary_fuzz_smoke.rs
new file mode 100644
index 0000000000..a925535eac
--- /dev/null
+++ b/libs/cua-driver/rust/crates/cua-driver-testkit/tests/tool_boundary_fuzz_smoke.rs
@@ -0,0 +1,133 @@
+//! Bounded, deterministic runs of the tool-call boundary fuzz targets.
+//!
+//! The target bodies live in `cua_driver_testkit::boundary_fuzz` and are the
+//! same functions the detached `fuzz/` crate hands to libFuzzer. Running them
+//! here over the checked-in seed corpus plus a seeded pseudo-random byte
+//! stream keeps them compiling on the pinned stable toolchain and turns every
+//! past finding into a regression test, without needing `cargo fuzz`.
+
+use cua_driver_testkit::boundary_fuzz::{self, TARGETS};
+use std::path::{Path, PathBuf};
+
+const RANDOM_CASES: usize = 1_500;
+const MAX_RANDOM_LEN: usize = 4096;
+
+fn corpus_dir(target: &str) -> PathBuf {
+ Path::new(env!("CARGO_MANIFEST_DIR"))
+ .join("../../fuzz/corpus")
+ .join(target)
+}
+
+/// Small xorshift64* stream so every run explores the same inputs.
+struct Xorshift(u64);
+
+impl Xorshift {
+ fn next_u64(&mut self) -> u64 {
+ let mut x = self.0;
+ x ^= x >> 12;
+ x ^= x << 25;
+ x ^= x >> 27;
+ self.0 = x;
+ x.wrapping_mul(0x2545_F491_4F6C_DD1D)
+ }
+
+ fn bytes(&mut self, len: usize) -> Vec<u8> {
+ (0..len).map(|_| self.next_u64() as u8).collect()
+ }
+}
+
+fn run_seed_corpus(target: &str, body: fn(&[u8])) -> usize {
+ let dir = corpus_dir(target);
+ let mut entries: Vec<_> = std::fs::read_dir(&dir)
+ .unwrap_or_else(|error| panic!("seed corpus {} unreadable: {error}", dir.display()))
+ .map(|entry| entry.unwrap().path())
+ .filter(|path| path.is_file())
+ .collect();
+ entries.sort();
+ for path in &entries {
+ let data = std::fs::read(path).unwrap();
+ body(&data);
+ }
+ entries.len()
+}
+
+fn run_random(target: &str, body: fn(&[u8])) {
+ // Seed from the target name so each target walks a distinct stream.
+ let seed = target.bytes().fold(0x9E37_79B9_7F4A_7C15_u64, |acc, byte| {
+ (acc ^ u64::from(byte)).wrapping_mul(0x100_0000_01B3)
+ });
+ let mut rng = Xorshift(seed | 1);
+ for case in 0..RANDOM_CASES {
+ let len = (rng.next_u64() as usize) % (MAX_RANDOM_LEN + 1);
+ let data = rng.bytes(len);
+ // Mix in structurally plausible prefixes so random bytes still reach
+ // the deeper parsing layers some of the time.
+ let data = match case % 4 {
+ 0 => data,
+ 1 => [
+ b"{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"tools/call\",\"params\":".as_slice(),
+ &data,
+ ]
+ .concat(),
+ 2 => [
+ b"{\"session\":\"s\",\"pid\":7,\"window_id\":9,".as_slice(),
+ &data,
+ ]
+ .concat(),
+ _ => [b"{".as_slice(), &data].concat(),
+ };
+ body(&data);
+ }
+}
+
+#[test]
+fn every_target_has_a_seed_corpus() {
+ for (name, body) in TARGETS {
+ let seeds = run_seed_corpus(name, *body);
+ assert!(seeds > 0, "fuzz target {name} has no seed corpus");
+ }
+}
+
+#[test]
+fn mcp_request_survives_random_bytes() {
+ run_random("mcp_request", boundary_fuzz::mcp_request);
+}
+
+#[test]
+fn tool_arguments_survive_random_bytes() {
+ run_random("tool_arguments", boundary_fuzz::tool_arguments);
+}
+
+#[test]
+fn typed_input_json_survives_random_bytes() {
+ run_random("typed_input_json", boundary_fuzz::typed_input_json);
+}
+
+#[test]
+fn registry_invoke_survives_random_bytes() {
+ run_random("registry_invoke", boundary_fuzz::registry_invoke);
+}
+
+#[test]
+fn targets_table_matches_fuzz_target_files() {
+ let dir = Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fuzz/fuzz_targets");
+ let mut files: Vec<String> = std::fs::read_dir(&dir)
+ .unwrap()
+ .map(|entry| {
+ entry
+ .unwrap()
+ .path()
+ .file_stem()
+ .unwrap()
+ .to_string_lossy()
+ .into_owned()
+ })
+ .collect();
+ files.sort();
+ let mut names: Vec<String> = TARGETS.iter().map(|(name, _)| name.to_string()).collect();
+ names.sort();
+ assert_eq!(
+ files, names,
+ "fuzz/fuzz_targets must mirror boundary_fuzz::TARGETS"
+ );
+}
diff --git a/libs/cua-driver/rust/fuzz/.gitignore b/libs/cua-driver/rust/fuzz/.gitignore
new file mode 100644
index 0000000000..a20a207455
--- /dev/null
+++ b/libs/cua-driver/rust/fuzz/.gitignore
@@ -0,0 +1,5 @@
+target/
+artifacts/
+coverage/
+work/
+Cargo.lock
diff --git a/libs/cua-driver/rust/fuzz/Cargo.toml b/libs/cua-driver/rust/fuzz/Cargo.toml
new file mode 100644
index 0000000000..eb325d8460
--- /dev/null
+++ b/libs/cua-driver/rust/fuzz/Cargo.toml
@@ -0,0 +1,48 @@
+[package]
+name = "cua-driver-fuzz"
+version = "0.0.0"
+publish = false
+edition = "2021"
+
+[package.metadata]
+cargo-fuzz = true
+
+[dependencies]
+libfuzzer-sys = "0.4"
+cua-driver-testkit = { path = "../crates/cua-driver-testkit" }
+
+# Detached from the main workspace on purpose: libfuzzer-sys must never enter
+# the shipped or `cargo test` dependency graph.
+[workspace]
+members = ["."]
+
+[profile.release]
+debug = 1
+
+[[bin]]
+name = "mcp_request"
+path = "fuzz_targets/mcp_request.rs"
+test = false
+doc = false
+bench = false
+
+[[bin]]
+name = "tool_arguments"
+path = "fuzz_targets/tool_arguments.rs"
+test = false
+doc = false
+bench = false
+
+[[bin]]
+name = "typed_input_json"
+path = "fuzz_targets/typed_input_json.rs"
+test = false
+doc = false
+bench = false
+
+[[bin]]
+name = "registry_invoke"
+path = "fuzz_targets/registry_invoke.rs"
+test = false
+doc = false
+bench = false
diff --git a/libs/cua-driver/rust/fuzz/README.md b/libs/cua-driver/rust/fuzz/README.md
new file mode 100644
index 0000000000..d3e26b2ce0
--- /dev/null
+++ b/libs/cua-driver/rust/fuzz/README.md
@@ -0,0 +1,49 @@
+# Tool-call boundary fuzzing
+
+Coverage-guided fuzz targets for the transport-free MCP tool-call boundary in
+`cua-driver-core`: JSON-RPC request parsing, reserved-argument stripping,
+argument normalisation, authorization, typed contract input parsing, and
+`ToolRegistry` dispatch against stub tools. No platform adapter, display, or
+input device is touched.
+
+The target bodies live in `cua_driver_testkit::boundary_fuzz`; the files under
+`fuzz_targets/` are one-line libFuzzer wrappers. The same bodies run as bounded
+smoke tests in `cargo test -p cua-driver-testkit`, so this directory is only
+needed for real fuzzing.
+
+The workspace pins a stable toolchain. `cargo fuzz` needs nightly only for
+sanitizers, so run with `--sanitizer none`:
+
+```bash
+cd libs/cua-driver/rust
+nix shell nixpkgs#cargo nixpkgs#rustc nixpkgs#cargo-fuzz --command \
+ cargo fuzz run --fuzz-dir fuzz --sanitizer none mcp_request \
+ fuzz/work/mcp_request fuzz/corpus/mcp_request -- -max_total_time=300
+```
+
+Targets: `mcp_request`, `tool_arguments`, `typed_input_json`, `registry_invoke`.
+
+libFuzzer writes every new input it discovers into the first corpus directory
+it is given. Passing an ignored `fuzz/work/<target>` directory first keeps
+`fuzz/corpus/<target>` limited to the hand-picked seeds that are committed and
+run by the smoke test. Omitting the directories makes `cargo fuzz` write into
+`fuzz/corpus/<target>` directly; delete the generated entries before
+committing if you do that.
+
+Keep the `CUA_DRIVER_*` policy and permission-mode environment variables unset
+while fuzzing so the process-default authorization path stays reproducible.
+
+The `Fuzz: Cua Driver tool-call boundary` GitHub Actions workflow
+(`.github/workflows/fuzz-cua-driver.yml`) runs every target for two minutes on
+pull requests that touch the boundary crates, fifteen minutes nightly, and a
+chosen budget on manual dispatch. A crash fails that target's job, prints the
+panic and reproduce command in the job summary, and uploads the crash file and
+log as an artifact.
+
+A crash lands in `artifacts/<target>/`. Reproduce it with
+`cargo fuzz run --fuzz-dir fuzz --sanitizer none <target> artifacts/<target>/<file>`,
+fix the bug, then copy the file into `corpus/<target>/` so the smoke test keeps
+it as a regression case. Only hand-picked seeds are committed; libFuzzer's
+generated corpus entries stay local.
+
+See `libs/cua-driver/docs/2026-09-04-tool-call-boundary-fuzzing-design.md`.
diff --git a/libs/cua-driver/rust/fuzz/corpus/mcp_request/bool_arguments.json b/libs/cua-driver/rust/fuzz/corpus/mcp_request/bool_arguments.json
new file mode 100644
index 0000000000..4085fc4a6b
--- /dev/null
+++ b/libs/cua-driver/rust/fuzz/corpus/mcp_request/bool_arguments.json
@@ -0,0 +1 @@
+{"jsonrpc":"2.0","id":9,"method":"tools/call","params":{"name":"get_session","arguments":true}}
\ No newline at end of file
diff --git a/libs/cua-driver/rust/fuzz/corpus/mcp_request/click.json b/libs/cua-driver/rust/fuzz/corpus/mcp_request/click.json
new file mode 100644
index 0000000000..4da1e9331e
--- /dev/null
+++ b/libs/cua-driver/rust/fuzz/corpus/mcp_request/click.json
@@ -0,0 +1 @@
+{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"click","arguments":{"session":"seed","pid":42,"window_id":7,"x":10,"y":20}}}
\ No newline at end of file
diff --git a/libs/cua-driver/rust/fuzz/corpus/mcp_request/empty_session.json b/libs/cua-driver/rust/fuzz/corpus/mcp_request/empty_session.json
new file mode 100644
index 0000000000..0044f53e45
--- /dev/null
+++ b/libs/cua-driver/rust/fuzz/corpus/mcp_request/empty_session.json
@@ -0,0 +1 @@
+{"jsonrpc":"2.0","id":8,"method":"tools/call","params":{"name":"click","arguments":{"session":"","_session_id":"forged"}}}
\ No newline at end of file
diff --git a/libs/cua-driver/rust/fuzz/corpus/mcp_request/forged_reserved.json b/libs/cua-driver/rust/fuzz/corpus/mcp_request/forged_reserved.json
new file mode 100644
index 0000000000..804e86c21b
--- /dev/null
+++ b/libs/cua-driver/rust/fuzz/corpus/mcp_request/forged_reserved.json
@@ -0,0 +1 @@
+{"jsonrpc":"2.0","id":4,"method":"tools/call","params":{"name":"browser_download","arguments":{"session":"public","_session_id":"forged","_transport_session_id":"forged","_cua_browser_download_mcp_host_approved":false}}}
\ No newline at end of file
diff --git a/libs/cua-driver/rust/fuzz/corpus/mcp_request/initialize.json b/libs/cua-driver/rust/fuzz/corpus/mcp_request/initialize.json
new file mode 100644
index 0000000000..2a35fb4ab6
--- /dev/null
+++ b/libs/cua-driver/rust/fuzz/corpus/mcp_request/initialize.json
@@ -0,0 +1 @@
+{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","clientInfo":{"name":"seed","version":"1"}}}
\ No newline at end of file
diff --git a/libs/cua-driver/rust/fuzz/corpus/mcp_request/no_arguments.json b/libs/cua-driver/rust/fuzz/corpus/mcp_request/no_arguments.json
new file mode 100644
index 0000000000..ee4ec43d3e
--- /dev/null
+++ b/libs/cua-driver/rust/fuzz/corpus/mcp_request/no_arguments.json
@@ -0,0 +1 @@
+{"jsonrpc":"2.0","id":"x","method":"tools/call","params":{"name":"click"}}
\ No newline at end of file
diff --git a/libs/cua-driver/rust/fuzz/corpus/mcp_request/notification.json b/libs/cua-driver/rust/fuzz/corpus/mcp_request/notification.json
new file mode 100644
index 0000000000..e34059261a
--- /dev/null
+++ b/libs/cua-driver/rust/fuzz/corpus/mcp_request/notification.json
@@ -0,0 +1 @@
+{"jsonrpc":"2.0","method":"notifications/initialized"}
\ No newline at end of file
diff --git a/libs/cua-driver/rust/fuzz/corpus/mcp_request/string_arguments.json b/libs/cua-driver/rust/fuzz/corpus/mcp_request/string_arguments.json
new file mode 100644
index 0000000000..37ad194314
--- /dev/null
+++ b/libs/cua-driver/rust/fuzz/corpus/mcp_request/string_arguments.json
@@ -0,0 +1 @@
+{"jsonrpc":"2.0","id":6,"method":"tools/call","params":{"name":"type_text","arguments":"not-an-object"}}
\ No newline at end of file
diff --git a/libs/cua-driver/rust/fuzz/corpus/mcp_request/tools_list.json b/libs/cua-driver/rust/fuzz/corpus/mcp_request/tools_list.json
new file mode 100644
index 0000000000..fa98a32ce3
--- /dev/null
+++ b/libs/cua-driver/rust/fuzz/corpus/mcp_request/tools_list.json
@@ -0,0 +1 @@
+{"jsonrpc":"2.0","id":2,"method":"tools/list"}
\ No newline at end of file
diff --git a/libs/cua-driver/rust/fuzz/corpus/mcp_request/typed_target.json b/libs/cua-driver/rust/fuzz/corpus/mcp_request/typed_target.json
new file mode 100644
index 0000000000..8a0dfbf321
--- /dev/null
+++ b/libs/cua-driver/rust/fuzz/corpus/mcp_request/typed_target.json
@@ -0,0 +1 @@
+{"jsonrpc":"2.0","id":5,"method":"tools/call","params":{"name":"click","arguments":{"target":{"kind":"window","pid":42,"window_id":7},"element_index":3,"dispatch":"Foreground"}}}
\ No newline at end of file
diff --git a/libs/cua-driver/rust/fuzz/corpus/mcp_request/unknown_method.json b/libs/cua-driver/rust/fuzz/corpus/mcp_request/unknown_method.json
new file mode 100644
index 0000000000..a2c3f54ee4
--- /dev/null
+++ b/libs/cua-driver/rust/fuzz/corpus/mcp_request/unknown_method.json
@@ -0,0 +1 @@
+{"jsonrpc":"2.0","id":7,"method":"nope"}
\ No newline at end of file
diff --git a/libs/cua-driver/rust/fuzz/corpus/registry_invoke/click_like.txt b/libs/cua-driver/rust/fuzz/corpus/registry_invoke/click_like.txt
new file mode 100644
index 0000000000..ee26cb33f7
--- /dev/null
+++ b/libs/cua-driver/rust/fuzz/corpus/registry_invoke/click_like.txt
@@ -0,0 +1 @@
+00{"pid":42,"window_id":7,"x":1,"y":2}
\ No newline at end of file
diff --git a/libs/cua-driver/rust/fuzz/corpus/registry_invoke/conflicting_target.txt b/libs/cua-driver/rust/fuzz/corpus/registry_invoke/conflicting_target.txt
new file mode 100644
index 0000000000..b6cc25955b
--- /dev/null
+++ b/libs/cua-driver/rust/fuzz/corpus/registry_invoke/conflicting_target.txt
@@ -0,0 +1 @@
+10{"target":{"kind":"window","pid":1,"window_id":1},"scope":"window"}
\ No newline at end of file
diff --git a/libs/cua-driver/rust/fuzz/corpus/registry_invoke/dispatch_alias.txt b/libs/cua-driver/rust/fuzz/corpus/registry_invoke/dispatch_alias.txt
new file mode 100644
index 0000000000..3509cc7fd0
--- /dev/null
+++ b/libs/cua-driver/rust/fuzz/corpus/registry_invoke/dispatch_alias.txt
@@ -0,0 +1 @@
+20{"dispatch":"Foreground","pid":3,"window_id":4}
\ No newline at end of file
diff --git a/libs/cua-driver/rust/fuzz/corpus/registry_invoke/empty.txt b/libs/cua-driver/rust/fuzz/corpus/registry_invoke/empty.txt
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/libs/cua-driver/rust/fuzz/corpus/registry_invoke/self_pid.txt b/libs/cua-driver/rust/fuzz/corpus/registry_invoke/self_pid.txt
new file mode 100644
index 0000000000..9de9287bde
--- /dev/null
+++ b/libs/cua-driver/rust/fuzz/corpus/registry_invoke/self_pid.txt
@@ -0,0 +1 @@
+30{"pid":1,"window_id":1}
\ No newline at end of file
diff --git a/libs/cua-driver/rust/fuzz/corpus/tool_arguments/click_like.txt b/libs/cua-driver/rust/fuzz/corpus/tool_arguments/click_like.txt
new file mode 100644
index 0000000000..ee26cb33f7
--- /dev/null
+++ b/libs/cua-driver/rust/fuzz/corpus/tool_arguments/click_like.txt
@@ -0,0 +1 @@
+00{"pid":42,"window_id":7,"x":1,"y":2}
\ No newline at end of file
diff --git a/libs/cua-driver/rust/fuzz/corpus/tool_arguments/conflicting_scope.txt b/libs/cua-driver/rust/fuzz/corpus/tool_arguments/conflicting_scope.txt
new file mode 100644
index 0000000000..42adae8f25
--- /dev/null
+++ b/libs/cua-driver/rust/fuzz/corpus/tool_arguments/conflicting_scope.txt
@@ -0,0 +1 @@
+30{"scope":"desktop","pid":1}
\ No newline at end of file
diff --git a/libs/cua-driver/rust/fuzz/corpus/tool_arguments/desktop_target.txt b/libs/cua-driver/rust/fuzz/corpus/tool_arguments/desktop_target.txt
new file mode 100644
index 0000000000..8c5220b526
--- /dev/null
+++ b/libs/cua-driver/rust/fuzz/corpus/tool_arguments/desktop_target.txt
@@ -0,0 +1 @@
+10{"target":{"kind":"desktop","display_id":"main"},"delivery_mode":"foreground"}
\ No newline at end of file
diff --git a/libs/cua-driver/rust/fuzz/corpus/tool_arguments/forged_session.txt b/libs/cua-driver/rust/fuzz/corpus/tool_arguments/forged_session.txt
new file mode 100644
index 0000000000..7d1b144990
--- /dev/null
+++ b/libs/cua-driver/rust/fuzz/corpus/tool_arguments/forged_session.txt
@@ -0,0 +1 @@
+20{"session":"s","_session_id":"forged"}
\ No newline at end of file
diff --git a/libs/cua-driver/rust/fuzz/corpus/tool_arguments/hotkey_empty_keys.bin b/libs/cua-driver/rust/fuzz/corpus/tool_arguments/hotkey_empty_keys.bin
new file mode 100644
index 0000000000..5f55b269da
--- /dev/null
+++ b/libs/cua-driver/rust/fuzz/corpus/tool_arguments/hotkey_empty_keys.bin
@@ -0,0 +1 @@
+p�r2
\ No newline at end of file
diff --git a/libs/cua-driver/rust/fuzz/corpus/tool_arguments/short.txt b/libs/cua-driver/rust/fuzz/corpus/tool_arguments/short.txt
new file mode 100644
index 0000000000..fa7af8bf5f
--- /dev/null
+++ b/libs/cua-driver/rust/fuzz/corpus/tool_arguments/short.txt
@@ -0,0 +1 @@
+z
\ No newline at end of file
diff --git a/libs/cua-driver/rust/fuzz/corpus/typed_input_json/click.json b/libs/cua-driver/rust/fuzz/corpus/typed_input_json/click.json
new file mode 100644
index 0000000000..983c2e4e9e
--- /dev/null
+++ b/libs/cua-driver/rust/fuzz/corpus/typed_input_json/click.json
@@ -0,0 +1 @@
+{"session":"seed","pid":42,"window_id":7,"x":10,"y":20,"button":"left"}
\ No newline at end of file
diff --git a/libs/cua-driver/rust/fuzz/corpus/typed_input_json/deep_nesting.json b/libs/cua-driver/rust/fuzz/corpus/typed_input_json/deep_nesting.json
new file mode 100644
index 0000000000..486d8fd288
--- /dev/null
+++ b/libs/cua-driver/rust/fuzz/corpus/typed_input_json/deep_nesting.json
@@ -0,0 +1 @@
+[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[
\ No newline at end of file
diff --git a/libs/cua-driver/rust/fuzz/corpus/typed_input_json/duplicate_key.json b/libs/cua-driver/rust/fuzz/corpus/typed_input_json/duplicate_key.json
new file mode 100644
index 0000000000..2d558ca72d
--- /dev/null
+++ b/libs/cua-driver/rust/fuzz/corpus/typed_input_json/duplicate_key.json
@@ -0,0 +1 @@
+{"session":"seed","session":"dup"}
\ No newline at end of file
diff --git a/libs/cua-driver/rust/fuzz/corpus/typed_input_json/empty_object.json b/libs/cua-driver/rust/fuzz/corpus/typed_input_json/empty_object.json
new file mode 100644
index 0000000000..9e26dfeeb6
--- /dev/null
+++ b/libs/cua-driver/rust/fuzz/corpus/typed_input_json/empty_object.json
@@ -0,0 +1 @@
+{}
\ No newline at end of file
diff --git a/libs/cua-driver/rust/fuzz/corpus/typed_input_json/hotkey_empty_keys_sequence.json b/libs/cua-driver/rust/fuzz/corpus/typed_input_json/hotkey_empty_keys_sequence.json
new file mode 100644
index 0000000000..00a55f0496
--- /dev/null
+++ b/libs/cua-driver/rust/fuzz/corpus/typed_input_json/hotkey_empty_keys_sequence.json
@@ -0,0 +1 @@
+[[]]
\ No newline at end of file
diff --git a/libs/cua-driver/rust/fuzz/corpus/typed_input_json/huge_number.json b/libs/cua-driver/rust/fuzz/corpus/typed_input_json/huge_number.json
new file mode 100644
index 0000000000..2bdf41840f
--- /dev/null
+++ b/libs/cua-driver/rust/fuzz/corpus/typed_input_json/huge_number.json
@@ -0,0 +1 @@
+{"session":"seed","pid":42,"window_id":7,"x":1e400}
\ No newline at end of file
diff --git a/libs/cua-driver/rust/fuzz/corpus/typed_input_json/negative_pid.json b/libs/cua-driver/rust/fuzz/corpus/typed_input_json/negative_pid.json
new file mode 100644
index 0000000000..bf16e11cea
--- /dev/null
+++ b/libs/cua-driver/rust/fuzz/corpus/typed_input_json/negative_pid.json
@@ -0,0 +1 @@
+{"session":"seed","pid":-1}
\ No newline at end of file
diff --git a/libs/cua-driver/rust/fuzz/corpus/typed_input_json/null.json b/libs/cua-driver/rust/fuzz/corpus/typed_input_json/null.json
new file mode 100644
index 0000000000..ec747fa47d
--- /dev/null
+++ b/libs/cua-driver/rust/fuzz/corpus/typed_input_json/null.json
@@ -0,0 +1 @@
+null
\ No newline at end of file
diff --git a/libs/cua-driver/rust/fuzz/corpus/typed_input_json/unicode_escapes.json b/libs/cua-driver/rust/fuzz/corpus/typed_input_json/unicode_escapes.json
new file mode 100644
index 0000000000..cee0d6fef8
--- /dev/null
+++ b/libs/cua-driver/rust/fuzz/corpus/typed_input_json/unicode_escapes.json
@@ -0,0 +1 @@
+{"session":"\ud83d\ude00","text":"caf\u00e9\n"}
\ No newline at end of file
diff --git a/libs/cua-driver/rust/fuzz/fuzz_targets/mcp_request.rs b/libs/cua-driver/rust/fuzz/fuzz_targets/mcp_request.rs
new file mode 100644
index 0000000000..de4a96cc88
--- /dev/null
+++ b/libs/cua-driver/rust/fuzz/fuzz_targets/mcp_request.rs
@@ -0,0 +1,5 @@
+#![no_main]
+
+use libfuzzer_sys::fuzz_target;
+
+fuzz_target!(|data: &[u8]| cua_driver_testkit::boundary_fuzz::mcp_request(data));
diff --git a/libs/cua-driver/rust/fuzz/fuzz_targets/registry_invoke.rs b/libs/cua-driver/rust/fuzz/fuzz_targets/registry_invoke.rs
new file mode 100644
index 0000000000..1a6ae14eed
--- /dev/null
+++ b/libs/cua-driver/rust/fuzz/fuzz_targets/registry_invoke.rs
@@ -0,0 +1,5 @@
+#![no_main]
+
+use libfuzzer_sys::fuzz_target;
+
+fuzz_target!(|data: &[u8]| cua_driver_testkit::boundary_fuzz::registry_invoke(data));
diff --git a/libs/cua-driver/rust/fuzz/fuzz_targets/tool_arguments.rs b/libs/cua-driver/rust/fuzz/fuzz_targets/tool_arguments.rs
new file mode 100644
index 0000000000..1ae8f91ab9
--- /dev/null
+++ b/libs/cua-driver/rust/fuzz/fuzz_targets/tool_arguments.rs
@@ -0,0 +1,5 @@
+#![no_main]
+
+use libfuzzer_sys::fuzz_target;
+
+fuzz_target!(|data: &[u8]| cua_driver_testkit::boundary_fuzz::tool_arguments(data));
diff --git a/libs/cua-driver/rust/fuzz/fuzz_targets/typed_input_json.rs b/libs/cua-driver/rust/fuzz/fuzz_targets/typed_input_json.rs
new file mode 100644
index 0000000000..0b68e305a7
--- /dev/null
+++ b/libs/cua-driver/rust/fuzz/fuzz_targets/typed_input_json.rs
@@ -0,0 +1,5 @@
+#![no_main]
+
+use libfuzzer_sys::fuzz_target;
+
+fuzz_target!(|data: &[u8]| cua_driver_testkit::boundary_fuzz::typed_input_json(data));