docs/sandbox/architecture.md
This document describes the architecture of the V8 Sandbox, a low-overhead, in-process sandbox designed to protect the rest of the process from typical V8 vulnerabilities.
The V8 Sandbox restricts the code executed by V8 to a subset of the process's virtual address space (typically 1TB), called the sandbox. All untrusted V8 objects live inside this sandbox. If an attacker exploits a vulnerability to gain arbitrary read/write primitives, they are ideally confined to this sandbox and cannot corrupt memory outside of it.
The sandbox works purely in software by converting raw pointers into either:
The sandbox assumes that an attacker can:
The goal is to prevent the attacker from corrupting memory outside the sandbox. Any such corruption is considered a sandbox violation.
To maintain isolation, V8 replaces raw pointers with specialized pointer types when referencing objects across the sandbox boundary or even within it for specific security properties.
To securely reference objects outside the sandbox, V8 uses indirection via pointer tables located outside the sandbox. An attacker can only modify the index (which is inside the sandbox), but the table itself is protected.
CppHeap. It is an index into the CppHeapPointerTable. It uses a different type tagging scheme supporting type hierarchies.Code object, using the CodePointerTable (CPT). This also directly provides the entry point for execution.TrustedObjects in trusted space. They are implemented as compressed pointers but relative to the trusted space base. Neither the pointer nor the object can be modified by an attacker.The ExternalPointerTable (EPT) is a fundamental component of the V8 Sandbox designed to provide memory-safe access to objects located outside the V8 heap (external pointers) from within the sandbox.
Indirection via Handles:
ExternalPointerHandle, which is an index into the EPT.Type Tagging:
ExternalPointerTag).Temporal Memory Safety (Garbage Collection):
Managed Resources:
ManagedResource class provides a way to explicitly zap (invalidate) the table entry when the external resource is destroyed. This prevents dangling pointers and use-after-free vulnerabilities.TrustedObject). Attackers cannot directly write to this space.src/sandbox/: Implementation of the sandbox.src/sandbox/sandbox.h: Main sandbox class and configuration.src/sandbox/external-pointer-table.h: External pointer table implementation.src/sandbox/code-pointer-table.h: Code pointer table implementation.src/sandbox/trusted-pointer-table.h: Trusted pointer table implementation.src/sandbox/cppheap-pointer-table.h: CppHeap pointer table implementation.