Skip to content

Use null-prototype descriptors in per-call node code - #8520

Merged
littledivy merged 1 commit into
mainfrom
littledivy/2026-11-17-node-proto-descriptors
Nov 18, 2026
Merged

littledivy merged 1 commit into
mainfrom
littledivy/2026-11-17-node-proto-descriptors

Conversation

@littledivy

@littledivy littledivy commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

#8462 fixed the descriptor literals in the lazily loaded stdio graph, but several node: functions still build plain descriptor literals each time they're called. When worker code has added get, set, value, writable or enumerable to Object.prototype, those literals inherit it. Object.defineProperty then either throws Invalid property descriptor or quietly changes the property. For example, every node:http request threw while it set up req.socket.

In this patch those descriptors use __proto__: kNullProtoObject, at the same sites that have __proto__: null in Node.js. The sites are req.socket in IncomingMessage, util.inspect() of JSG resources, the Console constructor, util.debuglog(), assigning process.stdout/stderr/stdin, util.inherits() and util.promisify(). A new test calls each one with each descriptor field added to Object.prototype, in one isolate per field.

Nothing changes for a Worker that leaves Object.prototype alone. With one of these fields added, the calls that threw now work, and the properties keep the attributes they have in Node.js instead of inheriting them, so there is no compatibility flag.

@littledivy
littledivy requested review from a team as code owners November 17, 2026 05:51

@clanky-the-clanker clanky-the-clanker Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Superseded by the review of 8a3e3e65.

This review, of fa2f2edb

💬 Approved with comments — The approach is sound and well tested. One WARNING: the ordinary util.promisify() path still uses a plain descriptor literal and throws when Object.prototype.get or .set is defined.

Findings: 1 warning (1 is an inline comment on the diff)

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.

🔧 Fix with your agent

Paste the following into your coding agent to investigate and fix these issues.

Fix the following code review issues found in pull request #8520.

Before making changes, review each issue and present a brief summary table:
- For each finding, state whether you agree, disagree, or need clarification
- If you disagree (e.g., the fix would require disproportionate changes
  for minimal ROI, or the finding is factually incorrect), explain why
- If you need to clarify something before deciding, ask those questions
- Then share your plan for which issues to tackle and in what order

## WARNING (1)

### [Code Quality] util.promisify() on a function without util.promisify.custom still defines kCustomPromisifiedSymbol with a plain descriptor literal (src/node/util.ts:173), so it throws when Object.prototype.get or .set is defined.
- **File:** src/node/util.ts:140

📋 Code Quality: ⚠️ 1 warning

The ordinary util.promisify() path still builds a plain descriptor literal, and the new test does not cover it.

Recommendation: 📝 Minor Comments

  • [WARNING] util.promisify() on a function without util.promisify.custom still defines kCustomPromisifiedSymbol with a plain descriptor literal (src/node/util.ts:173), so it throws when Object.prototype.get or .set is defined. (src/node/util.ts:140)
View full review

Missed site in util.promisify (src/node/util.ts:173-178)

The pull request makes the descriptor in the util.promisify.custom branch (line 138) a null-prototype object. The branch that every util.promisify(fn) call without a custom symbol takes still has a plain literal at line 173:

Object.defineProperty(fn, kCustomPromisifiedSymbol, {
  value: fn,
  enumerable: false,
  writable: false,
  configurable: true,
});

If Object.prototype.get or .set is defined, this literal inherits an accessor field next to its own value, and defineProperty throws Invalid property descriptor. Node.js uses __proto__: null at this site too. The same function already gives the defineProperties descriptors a null prototype a few lines later, so leaving this one out looks accidental.

Fix: add // @ts-expect-error TS2353 Required for __proto__ and __proto__: kNullProtoObject, to that literal. Also add a test case that calls util.promisify on a plain callback-style function under each polluted key. With the current code it fails for get and set.


✅ All other checks passed

🔒 Security: ✅ LGTM

Null-prototype descriptors protect these sites from changes made to Object.prototype. No security issues found.


📖 AGENTS.md: ✅ LGTM

No AGENTS.md updates needed.


⚡ Performance: ✅ LGTM

No performance concerns.


📝 Documentation: ✅ LGTM

No documentation issues.


Reviewed commit: fa2f2edb

Comment thread src/node/util.ts Resolved
#8462 fixed the descriptor literals in the lazily loaded stdio graph, but several node: functions still build plain descriptor literals each time they're called. When worker code has added `get`, `set`, `value`, `writable` or `enumerable` to `Object.prototype`, those literals inherit it. `Object.defineProperty` then either throws `Invalid property descriptor` or quietly changes the property. For example, every node:http request threw while it set up `req.socket`.

In this patch those descriptors use `__proto__: kNullProtoObject`, at the same sites that have `__proto__: null` in Node.js. The sites are `req.socket` in `IncomingMessage`, `util.inspect()` of JSG resources, the `Console` constructor, `util.debuglog()`, assigning `process.stdout`/`stderr`/`stdin`, `util.inherits()` and `util.promisify()`. A new test calls each one with each descriptor field added to `Object.prototype`, in one isolate per field. The properties defined are unchanged, so there is no compatibility flag.
@littledivy
littledivy force-pushed the littledivy/2026-11-17-node-proto-descriptors branch from fa2f2ed to 8a3e3e6 Compare November 17, 2026 05:56

@clanky-the-clanker clanky-the-clanker Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Approved — The util.promisify() descriptor that the last review flagged now has a null prototype, and the new test covers it. No other findings.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

🔒 Security: ✅ LGTM

Null-prototype descriptors keep these sites working when worker code changes Object.prototype. No security issues found.


📖 AGENTS.md: ✅ LGTM

No AGENTS.md updates needed.


📋 Code Quality: ✅ LGTM

The plain-function branch of util.promisify now builds its kCustomPromisifiedSymbol descriptor with __proto__: kNullProtoObject (src/node/util.ts:173-180). The new utilPromisify case in node-proto-descriptor-pollution-test.js promisifies a callback-style function with no custom symbol once for each polluted descriptor field, so this branch is covered. None of the other changed files has a missed site.


⚡ Performance: ✅ LGTM

No performance concerns.


📝 Documentation: ✅ LGTM

No documentation issues.


Reviewed commit: 8a3e3e65

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 66.37%. Comparing base (5713cd2) to head (8a3e3e6).
⚠️ Report is 11 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8520      +/-   ##
==========================================
- Coverage   66.44%   66.37%   -0.07%     
==========================================
  Files         794      795       +1     
  Lines      202976   203212     +236     
  Branches    31536    31541       +5     
==========================================
+ Hits       134868   134886      +18     
- Misses      49646    49864     +218     
  Partials    18462    18462              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@littledivy
littledivy merged commit 71534e6 into main Nov 18, 2026
25 checks passed
@littledivy
littledivy deleted the littledivy/2026-11-17-node-proto-descriptors branch November 18, 2026 04:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants