Commit Graph
13385 Commits
Author SHA1 Message Date
Livia Medeiros 2b365b2892 lib: legitimize SuppressedError as primordial
Signed-off-by: LiviaMedeiros <livia@cirno.name>
PR-URL: https://github.com/nodejs/node/pull/67551
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
2026-11-21 20:07:09 +00:00
Matteo Collina 08eff138e3 stream: stop reusing a detached onread buffer
CustomBufferJSListener keeps only the raw address (uv_buf_t) of the
user-supplied onread buffer, without retaining the backing store. If
application code transfers (and thereby detaches) that buffer during the
onread callback, for example by enqueuing a view into a byte
ReadableStream, the backing store is moved away from under the listener
and the raw address is left dangling. Reading subsequent peer data into
that address then corrupts memory the application owns, and if the
backing store is later released, it becomes a use-after-free.

Retain the backing store in CustomBufferJSListener so the raw address
never dangles, and stop reading when the onread callback detaches the
buffer so the stale address is not handed back to libuv.

Signed-off-by: Matteo Collina <hello@matteocollina.com>
PR-URL: https://github.com/nodejs/node/pull/67542
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
2026-11-21 16:33:22 +00:00
jakecastelliandMikhail Leliakin 6d426a0494 http2: add missing setHeaders
Make it possible to invoke response.setHeaders() on the
Http2ServerResponse object, matching the http.OutgoingMessage API.

Fixes: https://github.com/nodejs/node/issues/51573
Refs: https://github.com/nodejs/node/pull/51576
Signed-off-by: jakecastelli <38635403+jakecastelli@users.noreply.github.com>
Signed-off-by: Mikhail Leliakin <leliakin@canva.com>
Co-authored-by: Mikhail Leliakin <leliakin@canva.com>
Assisted-by: Cursor
PR-URL: https://github.com/nodejs/node/pull/67597
Reviewed-By: Jason Zhang <xzha4350@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2026-11-21 15:21:55 +00:00
LiviaMedeiros 915cf105fa diagnostics_channel: use DisposableStack primordial
Signed-off-by: LiviaMedeiros <livia@cirno.name>
PR-URL: https://github.com/nodejs/node/pull/67533
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2026-11-21 22:53:07 +08:00
LiviaMedeiros 9297acd21b Revert "diagnostics_channel: replace using with try-finally"
This reverts commit b1251217f2.

Signed-off-by: LiviaMedeiros <livia@cirno.name>
PR-URL: https://github.com/nodejs/node/pull/67533
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2026-11-21 22:52:58 +08:00
LiviaMedeiros 76e5ca6fe0 lib: add ERM classes to primordials
Totes three classes:
- `DisposableStack`
- `AsyncDisposableStack`
- `SuppressedError`

Signed-off-by: LiviaMedeiros <livia@cirno.name>
PR-URL: https://github.com/nodejs/node/pull/67533
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2026-11-21 22:52:51 +08:00
Matteo Collina ce44266018 esm: avoid dictionary-mode objects in import()
Import attributes were created in C++ with v8::Object::New() and a
null prototype, once per module request and once per import() call.
Every import() call also created a `{ __proto__: null }`
diagnostics_channel context, which was discarded when module.import
had no subscribers. V8 creates all of these in dictionary mode.

Build the attributes from an ordinary object with its prototype set to
null, and only create the trace context when there are subscribers.

Signed-off-by: Matteo Collina <hello@matteocollina.com>
PR-URL: https://github.com/nodejs/node/pull/67554
Refs: https://github.com/nodejs/node/pull/67552
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2026-11-21 06:38:30 +00:00
Max Fisher a6dcfec130 repl: redraw highlighted input once per chunk
Signed-off-by: Max H Fisher <mfisher187@bloomberg.net>
PR-URL: https://github.com/nodejs/node/pull/67422
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
2026-11-21 04:17:55 +00:00
Rafael Gonzaga 3fda34e186 fs: do not disable fd-based APIs in permission audit mode
Refs: https://github.com/nodejs/node/pull/65659
Refs: https://github.com/nodejs/node/issues/65419
Signed-off-by: RafaelGSS <rafael.nunu@hotmail.com>
PR-URL: https://github.com/nodejs/node/pull/66726
Reviewed-By: Ulises Gascón <ulisesgascongonzalez@gmail.com>
2026-11-20 19:25:20 +00:00
James M Snell e8c279d731 lib: avoid using __proto__: null in AbortController/AbortSignal
Using `__proto__: null` on objects will properties immediately
puts them into the slower DictionaryProperties mode. Using a
`__proto__: { __proto: null }, ...` pattern, however, keeps
the objects in FastProperties mode.

Technically this is an observable change since calling
`Object.getPrototoTypeOf(...)` some of these will no longer
return `null`. So a decision needs to be made about whether
these types of changes are `semver-major` or not.

Signed-off-by: James M Snell <jasnell@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/66678
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Ulises Gascón <ulisesgascongonzalez@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
2026-11-20 16:48:04 +00:00
Aviv Keller 030745c54e test_runner: junit fixes
Signed-off-by: avivkeller <me@aviv.sh>
PR-URL: https://github.com/nodejs/node/pull/67160
Fixes: https://github.com/nodejs/node/issues/67155
Fixes: https://github.com/nodejs/node/issues/67149
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2026-11-20 13:56:15 +00:00
Paolo Insogna 50ba1ec6c2 worker: add diagnostic channel 'worker_threads.main.registry'
Signed-off-by: Paolo Insogna <paolo@cowtech.it>
Assisted-By: OpenAI:GPT-6.1 Sol <openai/gpt-6.1-sol>
PR-URL: https://github.com/nodejs/node/pull/67311
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2026-11-20 06:53:49 +00:00
Filip Skokan 360bd63c6c crypto: use settable parameter descriptors
Resolve the exposed digest options against provider descriptors and
construct UTF-8 or octet strings according to their advertised types.
Keep binary values intact for octet strings and reject NUL bytes for
UTF-8 strings.

Share hash initialization and one-shot input/output handling while
retaining the plain digest fast paths and XOF length checks. Probe RSA
implicit rejection without changing its context.

Signed-off-by: Filip Skokan <panva.ip@gmail.com>
Assisted-by: Codex
PR-URL: https://github.com/nodejs/node/pull/67565
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
2026-11-19 23:37:28 +00:00
Marten Richter 3521a6e311 quic: add option waitUntilAvailable to creating streams
We add an option to createBidirectionalStream and
createUnidirectionalStream to fail immediately,
if the flow control's stream budget does not
allow stream creation.
The behavior matches W3C webtransport's behavior.

Fixes #65321

Signed-off-by: Marten Richter <marten.richter@freenet.de>
PR-URL: https://github.com/nodejs/node/pull/65331
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Tim Perry <pimterry@gmail.com>
2026-11-19 19:14:32 +00:00
Tim Perry eda8de765b http2: don't fail response reads after clean RST_STREAM
Signed-off-by: Tim Perry <pimterry@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/67558
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2026-11-19 19:14:15 +00:00
Vlad Frangu 42800b60d3 os: expose guessFileDescriptorType
Exposes the internal `guessHandleType` function as
`guessFileDescriptorType`, which can be used to see if a handle has a
specific type, regardless of the OS it is on.

This helps out with detecting, for example, if standard input is piped
into the process, instead of relying on file system calls.

Refs: https://github.com/nodejs/node/issues/57603
Signed-off-by: Vlad Frangu <me@vladfrangu.dev>
PR-URL: https://github.com/nodejs/node/pull/58060
Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
Reviewed-By: Aviv Keller <me@aviv.sh>
2026-11-19 10:46:13 -07:00
Tim Perry db671bb416 http2: fix eos() for HTTP/2 streams after clean end & close
Previously this could fail - not having read 'end' when the close
arrived was treated as a premature close error for finished() and
related APIs, even though the body data was cleanly ended and complete.
We now check whether there is a clean end buffered. If so, we wait
until it's read before evaluating whether the stream ended cleanly.

Signed-off-by: Tim Perry <pimterry@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/67553
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2026-11-19 17:41:27 +00:00
Matteo Collina f4fab9770b module: avoid dictionary-mode objects on hot paths
V8 keeps objects created from `{ __proto__: null }` literals, and from
v8::Object::New() with names and values, in dictionary mode for their
whole life. The module loader created such objects on every require()
of a builtin and every import(), and kEmptyObject, the cached ESM
resolve results and the requests from getModuleRequests() were all
in dictionary mode as well.

Use classes with a null-prototype prototype for the per-call objects,
null the prototype of plain literals for the long-lived ones, and
build module requests from a DictionaryTemplate.

Signed-off-by: Matteo Collina <hello@matteocollina.com>
PR-URL: https://github.com/nodejs/node/pull/67552
Refs: https://adventures.nodeland.dev/archive/optimizing-objects-with-null-prototypes/
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2026-11-19 17:31:56 +00:00
Gürgün Dayıoğlu 41918c1d44 buffer: use typed arrays for 64-bit BigInt accessors
readBig(U)Int64{LE,BE}() and writeBig(U)Int64{LE,BE}() assembled and
split values with BigInt arithmetic, allocating intermediate BigInts on
every call. Copy the bytes through BigInt64Array and BigUint64Array
views over the existing 8-byte scratch buffer instead, as the double
accessors already do.

Range and bounds checks are unchanged, and the value is masked with
`& -1n` before the store so non-BigInt values still throw the same
TypeError instead of being coerced by the typed array.

benchmark/buffers/buffer-read.js now uses the value it reads. The
loop discarded it, which let V8 remove side-effect-free reads
altogether.

Assisted-by: claude:opus-5.5
Signed-off-by: Gürgün Dayıoğlu <hey@gurgun.day>
PR-URL: https://github.com/nodejs/node/pull/67549
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2026-11-19 17:13:01 +00:00
Ethan Arrowood 86b9e3544c http,http2: copy header arrays in setHeader
setHeader() stored the caller's array and that led to mutation
issues with appendHeader() pushing new values into it. The caller
would see values added to that array, and if the array was frozen
appendHeader() would throw a TypeError.

This fix copies the array value instead so the response instance
owns it completely. getHeader() still return the stored array.

It also applies the same change to HTTP2 compat api.

Fixes: https://github.com/nodejs/node/issues/67526
Assisted-by: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Ethan Arrowood <ethan@arrowood.dev>
PR-URL: https://github.com/nodejs/node/pull/67528
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Tim Perry <pimterry@gmail.com>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
2026-11-19 16:50:31 +00:00
Yuya Inoue f442b5a232 http2: add callback to informational header methods
In the HTTP/1 server, writeContinue(), writeEarlyHints() and
writeInformation() accept a callback that is called once the response
has been written to the socket. The HTTP/2 compat versions did not, so
code moving to the compat API had its callback ignored.

Accept an optional callback in http2stream.additionalHeaders() and in
the three compat methods. The request for the HEADERS frame is tracked
until nghttp2 serializes the frame, and completed together with the
write to the underlying stream that carries it.

Signed-off-by: inoway46 <inoueyuya416@gmail.com>
Assisted-by: claude:opus-5.5
PR-URL: https://github.com/nodejs/node/pull/67470
Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
Reviewed-By: Tim Perry <pimterry@gmail.com>
2026-11-19 16:39:21 +00:00
Jacky Zhao 0c8797b2a6 module: don't map a trailing generated-only segment
The mappings parser detects a segment that has only a generated column
by peeking at the next character. At the end of the mappings string the
peek returns an empty string, which is not a separator, so a final
generated-only segment is decoded with phantom zero deltas and inherits
the source, line, and column of the segment before it. With
--enable-source-maps, stack frames in code after the last mapped
segment are then attributed to the last mapped source.

Check for the end of the string before reading source fields.

Signed-off-by: Jacky Zhao <j.zhao2k19@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/66264
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2026-11-19 15:50:19 +00:00
René c91d8aa1a5 fs: use try...finally for abort race
Signed-off-by: Renegade334 <rene@renegade334.me.uk>
PR-URL: https://github.com/nodejs/node/pull/67545
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2026-11-19 14:57:12 +00:00
Robert Nagy 029acbfbd7 lib: stop refreshing composite AbortSignals
AbortSignal.any() follows its sources as soon as it creates a
composite, so aborting a source synchronously aborts every composite
that follows it. The aborted and reason getters and throwIfAborted()
still walked the composite's sources on every call and dereferenced
the WeakRef of each one, which is expensive because
WeakRef.prototype.deref() adds its target to the kept objects of the
current job.

That walk can no longer find an aborted source of a composite that
isn't aborted itself, so remove it. throwIfAborted() on a composite
with two sources becomes about 17 times faster, the same as on a
plain signal.

Add a benchmark for throwIfAborted() on plain, timeout, composite and
mixed signals.

Assisted-by: claude:opus-5.5
Signed-off-by: Robert Nagy <ronagy@icloud.com>
PR-URL: https://github.com/nodejs/node/pull/67543
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
Reviewed-By: James M Snell <jasnell@gmail.com>
2026-11-19 14:16:59 +00:00
Trivikram Kamat d9e18d51d5 vfs: normalize RealFSProvider mkdir return paths
RealFSProvider.mkdirSync()/mkdir() forwarded the raw fs.mkdirSync()
result, which for { recursive: true } is the absolute backing-directory
path of the first created directory. VirtualFileSystem#toMountedPath()
then joined the mount point with it, producing <mount>/<root>/a instead
of <mount>/a, so the returned path failed fs.existsSync().

Reuse the existing #resolvedToVfsPath() helper (as realpath does) to
translate the result back to a provider-relative VFS path, matching
MemoryProvider.

Signed-off-by: Kamat, Trivikram <16024985+trivikr@users.noreply.github.com>
Assisted-by: opencode
PR-URL: https://github.com/nodejs/node/pull/66221
Fixes: https://github.com/nodejs/node/issues/66220
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2026-11-19 08:20:45 +00:00
Matteo Collina c47b8d8781 url: restrict option copying in urlToHttpOptions to URL instances
Only spread own enumerable properties for URL instances created by this
realm's URL constructor. Duck-typed objects accepted by isURL() can no
longer smuggle connection options (socketPath, method, headers, agent)
into a request.

This fixes a footgun where a hostname-validated http.request() could be
redirected to a Unix socket (e.g. the Docker daemon) via a URL-shaped
object, bypassing hostname-based SSRF checks. Extending a genuine URL
object with extra options is preserved.

Refs: https://github.com/nodejs/node/pull/46989
Signed-off-by: Matteo Collina <hello@matteocollina.com>
PR-URL: https://github.com/nodejs/node/pull/67454
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
2026-11-19 08:20:21 +00:00
Ved Chaudhari cdd06876da fs: restore stack traces of fs/promises stat permission errors
Since stat() started going through raceWithSignal(), permission
errors from fsPromises.stat() have had no stack frames. The binding
rejects them right away, and raceWithSignal() returned that promise
from an async function without awaiting it, so nothing was awaiting
it yet when the stack was captured.

Return the promise as is when there is no signal, so stat() awaits
it directly again.

Refs: https://github.com/nodejs/node/pull/63143
Signed-off-by: vedchaudhari <vedc2853@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/67525
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Christian Aurich Zanettini Martins <christian.aurichzm@gmail.com>
2026-11-19 03:40:55 +00:00
inoway46 371ac095ac tls: destroy sockets after fatal errors
Destroy established TLS sockets on fatal errors so pending writes
cannot prevent HTTP/2 session cleanup from completing. Defer closing
until after error handling to preserve connection details for listeners.

Add regression coverage for standalone TLS socket closure and HTTP/2
cleanup with default and custom TLS connections.

Fixes: https://github.com/nodejs/node/issues/67213
Signed-off-by: inoway46 <inoueyuya416@gmail.com>
Assisted-by: Codex
PR-URL: https://github.com/nodejs/node/pull/67215
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Tim Perry <pimterry@gmail.com>
2026-11-19 02:21:25 +00:00
inoway46 3f61461631 net: clear closed handles before emitting close
Clear a deferred socket handle before invoking close listeners. TLS has
already freed its SSL state at this point, so retaining the handle lets
getProtocol() access a null SSL pointer and crash the process.

Keep connection details available during tlsClientError and add coverage
for querying the protocol after a failed handshake closes the socket.

Signed-off-by: inoway46 <inoueyuya416@gmail.com>
Assisted-by: Codex
PR-URL: https://github.com/nodejs/node/pull/67215
Fixes: https://github.com/nodejs/node/issues/67213
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Tim Perry <pimterry@gmail.com>
2026-11-19 02:21:24 +00:00
Tim Perry b7df44bf9c tls: docs-deprecate TLS renegotiation, add allowRenegotiation opt-in
For now this changes very little, but offers an option to directly
control whether this is supported. In future, this will default to
'false' (disabling by default) and eventually be mostly removed,
except opt-in client support for accepting renegotiation requests
from servers.

Signed-off-by: Tim Perry <pimterry@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/67532
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2026-11-18 22:39:56 +00:00
Ethan Arrowood 0f2c06155d tools: apply http lint rule to lib/internal/http
The `lib/_http_*.js` files moved to `lib/internal/http/` recently.
But the ESLint config still only listed the old paths. The moved
files lost the "Do not use prototype primordials in this file"
check that other HTTP hot paths have.

This change adds `lib/internal/http/*.js` to that rule list. The
files already comply so no other changes are needed.

Assisted-by: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Ethan Arrowood <ethan@arrowood.dev>
PR-URL: https://github.com/nodejs/node/pull/67529
Refs: https://github.com/nodejs/node/pull/58535
Reviewed-By: Efe Karasakal <hi@efe.dev>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Richard Lau <richard.lau@ibm.com>
2026-11-18 20:00:13 +00:00
Lazizbek Ergashev 5a823400b2 lib: end --eval crypto wrapper code with a newline
Assisted-by: Claude Code
Signed-off-by: lazerg <lazerg2@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/67162
Fixes: https://github.com/nodejs/node/issues/67159
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
2026-11-18 17:55:41 +00:00
James M Snell d77ed7854e fs: move DEP0187 to End-of-Life
Passing an invalid argument type to fs.existsSync() now throws
ERR_INVALID_ARG_TYPE instead of returning false. Other invalid paths,
such as strings containing null bytes or non-file: URLs, continue to
return false.

This has been a runtime deprecation since v24.0.0.

Refs: https://github.com/nodejs/node/pull/55753
Refs: https://github.com/nodejs/node/pull/55892
Assisted-by: Claude
Signed-off-by: James M Snell <jasnell@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/67494
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
Reviewed-By: LiviaMedeiros <livia@cirno.name>
Reviewed-By: Richard Lau <richard.lau@ibm.com>
2026-11-18 12:02:29 +00:00
Moshe Atlow 20a93ab52b test_runner: scope rerun ids to the entry file
With process isolation, the `--test-rerun-failures` state file is
written by the parent process, which numbered tests sharing a location
across all test files, while each child process numbers them within
its own file. A test defined in a helper used by several test files
was therefore looked up in a slot belonging to another file, and a
failing test could be replayed as passed without running.

Prefix the identifier of a test defined outside of its entry file with
the entry file when tests run in per-file child processes, and build
the identifier with the same helper on both sides.

Signed-off-by: Moshe Atlow <moshe@atlow.co.il>
PR-URL: https://github.com/nodejs/node/pull/67512
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
2026-11-18 09:39:47 +00:00
Moshe Atlow 19cb394896 test_runner: resolve entryFile against the cwd option
The location of a test file run in a child process was resolved
against `process.cwd()`, so `run()` reported a wrong `entryFile` for
relative paths when called with a different `cwd`.

Signed-off-by: Moshe Atlow <moshe@atlow.co.il>
PR-URL: https://github.com/nodejs/node/pull/67512
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
2026-11-18 09:39:46 +00:00
Gürgün Dayıoğlu 369b9c88ac http: keep request option copies in fast mode
The options of every client request are copied several times: once
in ClientRequest to merge the URL and the options, once more to
build the options handed to the agent, and again in Agent#addRequest
(on every request, including keep-alive reuse) and createSocket to
merge in the agent options. Each copy was a `{ __proto__: null, ...}`
literal or an Object.assign() onto `{ __proto__: null }`. V8 creates
such an object in dictionary mode, and copying from a dictionary-mode
source takes the generic slow path, so every copy in the chain was
slow and fed a slow source into the next one.

Use kEmptyObject, a frozen object with a null prototype and no
properties, as the prototype of each copy instead of null. The copy
still inherits nothing, has the same own properties in the same
order, and stays in fast mode. The same is done for the copy of the
options in the http and https Agent constructors, which is the
source of the agent options merged into every request.

benchmark/http/create-clientrequest.js improves by 2 to 24 % at the
default e=1 (50 runs) and by 49 to 87 % with e=6 (30 runs).

Assisted-by: claude:opus-5.5
Signed-off-by: Gürgün Dayıoğlu <hey@gurgun.day>
PR-URL: https://github.com/nodejs/node/pull/67395
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Tim Perry <pimterry@gmail.com>
Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
2026-11-18 08:51:01 +00:00
Efe Karasakal 3e797cbda2 quic: handle application-specific no-error codes
Signed-off-by: Efe Karasakal <hi@efe.dev>
PR-URL: https://github.com/nodejs/node/pull/67094
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Tim Perry <pimterry@gmail.com>
2026-11-18 07:50:23 +00:00
Matteo Collina 93053532e8 stream: keep async context of the pipeTo pump
The pipeTo() pump re-enters from the destination's ready hook, which
writableStreamUpdateBackpressure invokes synchronously, and from the
chunk steps of its read request. Both run in the async context of the
code that cleared the backpressure or enqueued the chunk, so the
source's pull() and the writes issued after a resumption observed that
context instead of the one of the pipeTo() call, as they did with the
promise-based pump. Capture the async context frame when the pipe starts
and run the pump in it.

Refs: https://github.com/nodejs/node/issues/66906
Refs: https://github.com/nodejs/node/pull/65138
Signed-off-by: Matteo Collina <hello@matteocollina.com>
PR-URL: https://github.com/nodejs/node/pull/67054
Refs: https://github.com/nodejs/node/pull/67052
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
2026-11-18 06:45:33 +00:00
Yohannes Desta 1fb0cd6978 fs: validate opendir() bufferSize before opening the directory
fs.opendir() only checked options.bufferSize in the Dir constructor,
which runs from the completion callback of the native opendir call.
An invalid value was thrown from there, so it could not be caught and
the process exited. fs.promises.opendir() is built on fs.opendir() and
had the same problem.

Check bufferSize before starting the native call, so fs.opendir()
throws to the caller and fs.promises.opendir() rejects.

Fixes: https://github.com/nodejs/node/issues/67182
Signed-off-by: Yohannes Desta <yohannesdestagebru10@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/67183
Reviewed-By: Christian Aurich Zanettini Martins <christian.aurichzm@gmail.com>
2026-11-18 03:59:25 +00:00
Bryan English 7fa06d4717 http2: allow client request header injection via diagnostics_channel
The http2.client.stream.created and http2.client.stream.start channels
publish the stream's sentHeaders object, but by that point the request
headers have already been serialized in ClientHttp2Session#request().
Mutating the published object has no effect on the wire, so tracing
instrumentation has no way to add context headers such as traceparent to
outgoing HTTP/2 client requests.

Add a new http2.client.request.headers channel, published when
ClientHttp2Session#request() is called, before the headers are validated
and serialized. Subscribers receive a shallow copy of the headers object
passed by the caller and can mutate it in place to add or modify request
headers. When request() is called without headers, a fresh object is
published so subscribers can still inject headers. The caller's own
headers object and its sensitiveHeaders list are never modified, so
header objects can be safely reused or forwarded across requests.
Injected headers go through the same validation as headers passed
directly to request().

The existing created and start channels are unchanged.

Assisted-by: pi
Signed-off-by: Bryan English <bryan@bryanenglish.com>
PR-URL: https://github.com/nodejs/node/pull/67069
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
Reviewed-By: Tim Perry <pimterry@gmail.com>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2026-11-17 20:38:06 +00:00
James M Snell 3193305572 stream: deduplicate string chunk encoding in web stream adapters
The Writable and Duplex adapters created from web streams duplicated
the logic that encodes string chunks as a Uint8Array before writing
them to the WritableStream. Move it into a shared encodeStringChunk()
helper.

Assisted-by: Claude
Signed-off-by: James M Snell <jasnell@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/67495
Reviewed-By: Guilherme Araújo <arauujogui@gmail.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
2026-11-17 18:37:05 +00:00
James M Snell 67798df884 util: share helpers between debounce() and throttle()
util.debounce() and util.throttle() duplicated the construction of the
AbortError used for cancel()/abort, and the property definitions for
the returned function's control methods, state getters, length, and
name. Move both into internal/util/wrapped_function.

Assisted-by: Claude
Signed-off-by: James M Snell <jasnell@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/67495
Reviewed-By: Guilherme Araújo <arauujogui@gmail.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
2026-11-17 18:37:00 +00:00
James M Snell 8002dbdc27 http: share insecureHTTPParser/httpValidation option handling
ClientRequest and Server duplicated the validation of the
insecureHTTPParser and httpValidation options, including the check
that they are mutually exclusive. Move it into a shared
setHttpParserOptions() helper in internal/http.

Assisted-by: Claude
Signed-off-by: James M Snell <jasnell@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/67495
Reviewed-By: Guilherme Araújo <arauujogui@gmail.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
2026-11-17 18:36:56 +00:00
James M Snell c807380348 crypto: deduplicate WebCrypto SPKI/PKCS#8 exporter lookup
exportKeySpki() and exportKeyPkcs8() contained identical switch
statements mapping the algorithm name to its export function. Move
the lookup into a shared getAsymmetricKeyExporter() helper.

Assisted-by: Claude
Signed-off-by: James M Snell <jasnell@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/67495
Reviewed-By: Guilherme Araújo <arauujogui@gmail.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
2026-11-17 18:36:52 +00:00
James M Snell fd6ba3f246 crypto: share asymmetric WebCrypto key import logic
The RSA, EC, CFRG, ML-DSA, and ML-KEM importKey implementations each
duplicated the handling of the 'KeyObjectHandle', 'spki', and 'pkcs8'
formats. Move it into a shared importAsymmetricKeyHandle() helper in
webcrypto_util, with an optional hook that ML-DSA and ML-KEM use to
reject PKCS#8 keys without a seed.

Assisted-by: Claude
Signed-off-by: James M Snell <jasnell@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/67495
Reviewed-By: Guilherme Araújo <arauujogui@gmail.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
2026-11-17 18:36:47 +00:00
James M Snell 1727b138f9 esm: move DEP0155 and DEP0166 to End-of-Life
Package "exports" subpaths ending in "/" now throw
ERR_INVALID_MODULE_SPECIFIER instead of emitting DEP0155, matching
the existing "imports" behavior and the documented resolution
algorithm.

"imports" and "exports" targets containing empty segments (double,
leading, or trailing slashes after the initial "./") now throw
ERR_INVALID_PACKAGE_TARGET, and pattern matches containing empty
segments now throw ERR_INVALID_MODULE_SPECIFIER, instead of emitting
DEP0166.

The isPathMap parameter, which only served to suppress DEP0166 for
trailing slash pattern resolutions, is removed.

DEP0155 has been a runtime deprecation since v17.0.0, DEP0166 since
v19.0.0.

Refs: https://github.com/nodejs/node/pull/40117
Refs: https://github.com/nodejs/node/pull/44495
Assisted-by: Claude
Signed-off-by: James M Snell <jasnell@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/67488
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2026-11-17 16:41:10 +00:00
James M Snell 6c835918fb crypto: move DEP0179 and DEP0181 to End-of-Life
Calling the Hash or Hmac constructors directly, with or without new,
now throws ERR_ILLEGAL_CONSTRUCTOR. Instances must be created with
crypto.createHash() and crypto.createHmac().

The classes remain exported from node:crypto so that instanceof checks
continue to work. Internally, instances are constructed through a
private symbol, and the createHash() and createHmac() factories now
live alongside the classes in internal/crypto/hash.

Both have been runtime deprecations since v22.0.0.

Refs: https://github.com/nodejs/node/pull/51880
Refs: https://github.com/nodejs/node/pull/52071
Assisted-by: Claude
Signed-off-by: James M Snell <jasnell@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/67490
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Tim Perry <pimterry@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2026-11-17 16:40:55 +00:00
Jacky Zhao 3db9632585 module: store source map mappings in a typed array
SourceMap kept one six-element array per mapping segment. Bundled
applications have millions of segments, and with --enable-source-maps
a parsed map lives for the life of the process: a 63 MB source map with
2.9 million segments retained about 290 MiB of heap.

Store the segments in a single Int32Array, six fields per segment, and
resolve source URLs and names through per-map tables. Segments are
counted before parsing so storage is allocated once, and sorting is
skipped when the mappings are already in order. The public API and the
objects returned by findEntry() and findOrigin() are unchanged.

Signed-off-by: Jacky Zhao <j.zhao2k19@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/66261
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2026-11-17 14:58:30 +00:00
Gabe De Mesa cdc1dacdd5 http2: enforce maxSessionMemory for client requests
The documentation for `maxSessionMemory` says new streams are rejected
while the limit is exceeded. That was only enforced for streams opened
by the peer (`Http2Session::CanAddStream()`). `session.request()` went
straight to `nghttp2_submit_request()`, so a client whose socket
stopped draining could keep queuing requests in nghttp2 without bound.

Check the session memory before submitting a request. If it is over
the limit, reject only that request with the new
`ERR_HTTP2_SESSION_MEMORY_EXCEEDED` error. Nothing is sent to the peer,
so the request can be retried, and the session stays usable. As with
response headers, request bodies queued for flow control are not
counted, so large uploads do not block unrelated requests on the same
session.

Refs: https://github.com/nodejs/undici/issues/6181
Assisted-by: a closed-source coding agent
Signed-off-by: Gabe De Mesa <gdemesa@opengov.com>
PR-URL: https://github.com/nodejs/node/pull/67361
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2026-11-17 13:26:40 +00:00
Ved Chaudhari d2da05f14b util: fix debounce/throttle abort listener leak
debounce() and throttle() added an abort listener to the signal when
they were created and never removed it, so a long-lived signal kept
every debounced or throttled function, and its data, in memory.

Only listen for abort while calls are pending. Calls made after the
signal is aborted still reject, since each call checks signal.aborted.

Assisted-by: a closed-source coding agent
Signed-off-by: vedchaudhari <vedc2853@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/66839
Refs: https://github.com/nodejs/node/pull/65899
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
2026-11-17 11:47:28 +00:00