deno
3716eb4d - fix(node): restore Object.prototype.__proto__ for CJS modules

Commit
34 days ago
fix(node): restore Object.prototype.__proto__ for CJS modules Deno deletes `Object.prototype.__proto__` during bootstrap for security reasons (preventing the prototype-pollution accessor exposed by Annex B). Many npm packages, however, install their prototype chain with `Child.prototype.__proto__ = Parent.prototype`. With the accessor gone that assignment silently becomes a plain own-property write that leaves the real [[Prototype]] unchanged, so methods that rely on the inherited behavior fall back to default paths and (in the stylus case) recurse forever until V8 reports "Maximum call stack size exceeded". Save the original `__proto__` descriptor on `internals` before deleting it and reinstall it lazily on the first CJS module compile in `wrapSafe()`. Pure-ESM programs that never load a CJS module keep the hardened default, so the existing `unsafe_proto` test still passes. Adds spec tests under `run/cjs/proto_chain_via_dunder` covering the inheritance case, the unchanged ESM-only behavior, and the lazy restoration path. Closes denoland/orchid#219 Co-Authored-By: Divy Srivastava <me@littledivy.com>
Author
Committer
Parents
Loading