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.
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:
// 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, orhasOwnProperty.
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:
Intercepts direct assignment (Object.prototype.evil = true) and descriptor definitions (Object.defineProperty), rejecting unauthorized keys with a security alert.
Neutralizes the mutable accessor on Object.prototype, disarming recursive merge tools (such as vulnerable versions of lodash.merge, deepmerge, etc.).
Deeply freezes standard intrinsics (Object.prototype, Array.prototype, Function.prototype) via Object.preventExtensions and Object.freeze.
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):
// xypriss.config.jsonc
{
"$protoShield": {
"enabled": true,
"mode": "block",
"neutralizeProto": true,
"freezePrototypes": false,
"allowedProperties": []
}
}| Option | Type | Default | Description |
|---|---|---|---|
| enabled | boolean | true | Enables or disables ProtoShield runtime enforcement. |
| mode | "block" | "warn" | "freeze" | "block" | Enforcement mode when an unauthorized prototype mutation is attempted. |
| neutralizeProto | boolean | true | Disarms Object.prototype.__proto__ to block recursive chain traversal attacks. |
| freezePrototypes | boolean | false | Completely freezes Object.prototype, Array.prototype, and Function.prototype. |
| allowedProperties | string[] | [] | Explicit whitelist of properties allowed to be defined on Object.prototype (e.g. polyfills). |
4. Enforcement Modes
mode: "block"
Intercepts all unauthorized additions or modifications to prototype chains. Drops assignments silently or throws in strict mode, emitting a security alert:
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.
mode: "freeze"
Calls Object.preventExtensions and Object.freeze on core intrinsics at boot time. Guarantees complete immutability at the engine level.
5. Neutralizing __proto__
Recursive merge utilities commonly traverse nested object graphs by checking for key names matching "__proto__":
// 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 returnsObject.getPrototypeOf(obj). - Setting
obj.__proto__ = valueis 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:
{
"$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:
# Typo: "$protoShield": { "mode": "blocking" }
[XyPriss Validation Error] Invalid '$protoShield.mode': "blocking". Accepted values are: 'block', 'warn', 'freeze'.# 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:
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.
Learn how libXESS secures process memory, eliminates secret leaks, and serves honeypot canaries.
