SES (Secure EcmaScript) is a JavaScript shim providing a hardened environment for robust security and fearless cooperation. It implements Hardened JavaScript, a subset of JavaScript proposed to ECMA TC39, designed to prevent prototype pollution and other common vulnerabilities. The current stable version, 2.0.0, focuses on plugging side-channel attacks and refining security guarantees. SES operates by 'locking down' the global environment, freezing intrinsic objects, and providing the `Compartment` constructor for creating isolated execution contexts. Each `Compartment` has its own global object and module system but shares hardened, immutable primordials with other compartments. This approach ensures that mutually suspicious code can interact safely via object-capability (ocap) principles, where powers are explicitly granted. The package maintains an active release cadence, with frequent updates across the broader `@endo` ecosystem. Key differentiators include its comprehensive protection against tampering with built-in objects, enforcement of strict mode, and its utility in sandboxing third-party code for applications like blockchain smart contracts and browser extensions, notably used by Agoric and MetaMask.
npm install sesVerified import paths — ran on the pinned version, not inferred.
Demonstrates locking down the global environment and securely executing untrusted TypeScript code within an isolated Compartment, explicitly granting limited capabilities like logging and a custom greeting function. It also shows how attempts at prototype pollution or unauthorized global access are prevented.
Upgrade `ses` to version 2.0.0 or higher. Ensure your application architecture accounts for the strictness introduced by `lockdown()` regarding numeric representations.
Ensure `lockdown()` is the very first significant operation in your main entry point. Avoid calling it multiple times or after third-party libraries have initialized, as they might expect a mutable global environment.
Do not rely on global `new Function()` or `eval()` after `lockdown()`. Instead, use `compartment.evaluate(code)` for code evaluation within an explicitly controlled, isolated environment. For dynamic module loading, use `compartment.import()` or `compartment.moduleMapHook`.
Explicitly pass any required ambient authority (e.g., `console.log`, `fetch`) into the `Compartment`'s `globals` or via its `importHook` and `moduleMap`. Use `harden()` on any objects passed into the `globals` to prevent the compartment from tampering with them.
Do not attempt to modify built-in objects or their prototypes after `lockdown()` has been called. If you need to introduce polyfills or shims, they must be applied *before* `lockdown()`.
To grant access to specific host APIs, pass them explicitly into the `Compartment`'s `globals` option. For example: `new Compartment({ globals: { fetch: harden(globalThis.fetch) } })`. Ensure any granted capabilities are `harden()`ed.Use the `Compartment.prototype.evaluate(code)` method to securely run code within a specific `Compartment`'s scope. For dynamic module loading, explore `Compartment.prototype.import()` or `Compartment`'s `moduleMapHook`.
No dependency data recorded yet.