Summary
A sandbox escape in SandboxJS before version 0.8.29 allows an attacker to bypass prototype whitelist enforcement by shadowing hasOwnProperty on sandboxed objects.
Once the check is disabled, blocked properties like __proto__ become directly accessible, enabling host Object.prototype pollution and persistent, cross-sandbox compromise of code execution and data integrity.
Affected context
This issue affects applications that:
- Embed untrusted or semi-trusted JavaScript code using SandboxJS for isolation
- Rely on SandboxJS's property access and prototype whitelisting to prevent access to dangerous object internals
- Allow sandboxed code to define or modify object properties, including
hasOwnPropertyor similar keys
In such environments, the sandbox is expected to enforce restrictions on prototype properties like __proto__, but that enforcement can be bypassed when hasOwnProperty is shadowed inside the sandbox.
Exploit preconditions
- Attack surface: Any interface where untrusted JavaScript is executed inside SandboxJS (e.g., plugins, user scripts, rules engines, customization hooks, or multi-tenant logic).
- Required access: Ability to submit or influence JavaScript that runs in the SandboxJS environment.
- Trigger point: Creation or modification of an object within the sandbox such that its own
hasOwnPropertyshadows the expected method, followed by property access operations. - Why exploitation is possible: The sandbox's property-access path assumes
hasOwnPropertyis trustworthy for prototype whitelist enforcement. When it is shadowed, the check becomes ineffective, allowing direct access to blocked prototype properties like__proto__, leading to hostObject.prototypepollution and persistent cross-sandbox manipulation.
Why this happens
The underlying bug is a logic flaw in how SandboxJS enforces prototype whitelisting for property access.
The enforcement code relies on hasOwnProperty on sandbox objects to determine whether a given property should be allowed, effectively trusting an attacker-controlled property on the object itself.
By redefining or shadowing hasOwnProperty, sandboxed code can disable or alter this check so that restricted properties (e.g., __proto__) pass through.
This maps to CWE-74: Improper Neutralization of Special Elements in Output Used by a Downstream Component (Injection) in the sense that untrusted inputs (sandboxed code and properties) can influence downstream behavior (sandbox enforcement) and inject changes into shared prototypes.
Conceptually, the sandbox conflates user-controlled object state with its security boundary logic, enabling prototype pollution and a full sandbox escape.
Potential impact
- Manipulation of
Object.prototypein the host context, affecting all objects that inherit from it - Bypassing sandbox restrictions and escaping from the intended JS isolation boundary
- Persistent cross-sandbox impact where one tenant's code can influence other sandboxes or host logic
- Alteration of application control flow, data validation, or security checks that depend on prototype methods
- Potential arbitrary code execution in the broader application context, depending on how SandboxJS is integrated
General mitigation guidance
Effective mitigation focuses on hardening the sandbox boundary and removing trust in attacker-controlled object properties:
- Design sandbox enforcement to avoid reliance on mutable, user-controlled object methods (e.g., do not trust
obj.hasOwnPropertyor similar instance methods for security logic). - Use robust, reference-safe patterns such as
Object.prototype.hasOwnProperty.call(obj, key)from a trusted, non-overridable reference, or internal metadata to track allowed properties. - Enforce strict controls around prototype access, ensuring that properties like
__proto__,constructor, and other prototype-linked fields are blocked via defensive checks not influenced by sandboxed code. - Reduce the privileges of sandboxed environments: ensure they cannot access sensitive APIs, global objects, or host-side capabilities beyond what is strictly necessary.
- Consider multiple layers of isolation (e.g., process or VM-based isolation) for running highly untrusted code, instead of relying solely on an in-process JavaScript sandbox.
- Regularly review and test sandbox logic against known prototype pollution and sandbox escape patterns to ensure that enforcement is resilient to shadowing and tampering.
How teams detect issues like this
Detection typically involves a combination of code-centric and behavior-centric approaches:
- Static analysis and code review:
- Search for security-critical checks that depend on methods obtained from potentially attacker-controlled objects (e.g.,
obj.hasOwnProperty(...)instead of using a trusted reference). - Flag sandbox or access-control code where prototype or property restrictions rely on values from the sandboxed environment itself.
- Look for any direct or indirect allowance of
__proto__,constructor, or prototype chain manipulation within sandboxed code paths. - Automated tooling and tests:
- Integrate security-focused static analyzers or linters that recognize prototype pollution patterns and dangerous property access sequences.
- Add regression tests that attempt to shadow core methods (like
hasOwnProperty) inside the sandbox and verify that restricted properties remain inaccessible. - Use fuzzing or property-based tests that generate mutated object shapes and method overrides to stress-test sandbox enforcement.
- Runtime monitoring (where feasible):
- Instrument sandbox environments to flag attempts to access or define suspicious properties such as
__proto__,prototype,constructor, or overwritten fundamental methods.

