Repository navigation
Conversation
…merable Node defines the 28 members of X509Certificate.prototype and the KeyObject getters (type, symmetricKeySize, asymmetricKeyType, asymmetricKeyDetails) in class bodies, so none is enumerable. The property tables have installed them without DontEnum since the classes shipped (#16173, #19040). Object.entries, Object.assign, spread, and a for..in walk that reads each key call each getter with the prototype as the receiver, and the getter throws ERR_INVALID_THIS. The X509Certificate prototype became reachable in 1.3.11 (#27455). The KeyObject getters throw for a wrong receiver since 1.4.0 (#32623). bluebird's promisifyAll(require("crypto")) does that walk, so random-number-csprng has thrown since 1.3.11. Add DontEnum to the 32 table rows. Nothing else changes. The 28 X509Certificate rows come from the X509 half of #31807.
|
Status: the diff is complete. A maintainer must decide on the getter change: see "The decision for a maintainer" in the Notes of the description. Reproduced on the 1.4.3 canary release build and on main (5c6d4e2). The reference is node v26.3.0. const { X509Certificate, KeyObject } = require("crypto");
const keys = []; for (const k in X509Certificate.prototype) keys.push(k);
console.log(keys.length, Object.getOwnPropertyDescriptor(KeyObject.prototype, "type").enumerable);
// main: 28 true
// node: 0 false
// this PR: 0 falseThe repro of #29533 ( After bluebird's |
|
Updated 1:26 PM PT - Oct 24th, 2026
✅ @robobun, your commit 65a150de49c4e3ed7edd370c2ac1279492a22a92 passed in 🧪 To try this PR locally: bunx bun-pr 46622That installs a local version of the PR into your bun-46622 --bun |
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Make crypto prototype members non-enumerable src/jsc/bindings/JSX509CertificatePrototype.cpp, src/jsc/bindings/node/crypto/JS*KeyObjectPrototype.cpp, test/js/node/crypto/crypto.key-objects.test.ts, test/js/node/crypto/x509.test.ts |
X509Certificate methods and accessors, and selected KeyObject accessors, now include the DontEnum attribute. Tests check descriptors, enumeration, cloning, Worker deserialization, invalid accessor receivers, and Bun.inspect output. |
Guard lazy getters on crypto prototypes src/js/internal/streams/lazy_transform.ts, src/js/node/crypto.ts, src/js/builtins.d.ts, test/js/node/crypto/node-crypto.test.js |
LazyTransform tracks registered prototypes and returns undefined from lazy getters on those prototypes. Hash, Hmac, Cipheriv, and Decipheriv use the registration function. Tests check prototype traversal and stream state. |
Add Bluebird regression coverage test/package.json, test/js/node/crypto/node-crypto.test.js, test/regression/issue/29533.test.ts |
Bluebird is added as a test dependency. Tests cover loading crypto after replacing global Set and Bluebird promisification of crypto.randomBytes. |
Possibly related issues
- oven-sh/bun#29533 — The regression test covers Bluebird promisification of
node:crypto, the reported issue’s behavior.
Possibly related PRs
- oven-sh/bun#46730 — Both PRs address the Bluebird failure in issue
#29533, through different mechanisms.
Priority:
Severity of issue fixed: Medium
Merge Risk: 
Minimal · up to 65a15
-
The compatibility fix appears ready to merge after normal checks; no actionable merge-blocking issue was established.
Pre-merge checks: 
4
-
Full details: Title check
-
Explanation
The title names the main change: making X509Certificate and KeyObject class members non-enumerable. It also names the second part, keeping stream state off class prototypes. The changeset matches both parts. The title is long (110 characters, 13 words), but it is specific and on topic.
Full details: Description check
-
Explanation
The description follows the template. It has a 'What does this PR do?' section, covered by the Problem, Fix, and Background sections. It also has a 'How did you verify your code works?' section, covered by the Fix verification bullets and the Tests section in Notes. The description is very long, and most of the detail sits in a collapsed Notes block. The template headings are not used verbatim, but the required information is present and specific.
Full details: Linked Issues check
-
Explanation
Direct issue
#29533requires Bluebird'spromisifyAll(require("crypto"))path to run without the prototype getter error. The four crypto property tables now mark all 32 class members asDontEnum. The regression test runs Bluebird andrandomBytesAsync(8)in a child Bun process and checks successful output. TheLazyTransformreceiver guard prevents the same prototype walk from creating shared stream state. The added crypto tests cover enumeration, descriptor behavior, getter errors, and independent stream state.
Full details: Out of Scope Changes check
-
Explanation
The implementation changes stay connected to
#29533. The property-table updates stop the failing crypto prototype walk. TheLazyTransformchanges prevent side effects from that walk on the four crypto stream classes. The$Setdeclaration, Bluebird dependency, and added crypto tests support this behavior. No unrelated implementation change is established.
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands.
The walk reads `_readableState` on Hash.prototype, Hmac.prototype, Cipheriv.prototype and Decipheriv.prototype. That getter runs the Transform constructor on its receiver, as in Node, so the prototype gets its own stream state and every later instance in the process shares it. Do the walk in a child so that no later test inherits that state.
There was a problem hiding this comment.
The child-process move in 7a56491 takes care of the shared-prototype-state concern I raised on the earlier push, and I found no new bugs in this version. Because the enumerability flip also changes what bun:test matchers (toMatchObject, toBeEmpty, objectContaining) observe over certificates and keys, as the description's Downsides section lays out, a maintainer's call on that trade-off is still worthwhile before merging.
What was reviewed: the 32 DontEnum additions against Node's class-body getters/methods in lib/internal/crypto/x509.js and keys.js — all 32 match. The structured-clone and Worker paths: SerializedScriptValue.cpp readX509Certificate builds from the same lazily-created class structure, so the Worker test exercises the table rather than a separate path. The subprocess test's failure wiring: empty stdout, non-empty stderr, a nonzero exit, or KeyObject/X509Certificate missing from the walk each fail the single toEqual.
Extended reasoning...
The diff adds PropertyAttribute::DontEnum to 28 rows in src/jsc/bindings/JSX509CertificatePrototype.cpp and 4 getter rows across JSKeyObjectPrototype.cpp, JSSecretKeyObjectPrototype.cpp and JSAsymmetricKeyObjectPrototype.cpp, plus descriptor, for..in, Object.entries, Worker and Bun.inspect tests in test/js/node/crypto/. No cryptographic logic, key material handling, or validation changes — only property enumerability bits — so it touches no injection, auth, or data-exposure surface. The second commit addressed my prior inline finding by moving the prototype walk into a bun -e child, and the commit message correctly notes that lazy_transform's _readableState getter runs the Transform constructor on its receiver in Node too. No CODEOWNERS entry covers these files and no human CHANGES_REQUESTED review is on the timeline. Defer rather than approve because the files sit under the node:crypto bindings and the change shifts observable bun:test matcher results over certificates and keys, which is a product judgment for a maintainer.
Still open from earlier reviews (1):
- Unresolved: 1 minor or pre-existing.
random-number-csprng calls bluebird's promisifyAll(require("crypto"))
when it loads, then crypto.randomBytesAsync(). The test does the same
with bluebird 3.7.2 in a child process. It throws on main, at
KeyObject.prototype.type, and passes with the 32 DontEnum rows.
bluebird becomes a direct test dependency. It was in test/bun.lock
already, through unzipper.
Hash, Hmac, Cipheriv and Decipheriv extend LazyTransform. Its getters _readableState and _writableState run the Transform constructor on their receiver, as in Node. With a class prototype as the receiver, the prototype owns the stream state and each later stream of the class shares it. bluebird's promisifyAll reads each enumerable key of each class prototype in bun, because bun drops the "use strict" of bluebird's ES5 test (#14251). Before the 32 DontEnum rows, that walk threw at KeyObject.prototype.type and did not reach these getters. With the rows it completes. Then the second hash stream does not end, and the data listener of one cipher stream receives the output of another. The getter now returns undefined and stores nothing when its receiver is LazyTransform.prototype or the prototype of one of the four classes. Node's getter builds the Transform there. An instance, Object.create(crypto.Hash.prototype) and an instance of a subclass build their own state as before. The set of prototypes is a private-name Set, so that user code that replaces the global Set before the first require("node:crypto") does not change it.
There was a problem hiding this comment.
I re-reviewed the latest push and found no bugs; the LazyTransform change in f2462c2 addresses the shared-stream-state problem raised earlier, and the sweep now runs in child processes. A maintainer look is still worthwhile because the getter now deliberately diverges from Node for five receivers (the PR itself asks a maintainer to pick this or an alternative), and src/js/builtins.d.ts is CODEOWNER-covered.
What was reviewed:
- The 32 DontEnum rows against the Node v26.12.1 class-body definitions, and the descriptor/for..in/Object.entries/Worker-clone tests that pin them.
- The
classPrototypesidentity check inlazy_transform.ts:$Set/.$add/.$hasare link-time private names (@ Setappears in the bytecode-portability intrinsic list), the only consumer of the changed default export isnode/crypto.ts, and the global-Set-replacement child test covers tamper resistance. - The new subprocess tests drain stdout/stderr concurrently and use
await using; theit.failing("bluebird takes its ES5 path")test will flip once #14251/#46730 lands and needs un-marking then.
Extended reasoning...
The diff adds PropertyAttribute::DontEnum to 28 X509Certificate.prototype rows and 4 KeyObject-family accessors in the C++ binding tables, changes the LazyTransform _readableState/_writableState getters in src/js/internal/streams/lazy_transform.ts to return undefined when the receiver is one of five registered class prototypes, updates src/js/node/crypto.ts to use a new toLazyTransformClass helper, declares $Set in src/js/builtins.d.ts, and adds bluebird 3.7.2 plus regression/descriptor tests. It touches node:crypto class surfaces but no key material, validation, or TLS logic; the attribute changes match Node's class-body getters. Deciding against approve: the getter is an intentional divergence from Node's lazy_transform.js that the author explicitly leaves to a maintainer, the .d.ts change is owned by a CODEOWNER, and two earlier inline threads were author-self-resolved rather than independently closed.
|
Closing as stale: this PR conflicts with main, and its last commit is from 2026-10-24. The branch stays, so the work is not lost. To pick it up again, rebase the branch on main and reopen this PR. |
Fixes #29533
Problem
promisifyAll(require("crypto"))throwsTypeError: Can only call X509Certificate.ca on instances of X509Certificate(fix(crypto): fix X509Certificate subclassing and .prototype property #27455). Since 1.4.0 it throwsValue of "this" must be of type KeyObject(node:crypto: sync the crypto suite to Node v26.3.0 and fix surfaced gaps #32623).PropertyAttribute::DontEnum(JSX509CertificatePrototype.cpp:61,JSKeyObjectPrototype.cpp:23,JSSecretKeyObjectPrototype.cpp:25,JSAsymmetricKeyObjectPrototype.cpp:20). In Node these are class members.Hash.prototype._readableStatebuilds the stream on the prototype (lazy_transform.ts:16, since 1.2.5), and later hash streams share it. The throw stops bluebird before that read.Fix
DontEnumto the 32 rows.undefinedforLazyTransform.prototypeand the four class prototypes. Other receivers are unchanged.test/regression/issue/29533.test.ts, andx509.test.ts,crypto.key-objects.test.ts,node-crypto.test.jsintest/js/node/crypto/. 13 tests fail on main.Background
"use strict"in CommonJS (Strict mode does not work at function-level granularity #14251). js_parser: keep directives as statements and carry the file's prologue on the AST #46730 fixes that. Either merge order works (Notes).LazyTransform(a port of Node's) makes a hash or cipher a stream at the first read of_readableState.Downsides
stream.Transform.prototypedoes: 13 of 24 accessors change. A maintainer must pick this or an alternative.for..inover a certificate or key lists no members, like Node. bun:testexpect(certA).not.toMatchObject(certB)andexpect(key).not.toBeEmpty()now fail.require("node:crypto")+91,408 instructions (+0.29%), first stream use of a hash +31 to +44,Bun.inspect(cert)+581.Notes
Repro
0 []false false false[]28 [ "symmetricKeySize", "type" ]true true trueERR_INVALID_THIS Value of "this" must be of type KeyObject0 []false false false[]The Node runs used v26.3.0. The repo pins 26.12.1. In the v26.12.1 source all 32 are still class-body members (
lib/internal/crypto/x509.js:166-379,lib/internal/crypto/keys.js:184,:290,:309,:313).History
DontEnumsince each class shipped: Implement X509Certificate in node:crypto #16173 (1.1.45) forX509Certificate, Passtest-crypto-keygen-*tests #19040 (1.2.11) for theKeyObjectfamily.prototypeproperty of theX509Certificateconstructor wasundefined. fix(crypto): fix X509Certificate subclassing and .prototype property #27455 (1.3.11) installed it. Since then a walk over the class reaches its getters, and each one throws for the prototype.KeyObjectgetters throwERR_INVALID_THISfor a wrong receiver, as in Node. Before that they returnedundefined. Since 1.4.0 the walk stops onKeyObject.prototype.typefirst, so the X509 rows alone no longer clear the repro.random-number-csprng1.0.2, bluebird 3.7.2) on release builds: 1.3.10 prints a number. 1.3.11 and 1.3.14 throw the X509 error. 1.4.0, 1.4.4 and main throw the KeyObject error. This branch prints a number.bluebird
(function () { "use strict"; return this === undefined; })(). bun drops that directive in CommonJS (Strict mode does not work at function-level granularity #14251), so the test returns false. 1.3.10 drops it too, so the directive is the reason for the walk and not the regression.for..inand reads each one. On its ES5 path it usesObject.getOwnPropertyNamesand skips accessors.for..inwalk with a read over the prototype of each class thatnode:cryptoexports: 20 members throw on main, 0 with this PR, 0 on node.*Asyncmethods toX509Certificate.prototype(node: 9) orKeyObject.prototype(node: 1).cryptois the one module that this PR clears.promisifyAll(require(m))fails for 18 of the 76 names inbuiltinModuleson main and for 17 with this PR (node: 0 of 66). Of the 17:"use strict"atjs/release/es5.js:2deleted):buffer,http,perf_hooks,stream/web,string_decoder,sys,url,util,worker_threads.bun,bun:test,undici,ws.netstops onBlockList.prototype.rulesandmoduleonSourceMap.prototype.lineLengths, which Node keeps non-enumerable.child_processstops onChildProcess.prototype.stdin, which Node's prototype does not have (node:child_process:ChildProcessstdin, stdout, stderr, stdio and connected are getter-only and throw on an unspawned instance #44834, child_process: add setters for ChildProcess stdio and connected, return undefined before spawn #44933).vmnever returns (node:vm: Script results are own properties of the instance, as in Node #41776).bun patch bluebird. Setvar isES5 = true;injs/release/es5.js. Runbun patch --commit node_modules/bluebird. With that patch, 0 of the 76 names fail.The lazy stream getter
Hash,Hmac,CipherivandDecipherivextendLazyTransform(src/js/internal/streams/lazy_transform.ts, a port of Node'slib/internal/streams/lazy_transform.js). Its enumerable getters_readableStateand_writableStaterun theTransformconstructor on the receiver. With a class prototype as the receiver, the prototype owns_readableState,_writableStateand_events, and each later instance shares them.This defect is older than the regression, and no issue reports it.
HashandHmacextendLazyTransformsince 1.2.5 (#17920). The throw hides it only for a walk that meetsKeyObjectorX509Certificatefirst. On main today,require("bluebird").promisifyAll({ Cipheriv: crypto.Cipheriv })and then two cipher streams gives eachdatalistener both outputs (node: one each).After bluebird's
promisifyAll(require("crypto")):datachunks for each of two cipher streamsfor..inwalk with a readKeyObject.prototype.typefirst)ERR_STREAM_WRITE_AFTER_ENDdatalistener of one decipher stream receives the plaintext of the other one. So the rows do not ship without a second change.undefinedand stores nothing forLazyTransform.prototypeand for the prototype of each class made withtoLazyTransformClass(). The check is an identity test against those five objects, held in a private-nameSet. An instance,Object.create(crypto.Hash.prototype), a subclass instance andnew LazyTransform()build their own state as before.update(),final(),digest()and streams on instances do not change. Of 17 receiver cases, the 9 with a class prototype differ from Node and the 8 others are equal.The difference from Node, on these five receivers only:
stream.Transform.prototypedoes. A read of one of the 24 inherited accessors by name builds no stream there. Node builds one, and after it the streams of that class share state._readableState,_writableState,readableBuffer,writableBuffer,writableHighWaterMarkandwritableLengthareundefined.readableandwritablearefalse.readableLength,readableHighWaterMark,readableFlowing,readableDidReadandreadableAbortedthrow aTypeError.crypto.Hash.prototype,instanceof stream.Writable,stream.isReadable()andstream.isWritable()go fromtruetofalse, andstream.isDisturbed()throws.node:cryptoas the receiver, the reads that change a prototype go from 108 to 0 (node: 108). The reads that throw go from 44 to 64 (node: 44).for..indoes not reach the two getters.Where the check works, and where it does not:
node:cryptoruns. A--format=cjsbundle that main built has no"use strict"in bluebird's test, so it keeps the walk even when Strict mode does not work at function-level granularity #14251 is done. That bundle throws at load on main, ends withwrite after endwith the 32 rows alone, and prints Node's output with this PR.bun build --target=node --format=cjsbundle of the same program, run on Node, gives both cipher outputs to each listener. This PR does not change that. Only a bundle that keeps the directive does (Strict mode does not work at function-level granularity #14251).class My extends crypto.Cipherivwith an enumerable method). bluebird's walk over it builds the stream there, on main and with this PR. A direct read does the same on Node.crypto.Hmac.prototype.on("x", f)leaves an own_eventson the prototype. Node changes the prototype for this call too.The decision for a maintainer
promisifyAll(require("crypto")), then streamsfor..inover a hash that is not a stream yetSet, a helper, one checkDiffieHellman, fix(crypto): removeverifyErrorfromDiffieHellman.prototype#18710 changednode:crypto.LazyTransform.prototypetest goes away with that file.#46730
it.failing("bluebird takes its ES5 path")innode-crypto.test.jspasses today because bluebird's test is false. The PR that merges second makes it a plain test. That is the moment to decide again whether the getter keeps its check.29533.test.tspasses without this PR. The other 12 tests still fail without it.Measurements
The counter is
instructions:uthroughperf_event_open, with ASLR off and interleaved runs.The 32 rows. No release build was made for these numbers: A is the release build of 367d939 with the same 32 attribute bytes set, B is that build unchanged, and the JIT is off.
size -Aoutput and differ in 32 bytes (28, 1, 1, 2), all in the.rodatatable rows. A and B differ in the same 32 bytes.new X509Certificate: -0.002, -0.004, -5.6 instructions per call (noise floor 0.013, 0.07, 179).stepicount in the reify call).Bun.inspect(cert): +581 instructions per print (+0.26%, noise floor 90), 0 more heap cells, output byte-identical.Bun.inspect(secretKey): +46 (noise floor 77).for (k in cert): -13,133 instructions per loop. The first walk creates 0 objects, down from 29 (one enumerator and 28 name strings).enumerable. All 32 now equal node in that flag.The getter. Two release builds of this branch: with the 32 rows only, and the full PR.
require("node:crypto"): +91,408 instructions at load (+0.29% of the process, 12 runs, spread 177,721 and 128,185). Interpreted, GC off: +95,865 (spread 21,101 and 18,147).createHash, one read of_readableState,update,digest.createHash().update().digest(), GC off: -4.0 instructions per call with the JIT (baseline 3,209, spread 1.8), -3.9 interpreted (baseline 7,071, spread 0.4). The code on this path is the same in both builds. The getter is entered 0 times in 9,000 uses ofupdate,digestandfinal, and once for each stream.require("node:crypto"), one of them theSetof five prototypes.lazy_transform+306,crypto+14),.text+0, 0 new host functions.bun:test matchers
This PR does not change the matchers. They read inherited enumerable keys, so their results over certificates and keys move with the flag.
.notform goes the other way: 8 of 8 negated assertions pass on main and fail here.toMatchObject,expect.objectContainingandBun.deepMatch(9 of the 16): the new results equal jest 30.5.2 and vitest 4.1.9 on Node for fresh objects. bun:test: compare only the expected value's own properties in toMatchObject and Bun.deepMatch #46171 (for toMatchObject compares inherited properties, so a null-prototype array fails (Bun.deepMatch too) #45950) changes these matchers to own properties.toEqual,toStrictEqualandBun.deepEqualswhen one operand has an own accessor or is a Proxy (4 of the 16).toEqualof two plain certificates passes before and after.toBeEmpty(3 of the 16):expect(cert).toBeEmpty()now passes. jest-extended on Node says a certificate or key is not empty, as main does. bun:test: stop toBeEmpty() from passing for undefined, null, numbers, functions and Dates #42541 is an open rework oftoBeEmpty.Tests
x509.test.ts, 3 incrypto.key-objects.test.ts, 4 innode-crypto.test.js, 1 intest/regression/issue/29533.test.ts. 2 more new tests pass on main too: they pin thatBun.inspectof a certificate and of a key still prints every member.29533.test.tsruns bluebird 3.7.2promisifyAll(require("crypto"))in a child, thenrandomBytesAsync. The child prints the same on node v26.3.0. bluebird is a direct test dependency now. It was intest/bun.lockalready, throughunzipper.node-crypto.test.jseach run a child. The first three then make two hash streams and two cipher streams.for..inwalk with a read over each class prototype.LazyTransform.prototype.node:cryptoafter user code replaced the globalSet.29533.test.tspasses.LazyTransform.prototypenot registered, 1 of the 4 fails. With the four class prototypes not registered, 3 fail. With the globalSetin place of the private one, theSettest fails.x509.test.ts:144assertedenumerable: true. crypto: fix property attributes of X509Certificate validFromDate/validToDate #37057 added it to pin the accessor kind ofvalidFromDate. The value it recorded was bun's, and Node's value isfalse.node:assertpass on node (7 of 7).x509-subclass.test.ts,crypto-lazyhash.test.ts,crypto.test.ts,crypto-oneshot.test.ts,crypto.hmac.test.ts, and 12 vendored Node tests (test-crypto-x509.js,test-crypto-key-objects.js,test-crypto-stream.js,test-crypto-hash-stream-pipe.js,test-crypto-lazy-transform-writable.js,test-crypto-cipheriv-decipheriv.jsand 6 more).Not changed here
This PR changes every native property-table row of a
node:cryptoclass whoseenumerableflag differs from Node. Those rows are what the repro of #29533 needs. Other classes have the same gap since they shipped. No report names them, and no issue tracks them as a group. The self-review asked for that issue or for the same change in those classes. Neither is done here.util.MIMEType,util.MIMEParamsJSMIMEType.cpp:492,JSMIMEParams.cpp:602enumerablediffers.Object.entries(util.MIMEType.prototype)throws. #34622 closed without a merge.perf_hookshistogramJSNodePerformanceHooksHistogramPrototype.cpp:21enumerablediffers.BroadcastChannelref,unrefandPerformance.markResourceTimingJSBroadcastChannel.cpp:157,JSPerformance.cpp:210enumerablediffers.fs.DirentNodeDirent.cpp:41enumerablediffers. #45425 edits the same file.net.BlockList,module.SourceMapBlockList.bind.ts,sourcemap.bind.tsconfigurable.SocketAddress.bind.ts:6shows the class option.Timeout,ImmediateTimer.bind.tsvm.ScriptNodeVMScript.cpp:593writable(#41392). A read of an accessor on the prototype never returns (#41776).ChildProcess.prototypestdio getterschild_process.ts:1675crypto.Certificateownprototypepropertycrypto.ts:97Two more accessors store lazily built state on any receiver, a class prototype included:
http.ServerResponse.prototype.socket(_http_server.ts:3274) andtls.TLSSocket.prototype.ssl(tls.ts:749). Node's prototypes do not have them. Neither is enumerable, so a key walk does not reach them. No issue tracks them.Other differences on the four prototypes that this PR touches stay as they are:
structuredCloneandpostMessageof one of these prototype objects throwDataCloneError. Node returns{}.checkIP.lengthis 1 (Node: 2).X509Certificate.prototypehas an ownSymbol.toStringTag, andutil.inspect(cert)printsX509Certificate {}. Node has no tag and prints the members.KeyObject(Node:PublicKeyObject, node:crypto: name KeyObject subclasses PublicKeyObject and PrivateKeyObject #37019).The 28
X509Certificaterows come from #31807. That PR also carries a parser change and does not apply to main. It is still open.