WebAssembly Sandbox Security - 3D Scene

Watch a module run inside bounded linear memory: guard slabs trap stray writes, and only linked imports pass the gate.

Switch to 2D

Presets

Playback

Memory and probe

Committed pages, the instruction offset and how far the probe write overshoots.

Guard region

Which strategy the engine reserved.

Host-granted imports

Click to link or unlink; fixed ones cannot change.

Camera

Quality

Layers

Model checks

The science

Linear memory and the bounds rule

A WebAssembly instance sees one contiguous byte array, its linear memory, made of 64 KiB pages. Every load or store computes an effective address ea = base + offset from two unsigned 32-bit numbers (the pointer and the static offset encoded in the instruction) and is legal only if ea + len ≤ memory.size. The sum is formed in 64-bit arithmetic, so it never wraps round to a small address. Anything else is a trap: the module stops and the host is untouched. For a pointer drawn uniformly from all 232 values the chance of a legal access is (size − offset − len + 1) / 232 - a few parts per million for a few pages - and the page measures it by Monte Carlo as an independent check.

Guard regions or explicit checks

64-bit engines usually reserve 4 GiB of address space per instance plus a guard region. Pages the module has not been granted are simply unmapped, so a stray store faults in hardware and costs zero extra instructions. When a static offset is larger than the guard the compiler cannot rely on the fault and emits an explicit compare-and-branch instead (modelled here as three instructions). Either way the outcome is the same trap; only the price differs.

Capabilities instead of system calls

WebAssembly has no instruction that talks to the operating system. A module can only call imports the host linked when it created the instance. This is capability-based security: console.log and math.sqrt are linked, fs.open and net.connect can be granted or revoked by the host, and process.spawn cannot be linked at all in this model. A call to something not in the import table never reaches the host. The attack surface readout is the share of the five candidate imports that are linked.

Honest simplifications: a real engine also validates the module before running it, may add Spectre mitigations, and shares one process with the host; this page models only memory bounds and the import table. The 3 instructions per explicit check, the 12-page limit and the 2/4 GiB guard sizes are illustrative round numbers, not any single engine's defaults. The page shows defensive mechanisms only; it contains no exploit code.

What to try
  • Press Out-of-bounds write: the red packet is stopped at the guard slab and the status line names the mechanism that caught it.
  • Choose Large offset: explicit check and fire it again: the trap is the same but the bounds-check cost goes from 0 to 3 instructions.
  • Press Call ungranted import, then toggle fs.open on and watch its gate retract and the same call reach the host.
  • Raise the committed pages and see the legal-access probability on the first graph climb in steps of 64 KiB / 232.
  • Click process.spawn: it stays locked, because there is no such import to link.
Loading Blender model...
Legal-access probability against committed pages
Valid writes and traps over time
Import calls per capability
Made with 🟠 Blender · Three.js