Skip to content

node:crypto: make X509Certificate and KeyObject members non-enumerable, keep stream state off class prototypes - #46622

Closed
robobun wants to merge 5 commits into
mainfrom
robobun/1aeb87bd/crypto-class-members-non-enumerable
Closed

robobun wants to merge 5 commits into
mainfrom
robobun/1aeb87bd/crypto-class-members-non-enumerable

Conversation

@robobun

@robobun robobun commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #29533

Problem

  • Since 1.3.11, bluebird's promisifyAll(require("crypto")) throws TypeError: Can only call X509Certificate.ca on instances of X509Certificate (fix(crypto): fix X509Certificate subclassing and .prototype property #27455). Since 1.4.0 it throws Value of "this" must be of type KeyObject (node:crypto: sync the crypto suite to Node v26.3.0 and fix surfaced gaps #32623).
  • Cause: 32 rows in four property tables have no PropertyAttribute::DontEnum (JSX509CertificatePrototype.cpp:61, JSKeyObjectPrototype.cpp:23, JSSecretKeyObjectPrototype.cpp:25, JSAsymmetricKeyObjectPrototype.cpp:20). In Node these are class members.
  • Not reported: a read of Hash.prototype._readableState builds 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

  • Add DontEnum to the 32 rows.
  • The getter returns undefined for LazyTransform.prototype and the four class prototypes. Other receivers are unchanged.
  • Verified: test/regression/issue/29533.test.ts, and x509.test.ts, crypto.key-objects.test.ts, node-crypto.test.js in test/js/node/crypto/. 13 tests fail on main.
  • Self-reviewed: 30 concerns raised, 24 addressed. Notes list the rest.

Background

Downsides

  • The getter differs from Node's for five receivers. They answer as Node's stream.Transform.prototype does: 13 of 24 accessors change. A maintainer must pick this or an alternative.
  • for..in over a certificate or key lists no members, like Node. bun:test expect(certA).not.toMatchObject(certB) and expect(key).not.toBeEmpty() now fail.
  • Cost: require("node:crypto") +91,408 instructions (+0.29%), first stream use of a hash +31 to +44, Bun.inspect(cert) +581.
Notes

Repro

const { X509Certificate, KeyObject, createSecretKey } = require("crypto");
const keysIn = o => { const r = []; for (const k in o) r.push(k); return r; };
console.log(keysIn(X509Certificate.prototype).length, keysIn(createSecretKey(Buffer.alloc(16))));
const e = (p, n) => Object.getOwnPropertyDescriptor(p, n).enumerable;
console.log(e(X509Certificate.prototype, "ca"), e(X509Certificate.prototype, "checkEmail"), e(KeyObject.prototype, "type"));
try { console.log(Object.entries(KeyObject.prototype)); } catch (err) { console.log(err.code, err.message); }
line 1 line 2 line 3
node v26.3.0 0 [] false false false []
main 28 [ "symmetricKeySize", "type" ] true true true ERR_INVALID_THIS Value of "this" must be of type KeyObject
this PR 0 [] 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

bluebird

The lazy stream getter

Hash, Hmac, Cipheriv and Decipheriv extend LazyTransform (src/js/internal/streams/lazy_transform.ts, a port of Node's lib/internal/streams/lazy_transform.js). Its enumerable getters _readableState and _writableState run the Transform constructor on the receiver. With a class prototype as the receiver, the prototype owns _readableState, _writableState and _events, and each later instance shares them.

This defect is older than the regression, and no issue reports it. Hash and Hmac extend LazyTransform since 1.2.5 (#17920). The throw hides it only for a walk that meets KeyObject or X509Certificate first. On main today, require("bluebird").promisifyAll({ Cipheriv: crypto.Cipheriv }) and then two cipher streams gives each data listener both outputs (node: one each).

After bluebird's promisifyAll(require("crypto")):

prototypes that own stream state second hash stream data chunks for each of two cipher streams
node v26.3.0 0 of 4 ends 1
node v26.3.0, plain for..in walk with a read 4 of 4 never ends 2
bun 1.3.10 4 of 4 never ends 2
main 0 of 4 (throws at KeyObject.prototype.type first) ends 1
the 32 rows alone 4 of 4 never ends, or ERR_STREAM_WRITE_AFTER_END 2
this PR 0 of 4 ends 1
  • With the 32 rows alone, the data listener of one decipher stream receives the plaintext of the other one. So the rows do not ship without a second change.
  • The getter now returns undefined and stores nothing for LazyTransform.prototype and for the prototype of each class made with toLazyTransformClass(). The check is an identity test against those five objects, held in a private-name Set. An instance, Object.create(crypto.Hash.prototype), a subclass instance and new 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:

  • The five prototypes answer as Node's own stream.Transform.prototype does. 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.
  • 13 of the 24 give another result. _readableState, _writableState, readableBuffer, writableBuffer, writableHighWaterMark and writableLength are undefined. readable and writable are false. readableLength, readableHighWaterMark, readableFlowing, readableDidRead and readableAborted throw a TypeError.
  • On crypto.Hash.prototype, instanceof stream.Writable, stream.isReadable() and stream.isWritable() go from true to false, and stream.isDisturbed() throws.
  • Of 272 accessor reads with a class prototype of node:crypto as 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).
  • This is more than the bluebird walk needs. The walk needs only that for..in does not reach the two getters.

Where the check works, and where it does not:

  • It works wherever bun's node:crypto runs. A --format=cjs bundle 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 with write after end with the 32 rows alone, and prints Node's output with this PR.
  • It does not reach Node. A bun build --target=node --format=cjs bundle 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).
  • The prototype of a user subclass (class My extends crypto.Cipheriv with 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 _events on the prototype. Node changes the prototype for this call too.

The decision for a maintainer

the 32 rows alone the rows, and the two getters non-enumerable the rows, and the receiver check (this PR)
bluebird promisifyAll(require("crypto")), then streams shared state as Node as Node
bluebird over a user subclass, then streams shared state as Node shared state, as on main
a read by name of an inherited accessor on the five prototypes as Node as Node no stream is built, 13 of 24 results differ
descriptor flags that differ from Node 0 2 0
for..in over a hash that is not a stream yet as Node lists neither getter as Node
new code none two literals a Set, a helper, one check

#46730

Measurements

The counter is instructions:u through perf_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.

  • Binary size: +0 B. The 4 objects compiled before and after with the debug flags have equal size -A output and differ in 32 bytes (28, 1, 1, 2), all in the .rodata table rows. A and B differ in the same 32 bytes.
  • Getter read, method call, new X509Certificate: -0.002, -0.004, -5.6 instructions per call (noise floor 0.013, 0.07, 179).
  • Class setup, once for each global object: 31,682 to 31,586 instructions across the 4 tables (-96, gdb stepi count 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).
  • Descriptors: 32 members change, each only in 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).
  • First stream use of a hash, GC off: +44 and +31 instructions for each instance with the JIT (two samples of 6 runs, baseline 6,689, spread 25 to 45). Interpreted: +209 (baseline 47,272). The workload is 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 of update, digest and final, and once for each stream.
  • Allocations: 0 more cells for 10,000 hash streams. For each realm: +11 cells at require("node:crypto"), one of them the Set of five prototypes.
  • Release binary: +320 bytes of builtin JS text (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.

Tests

  • 13 tests fail on a release build of main: 5 in x509.test.ts, 3 in crypto.key-objects.test.ts, 4 in node-crypto.test.js, 1 in test/regression/issue/29533.test.ts. 2 more new tests pass on main too: they pin that Bun.inspect of a certificate and of a key still prints every member.
  • 29533.test.ts runs bluebird 3.7.2 promisifyAll(require("crypto")) in a child, then randomBytesAsync. The child prints the same on node v26.3.0. bluebird is a direct test dependency now. It was in test/bun.lock already, through unzipper.
  • The 4 tests in node-crypto.test.js each run a child. The first three then make two hash streams and two cipher streams.
    • A for..in walk with a read over each class prototype.
    • A direct read of the two getters on the four class prototypes.
    • The same read on LazyTransform.prototype.
    • A load of node:crypto after user code replaced the global Set.
  • With the 32 rows and no getter change, those 4 tests fail and 29533.test.ts passes.
  • With LazyTransform.prototype not registered, 1 of the 4 fails. With the four class prototypes not registered, 3 fail. With the global Set in place of the private one, the Set test fails.
  • x509.test.ts:144 asserted enumerable: true. crypto: fix property attributes of X509Certificate validFromDate/validToDate #37057 added it to pin the accessor kind of validFromDate. The value it recorded was bun's, and Node's value is false.
  • Each of the 32 rows is named in a descriptor assertion.
  • The descriptor and walk assertions written with node:assert pass on node (7 of 7).
  • Also run with this build: 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.js and 6 more).

Not changed here

This PR changes every native property-table row of a node:crypto class whose enumerable flag 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.

Class Where Members State
util.MIMEType, util.MIMEParams JSMIMEType.cpp:492, JSMIMEParams.cpp:602 6, 9 Only enumerable differs. Object.entries(util.MIMEType.prototype) throws. #34622 closed without a merge.
perf_hooks histogram JSNodePerformanceHooksHistogramPrototype.cpp:21 18 Only enumerable differs.
BroadcastChannel ref, unref and Performance.markResourceTiming JSBroadcastChannel.cpp:157, JSPerformance.cpp:210 2, 1 Only enumerable differs.
fs.Dirent NodeDirent.cpp:41 7 Only enumerable differs. #45425 edits the same file.
net.BlockList, module.SourceMap BlockList.bind.ts, sourcemap.bind.ts 5, 4 Generated classes. They also differ in configurable. SocketAddress.bind.ts:6 shows the class option.
Timeout, Immediate Timer.bind.ts 4, 3 Node has enumerable and non-enumerable members here. The generator has the option for a whole class only.
vm.Script NodeVMScript.cpp:593 8 The methods also differ in writable (#41392). A read of an accessor on the prototype never returns (#41776).
ChildProcess.prototype stdio getters child_process.ts:1675 4 Node's prototype does not have them (#44834, #44933).
crypto.Certificate own prototype property crypto.ts:97 1 Enumerable and configurable (#32160, #46197).

Two more accessors store lazily built state on any receiver, a class prototype included: http.ServerResponse.prototype.socket (_http_server.ts:3274) and tls.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:

  • structuredClone and postMessage of one of these prototype objects throw DataCloneError. Node returns {}.
  • checkIP.length is 1 (Node: 2).
  • X509Certificate.prototype has an own Symbol.toStringTag, and util.inspect(cert) prints X509Certificate {}. Node has no tag and prints the members.
  • The constructor of a public key is named KeyObject (Node: PublicKeyObject, node:crypto: name KeyObject subclasses PublicKeyObject and PrivateKeyObject #37019).

The 28 X509Certificate rows come from #31807. That PR also carries a parser change and does not apply to main. It is still open.

…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.
@robobun

robobun commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator Author

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 false

The repro of #29533 (random-number-csprng 1.0.2 with bluebird 3.7.2) throws TypeError: Value of "this" must be of type KeyObject on main. It prints a number on 1.3.10, on node, and with this PR.

After bluebird's promisifyAll(require("crypto")), two hash streams and two cipher streams give the same output as node with this PR. With the 32 DontEnum rows alone, the second hash stream does not end and each cipher listener receives both outputs. The getter change in src/js/internal/streams/lazy_transform.ts is in this PR for that reason.

@robobun

robobun commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator Author
Updated 1:26 PM PT - Oct 24th, 2026

✅ @robobun, your commit 65a150de49c4e3ed7edd370c2ac1279492a22a92 passed in Build #132149! 🎉


🧪   To try this PR locally:

bunx bun-pr 46622

That installs a local version of the PR into your bun-46622 executable, so you can run:

bun-46622 --bun

@coderabbitai

coderabbitai Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 5bf10ff and 65a150d.

Files ignored due to path filters: 1
  • test/bun.lock is excluded by !**/*.lock
Files selected for processing: 6
  • src/js/builtins.d.ts
  • src/js/internal/streams/lazy_transform.ts
  • src/js/node/crypto.ts
  • test/js/node/crypto/node-crypto.test.js
  • test/package.json
  • test/regression/issue/29533.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.

Walkthrough

Crypto prototype methods and accessors are now non-enumerable. Lazy stream getters return undefined on registered prototypes without initializing stream state. Tests cover enumeration, inspection, prototype traversal, and Bluebird promisification.

Changes

Crypto prototype behavior

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: Normal

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: Passed 4
Check name Status Explanation
Title check Passed 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…
Description check Passed 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, cover…
Linked Issues check Passed Direct issue #29533 requires Bluebird's promisifyAll(require("crypto")) path to run without the prototype getter error. The four crypto property tables now mark all 32 class members as DontEnum. T…
Out of Scope Changes check Passed The implementation changes stay connected to #29533. The property-table updates stop the failing crypto prototype walk. The LazyTransform changes prevent side effects from that walk on the four cryp…
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 #29533 requires Bluebird's promisifyAll(require("crypto")) path to run without the prototype getter error. The four crypto property tables now mark all 32 class members as DontEnum. The regression test runs Bluebird and randomBytesAsync(8) in a child Bun process and checks successful output. The LazyTransform receiver 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. The LazyTransform changes prevent side effects from that walk on the four crypto stream classes. The $Set declaration, 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Findings marked 🟡 are optional suggestions and need no follow-up push.

Comment thread test/js/node/crypto/node-crypto.test.js Resolved
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.
@robobun
robobun marked this pull request as draft October 23, 2026 21:17

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.
@robobun robobun changed the title node:crypto: make X509Certificate and KeyObject class members non-enumerable node:crypto: make X509Certificate and KeyObject members non-enumerable, keep stream state off class prototypes Oct 24, 2026
@robobun
robobun marked this pull request as ready for review October 24, 2026 21:11
@robobun
robobun requested a review from alii as a code owner October 24, 2026 21:11
@robobun
robobun requested a review from dylan-conway October 24, 2026 21:12

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 classPrototypes identity check in lazy_transform.ts: $Set/.$add/.$has are link-time private names (@ Set appears in the bytecode-portability intrinsic list), the only consumer of the changed default export is node/crypto.ts, and the global-Set-replacement child test covers tamper resistance.
  • The new subprocess tests drain stdout/stderr concurrently and use await using; the it.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.

@robobun

robobun commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator Author

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.

@robobun robobun closed this Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regression in Bun 1.3.11, 1.3.12, 1.3.13, 1.3.14, 1.4.0, 1.4.1, 1.4.2, 1.4.3, 1.4.4 when running uncompiled code

1 participant