Security Core

ProtoShield — Anti-Prototype Pollution Engine

Native runtime defense against Prototype Pollution attacks in V8 (Node.js) and JavaScriptCore (Bun). Protects global intrinsics directly at engine boot time before any route handler, plugin, or user script runs.

Zero-Trust Runtime Defense
ProtoShield protects core JavaScript prototypes (Object.prototype, Array.prototype, Function.prototype) against unauthorized mutations, neutralizing recursive merge exploits, malicious supply chain injections, and unvalidated JSON payload overrides.

1. What is Prototype Pollution?

In JavaScript runtimes, all plain objects inherit properties and methods from prototypes up the chain to Object.prototype. If an attacker or an unvetted third-party dependency injects properties into Object.prototype (e.g. through recursive object cloning, merge utilities, or query string parsers), every object across the entire runtime process immediately inherits that malicious property:

Vulnerable Payload / Rogue Library
javascript
// 1. Rogue dependency or unvalidated recursive merge:
Object.prototype.isAdmin = true;

// 2. Unrelated, legitimate application code:
const session = {};
if (session.isAdmin) {
    // CRITICAL: Privilege escalation triggered
    // across the entire application runtime!
}

Primary Attack Vectors

  • Remote Code Execution (RCE): Polluting execution flags such as NODE_OPTIONS, shell, or child process spawn arguments.
  • Privilege Escalation & Auth Bypass: Injecting truthy keys into authorization checks (e.g. role, isAdmin, verified).
  • Denial of Service (DoS): Overwriting fundamental intrinsics like toString, valueOf, or hasOwnProperty.
Mitigated automatically by ProtoShield at the engine boot phase.

2. The XyPriss Defense: $protoShield

Configured declaratively in xypriss.config.jsonc, ProtoShield intercepts tampering at the lowest JavaScript intrinsic level. It applies fail-closed runtime protections before your application logic begins execution:

1. Property Interception (mode: "block")

Intercepts direct assignment (Object.prototype.evil = true) and descriptor definitions (Object.defineProperty), rejecting unauthorized keys with a security alert.

2. __proto__ Neutralization

Neutralizes the mutable accessor on Object.prototype, disarming recursive merge tools (such as vulnerable versions of lodash.merge, deepmerge, etc.).

3. Intrinsic Freezing (mode: "freeze")

Deeply freezes standard intrinsics (Object.prototype, Array.prototype, Function.prototype) via Object.preventExtensions and Object.freeze.

4. Boot-Time Fail-Closed Validation

Any syntax error, typo (e.g. neuterProto), or invalid value in your configuration halts the server immediately with explicit diagnostics.

3. Configuration Reference ($protoShield)

Declare the $protoShield section in your root xypriss.config.jsonc (or xypriss.config.json):

jsonc
// xypriss.config.jsonc
{
  "$protoShield": {
    "enabled": true,
    "mode": "block",
    "neutralizeProto": true,
    "freezePrototypes": false,
    "allowedProperties": []
  }
}
OptionTypeDefaultDescription
enabledbooleantrueEnables or disables ProtoShield runtime enforcement.
mode"block" | "warn" | "freeze""block"Enforcement mode when an unauthorized prototype mutation is attempted.
neutralizeProtobooleantrueDisarms Object.prototype.__proto__ to block recursive chain traversal attacks.
freezePrototypesbooleanfalseCompletely freezes Object.prototype, Array.prototype, and Function.prototype.
allowedPropertiesstring[][]Explicit whitelist of properties allowed to be defined on Object.prototype (e.g. polyfills).

4. Enforcement Modes

Recommended Default

mode: "block"

Intercepts all unauthorized additions or modifications to prototype chains. Drops assignments silently or throws in strict mode, emitting a security alert:

[XyPriss ProtoShield] Blocked Prototype Pollution attempt! Unauthorized property 'polluted_var' on Object.prototype.
Audit & Migration

mode: "warn"

Allows the mutation to proceed, but logs a security warning with an execution stack trace. Ideal for assessing legacy packages prior to enforcing strict blocking.

Non-disruptive inspection mode
Maximum Hardening

mode: "freeze"

Calls Object.preventExtensions and Object.freeze on core intrinsics at boot time. Guarantees complete immutability at the engine level.

Engine-level absolute immutability

5. Neutralizing __proto__

Recursive merge utilities commonly traverse nested object graphs by checking for key names matching "__proto__":

javascript
// Exploitation attempt via untrusted JSON input:
const payload = JSON.parse('{"__proto__": {"admin": true}}');
merge({}, payload);

When neutralizeProto: true (enabled by default), ProtoShield replaces Object.prototype.__proto__ with a secure accessor:

  • Reading obj.__proto__ safely returns Object.getPrototypeOf(obj).
  • Setting obj.__proto__ = value is completely blocked, emitting a security log and preserving prototype chain integrity.

6. Whitelisting Legitimate Polyfills

If your application or a legacy library requires attaching a legitimate helper to Object.prototype or Array.prototype, declare it in allowedProperties:

jsonc
{
  "$protoShield": {
    "enabled": true,
    "mode": "block",
    "allowedProperties": [
      "customSafeHelper",
      "myPolyfill"
    ]
  }
}

7. Strict Boot-Time Validation (Fail-Closed)

To prevent silent security omissions caused by typos, XyPriss validates $protoShield at boot time. If an unknown property or invalid type is detected, the server refuses to start:

bash
# Typo: "$protoShield": { "mode": "blocking" }
[XyPriss Validation Error] Invalid '$protoShield.mode': "blocking". Accepted values are: 'block', 'warn', 'freeze'.
bash
# Typo: "$protoShield": { "neuterProto": true }
[XyPriss Validation Error] Unknown property '$protoShield.neuterProto' in xypriss.config.json(c). Allowed properties: 'enabled', 'mode', 'neutralizeProto', 'freezePrototypes', 'allowedProperties'

8. Programmatic API

ProtoShield can also be initialized or reconfigured programmatically via the official xypriss export:

typescript
import { ProtoShield, type ProtoShieldConfig } from "xypriss";

// Manually initialize or reconfigure
ProtoShield.initialize({
    mode: "block",
    neutralizeProto: true,
    allowedProperties: ["customHelper"],
});

9. Performance Impact

Zero Runtime Overhead

Standard object creations ({}, new MyClass()), lookups, and mutations execute at full native JIT speed with zero proxy layers.

Sub-Millisecond Boot

Intrinsics protection is established once during process initialization in under 1 millisecond.

Dual Runtime Engine

Engineered and tested with both V8 (Node.js) and JavaScriptCore (Bun) runtimes.

Environment Security Shield (libXESS)

Learn how libXESS secures process memory, eliminates secret leaks, and serves honeypot canaries.