Commit graph

9061 commits

Author SHA1 Message Date
uzlopak
c74c514273 errors: fix stacktrace of SystemError
PR-URL: https://github.com/nodejs/node/pull/49956
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2023-12-23 09:04:45 -08:00
theanarkh
e266bb1722
src: fix unix abstract socket path for trace event
PR-URL: https://github.com/nodejs/node/pull/50858
Reviewed-By: James M Snell <jasnell@gmail.com>
2023-12-23 16:35:27 +00:00
Antoine du Hamel
825163c5ab
lib: fix use of --frozen-intrinsics with --jitless
PR-URL: https://github.com/nodejs/node/pull/51248
Fixes: https://github.com/nodejs/node/issues/51232
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2023-12-23 12:38:24 +00:00
Marco Ippolito
6329d2cd27
timers: export timers.promises
PR-URL: https://github.com/nodejs/node/pull/51246
Fixes: https://github.com/nodejs/node/issues/51237
Reviewed-By: Raz Luvaton <rluvaton@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
2023-12-23 10:23:43 +00:00
marco-ippolito
b9df88a8c2 doc: runtime deprecate flag --trace-atomics-wait
PR-URL: https://github.com/nodejs/node/pull/51179
Refs: https://github.com/nodejs/node/issues/42982
Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2023-12-22 07:26:08 -08:00
Pulkit Gupta
48cdb880bc
fs: make offset, position & length args in fh.read() optional
PR-URL: https://github.com/nodejs/node/pull/51087
Fixes: https://github.com/nodejs/node/issues/47183
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2023-12-22 12:41:22 +00:00
Chiara Ricciardi
ba957a61f8
test: replace forEach with for-of in test-webcrypto-export-import-ec
PR-URL: https://github.com/nodejs/node/pull/51249
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2023-12-22 06:18:31 +00:00
Luca Del Puppo
c9fe4b67dd
test: move to for of loop in test-http-hostname-typechecking.js
PR-URL: https://github.com/nodejs/node/pull/50782
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
2023-12-22 06:06:01 +00:00
Ianna83
aa7de747b7 test: replace forEach with for of in file test-trace-events-net.js
PR-URL: https://github.com/nodejs/node/pull/50789
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2023-12-21 17:21:35 -08:00
Edoardo Dusi
a03d9bd39d test: replace forEach() with for...of in test/parallel/test-util-log.js
PR-URL: https://github.com/nodejs/node/pull/50783
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2023-12-21 17:20:41 -08:00
Andrea Pavone
ea41c63670 test: replace forEach with for of in test-trace-events-api.js
PR-URL: https://github.com/nodejs/node/pull/50784
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2023-12-21 17:10:06 -08:00
Luigi Pinca
30f8ef1a97
http: remove misleading warning
There are cases where the `'clientError'` event can be emitted multiple
times, even if the socket is correctly destroyed.

Fixes: https://github.com/nodejs/node/issues/51073
PR-URL: https://github.com/nodejs/node/pull/51204
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
2023-12-21 20:09:01 +00:00
Rafael Gonzaga
918e36e0b2
src,permission: add --allow-addon flag
PR-URL: https://github.com/nodejs/node/pull/51183
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
2023-12-21 17:44:11 +00:00
Rafael Gonzaga
2000c267dd
lib,permission: handle buffer on fs.symlink
PR-URL: https://github.com/nodejs/node/pull/51212
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
2023-12-21 17:36:13 +00:00
Rafael Gonzaga
3f2e234d98
permission: fix wildcard when children > 1
PR-URL: https://github.com/nodejs/node/pull/51209
Fixes: https://github.com/nodejs/node/issues/50659
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Rich Trott <rtrott@gmail.com>
2023-12-21 17:36:05 +00:00
Chengzhong Wu
147abb99d1 lib: expose default prepareStackTrace
Expose the default prepareStackTrace implementation as
`Error.prepareStackTrace` so that userland can chain up formatting of
stack traces with built-in source maps support.

PR-URL: https://github.com/nodejs/node/pull/50827
Fixes: https://github.com/nodejs/node/issues/50733
Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
2023-12-21 16:56:35 +00:00
legendecas
2cc6a0c545 repl: fix prepareStackTrace frames array order
The second parameter of `Error.prepareStackTrace` is an array of
reversed call site frames.

PR-URL: https://github.com/nodejs/node/pull/50827
Fixes: https://github.com/nodejs/node/issues/50733
Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
2023-12-21 16:56:34 +00:00
Mattia Iannone
fe918f5f14
test: replace forEach with for-of in test-v8-serders.js
PR-URL: https://github.com/nodejs/node/pull/50791
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
2023-12-21 13:05:48 +00:00
Paolo Insogna
2cb94240f9
net: add connection attempt events
PR-URL: https://github.com/nodejs/node/pull/51045
Fixes: https://github.com/nodejs/node/issues/48763
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
2023-12-21 10:43:15 +00:00
Yagiz Nizipli
abbdc3efaa
fs: make stats date fields lazy
PR-URL: https://github.com/nodejs/node/pull/50908
Reviewed-By: Raz Luvaton <rluvaton@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2023-12-21 01:20:33 +00:00
KuthorX
c925039b35
http: do not override user-provided options object
PR-URL: https://github.com/nodejs/node/pull/33633
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: James M Snell <jasnell@gmail.com>
2023-12-19 09:55:21 +00:00
Yagiz Nizipli
65e70bf54e
fs: validate fd synchronously on c++
PR-URL: https://github.com/nodejs/node/pull/51027
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2023-12-18 22:06:45 +00:00
Marten Richter
2c571c650a
http2: addtl http/2 settings
Currently, node.js http/2 is limited in sending SETTINGs,
that are currently implemented by nghttp2.
However, nghttp2 has the ability to send arbitary SETTINGs,
that are not known beforehand.
This patch adds this feature including a fall back mechanism,
if a SETTING is implemented in a later nghttp2 or node version.

Fixes: https://github.com/nodejs/node/issues/1337
PR-URL: https://github.com/nodejs/node/pull/49025
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
2023-12-18 09:18:25 +00:00
Filip Skokan
0afe731d35 assert,crypto: make KeyObject and CryptoKey testable for equality
PR-URL: https://github.com/nodejs/node/pull/50897
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
2023-12-17 12:55:38 +00:00
Joyee Cheung
fea74b0f7b
src: support configurable snapshot
- Add support for --build-snapshot-config which allows passing
  snapshot configurations via a JSON configuration file.
- Add support for node::SnapshotConfig in the embedder API

The initial configurable options are:

- "builder" (SnapshotConfig::builder_script_path): path to the
  builder script.
- "withoutCodeCache" (SnapshotFlags::kWithoutCodeCache): disable
  code cache generation.

PR-URL: https://github.com/nodejs/node/pull/50453
Refs: https://github.com/nodejs/node/issues/42566
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
2023-12-15 15:13:46 +01:00
Marco Ippolito
215f4d04b7
crypto: move createCipher and createDecipher to eol
PR-URL: https://github.com/nodejs/node/pull/50973
Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
Reviewed-By: James M Snell <jasnell@gmail.com>
2023-12-15 14:00:52 +00:00
Pulkit Gupta
452d29c62b
test_runner: format coverage report for tap reporter
PR-URL: https://github.com/nodejs/node/pull/51119
Reviewed-By: Raz Luvaton <rluvaton@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Debadree Chatterjee <debadree333@gmail.com>
2023-12-15 06:53:08 +00:00
Joyee Cheung
5ac658102d
test: deflake test-diagnostics-channel-memory-leak
PR-URL: https://github.com/nodejs/node/pull/50572
Refs: 0fd478bcda
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
2023-12-15 00:35:40 +01:00
Joyee Cheung
5fd5c1eca3
test: test syncrhnous methods of child_process in snapshot
These currently work in snapshot builder scripts. Asynchronous
methods are not supported yet.

PR-URL: https://github.com/nodejs/node/pull/50943
Refs: https://github.com/nodejs/node/issues/50924
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2023-12-14 22:11:28 +01:00
Tim Perry
4b76ccea95
http: preserve raw header duplicates in writeHead after setHeader calls
writeHead accepts a raw header array, which is intended to allow
directly specifying raw header details, such as ordering, duplicates
and header key casing. When used by itself this works correctly.

However, if setHeader was called first, it effectively changed the
behaviour of subsequent writeHead calls, so that even if a raw header
array was provided, duplicates were collapsed, losing raw header data.

This change preserves the raw headers passed to writeHead, while still
maintaining the 'writeHead overwrites setHeader' behaviour.

PR-URL: https://github.com/nodejs/node/pull/50394
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2023-12-14 14:26:30 +00:00
Arsalan Ahmad
6e90fed8c3
http: handle multi-value content-disposition header
Headers in nodejs can be arrays and current workaround for
content-disposition header do not take this into account.
This change fixes that and makes sure array values are handled
properly.

PR-URL: https://github.com/nodejs/node/pull/50977
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2023-12-11 08:41:23 +00:00
Pulkit Gupta
f801b58e77
test_runner: fix infinite loop when files are undefined in test runner
PR-URL: https://github.com/nodejs/node/pull/51047
Fixes: https://github.com/nodejs/node/issues/48823
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: James M Snell <jasnell@gmail.com>
2023-12-10 09:35:22 +00:00
kylo5aby
639c366883
stream: fix fd is null when calling clearBuffer
PR-URL: https://github.com/nodejs/node/pull/50994
Fixes: https://github.com/nodejs/node/issues/50979
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Raz Luvaton <rluvaton@gmail.com>
Reviewed-By: Robert Nagy <ronagy@icloud.com>
2023-12-07 18:21:19 +00:00
Joyee Cheung
1e31a01f89
src: implement --trace-promises
This patch implements a debugging flag that dumps the current
stack trace when a promise is created or resolved. To reduce
noise we ignore before and after events (as the execution is
less interesting) and use the per-isolate hook to avoid extra
JS frames. This flag can assist work in reducing unnecessary
promise overhead.

PR-URL: https://github.com/nodejs/node/pull/50899
Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
2023-12-05 11:26:44 +00:00
77e3dfca5c
lib: don't parse windows drive letters as schemes
We were incorrectly parsing windows drive letters as schemes. This was
polluting the source map cache with malformed file paths.

Fixes: https://github.com/nodejs/node/issues/50523
PR-URL: https://github.com/nodejs/node/pull/50580
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
2023-12-05 09:24:14 +00:00
Jérémy Lal
fba2c9332f
test: escape cwd in regexp
Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/50980
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
2023-12-05 00:17:48 +00:00
Murilo Kakazu
7bfb087727
fs: use default w flag for writeFileSync with utf8 encoding
PR-URL: https://github.com/nodejs/node/pull/50990
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
2023-12-03 13:49:50 +00:00
Antoine du Hamel
2e458d9736
fs: introduce dirent.parentPath
The goal is to replace `dirent.path` using a name that's less likely to
create confusion.
`dirent.path` value has not been stable, moving it to a different
property name should avoid breaking some upgrading user expectations.

PR-URL: https://github.com/nodejs/node/pull/50976
Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
Reviewed-By: LiviaMedeiros <livia@cirno.name>
2023-12-02 22:49:21 +00:00
Angelo Parziale
60ffa9f1b3
test: replace forEach to for.. test-webcrypto-export-import-cfrg.js
PR-URL: https://github.com/nodejs/node/pull/50785
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
2023-12-01 18:27:21 +00:00
DylanTet
2f4065250e
url: throw error if argument length of revokeObjectURL is 0
Added a check to see if url wasn't included as an argument
which will then throw an error.

Fixes: https://github.com/nodejs/node/issues/50432
PR-URL: https://github.com/nodejs/node/pull/50433
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Zeyu "Alex" Yang <himself65@outlook.com>
2023-11-30 21:26:56 +00:00
Jithil P Ponnan
3f10a2164c test: fix message v8 not normalising alphanumeric paths
PR-URL: https://github.com/nodejs/node/pull/50730
Fixes: https://github.com/nodejs/node/issues/50724
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
2023-11-28 17:36:26 -03:00
Joyee Cheung
97c29def52
test: consolidate utf8 text fixtures in tests
We previously used a text that appears to be an excerpt of
https://zh.wikipedia.org/wiki/%E5%8D%97%E8%B6%8A%E5%9B%BD
and can have copyright/license complications. It may
also include some geopolitical nuances. The text has been
repeated through out the code base without much reuse.

This patch consolidates the fixtures by adding a common helper
string as `fixtures.utf8TestText` which is identical to a copy
in test/fixtures/utf8_test_text.txt. It also updates the text
to a copy of 蘭亭集序, It was chosen because:

1. It's a well-known Chinese classical piece written in 353 CE
   and therefore in public domain. The string is copied from
   https://zh.wikisource.org/zh-hant/%E8%98%AD%E4%BA%AD%E9%9B%86%E5%BA%8F
   which contains a disclaimer of copyright for this reason.
2. The text is in suitable length for general UTF8 string
   read/write tests (including punctuations, 389 code points and
   1167 bytes).
3. This is also commonly used as reference text for Chinese text
   layout tests.
4. It's a timeless and harmless preface for a collection of poems,
   written by a uncontroversial figure who passed away >1600 years
   ago and contains no geopolitical nuances. Background and an
   English translation of this text can be found at
   https://en.wikipedia.org/wiki/Lantingji_Xu

PR-URL: https://github.com/nodejs/node/pull/50732
Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
2023-11-28 17:18:02 +00:00
CanadaHonk
4466deeb34
fs: add c++ fast path for writeFileSync utf8
PR-URL: https://github.com/nodejs/node/pull/49884
Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2023-11-27 00:01:39 +00:00
Moshe Atlow
f28839b5f3
fs: fix glob returning duplicates
PR-URL: https://github.com/nodejs/node/pull/50881
Fixes: https://github.com/nodejs/node/issues/50875
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
2023-11-26 07:31:58 +00:00
Brad House
345d16cc50 test: fix dns test case failures after c-ares update to 1.21.0+
c-ares has made intentional changes to the behavior of TXT records
to comply with RFC 7208, which concatenates multiple strings for
the same TXT record into a single string.  Multiple TXT records
are not concatenated.

Also, response handling has changed, such that a response which is
completely invalid in formatting is thrown away as a malicious
forged/spoofed packet rather than returning EBADRESP.  This is one
step toward RFC 9018 (EDNS COOKIES) which will require the message
to at least be structurally valid to validate against spoofed
records.

Fix By: Brad House (@bradh352)

PR-URL: https://github.com/nodejs/node/pull/50743
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Fixes: https://github.com/nodejs/node/issues/50741
Refs: https://github.com/nodejs/node/issues/50444
2023-11-24 15:59:39 +01:00
Conor Watson
303654c501
test: replace forEach with for of
PR-URL: https://github.com/nodejs/node/pull/50594
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2023-11-24 14:11:34 +00:00
Alessandro Di Nisio
8c72210457
test: replace forEach to for at test-webcrypto-sign-verify-ecdsa.js
PR-URL: https://github.com/nodejs/node/pull/50795
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2023-11-24 13:52:32 +00:00
Shikha Mehta
4e713a3930
test: replace foreach with for in test-https-simple.js
Fixes: https://github.com/nodejs/node/issues/50818
PR-URL: https://github.com/nodejs/node/pull/49793
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Jithil P Ponnan <jithil@outlook.com>
2023-11-23 16:34:46 +00:00
CanadaHonk
ea88a3e1f2
fs: improve error perf of sync lstat+fstat
PR-URL: https://github.com/nodejs/node/pull/49868
Refs: https://github.com/nodejs/performance/issues/106
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2023-11-23 00:25:15 +00:00
Tobias Nießen
041d435be9
permission: do not create symlinks if target is relative
The permission model's security guarantees fall apart in the presence of
relative symbolic links. When an application attempts to create a
relative symlink, the permission model currently resolves the relative
path into an absolute path based on the process's current working
directory, checks whether the process has the relevant permissions, and
then creates the symlink using the absolute target path. This behavior
is plainly incorrect for two reasons:

1. The target path should never be resolved relative to the current
   working directory. If anything, it should be resolved relative to the
   symlink's location. (Of course, there is one insane exception to this
   rule: on Windows, each process has a current working directory per
   drive, and symlinks can be created with a target path relative to the
   current working directory of a specific drive. In that case, the
   relative path will be resolved relative to the current working
   directory for the respective drive, and the symlink will be created
   on disk with the resulting absolute path. Other relative symlinks
   will be stored as-is.)
2. Silently creating an absolute symlink when the user requested a
   relative symlink is wrong. The user may (or may not) rely on the
   symlink being relative. For example, npm heavily relies on relative
   symbolic links such that node_modules directories can be moved around
   without breaking.

Because we don't know the user's intentions, we don't know if creating
an absolute symlink instead of a relative symlink is acceptable. This
patch prevents the faulty behavior by not (incorrectly) resolving
relative symlink targets when the permission model is enabled, and by
instead simply refusing the create any relative symlinks.

The fs APIs accept Uint8Array objects for paths to be able to handle
arbitrary file name charsets, however, checking whether such an object
represents a relative part in a reliable and portable manner is tricky.
Other parts of the permission model incorrectly convert such objects to
strings and then back to an Uint8Array (see 1f64147eb6),
however, for now, this bug fix will simply throw on non-string symlink
targets when the permission model is enabled. (The permission model
already breaks existing applications in various ways, so this shouldn't
be too dramatic.)

PR-URL: https://github.com/nodejs/node/pull/49156
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Michael Dawson <midawson@redhat.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2023-11-22 17:30:36 +00:00