Repository navigation
Use null-prototype descriptors in per-call node code - #8520
Conversation
There was a problem hiding this comment.
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
#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.
fa2f2ed to
8a3e3e6
Compare
There was a problem hiding this comment.
✅ 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 Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
#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,writableorenumerabletoObject.prototype, those literals inherit it.Object.definePropertythen either throwsInvalid property descriptoror quietly changes the property. For example, every node:http request threw while it set upreq.socket.In this patch those descriptors use
__proto__: kNullProtoObject, at the same sites that have__proto__: nullin Node.js. The sites arereq.socketinIncomingMessage,util.inspect()of JSG resources, theConsoleconstructor,util.debuglog(), assigningprocess.stdout/stderr/stdin,util.inherits()andutil.promisify(). A new test calls each one with each descriptor field added toObject.prototype, in one isolate per field.Nothing changes for a Worker that leaves
Object.prototypealone. 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.