Commit Graph

764 Commits

Author SHA1 Message Date
Hüseyin Açacak 00b2f07f9d
fs,win: fix bug in paths with trailing slashes
Fixes: https://github.com/nodejs/node/issues/17801
Refs: https://github.com/nodejs/node/pull/33831
PR-URL: https://github.com/nodejs/node/pull/54160
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
2024-10-10 11:14:56 +00:00
Carlos Espa f5d454ac7e
src: add receiver to fast api callback methods
When creating an fast api the callback might use the receiver. In that
case if the internal binding is destructured the method won't have
access to the reciver and it will throw. Passing the receiver as second
argument ensures the receiver is available.

PR-URL: https://github.com/nodejs/node/pull/54408
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
2024-09-28 09:46:03 +00:00
Sonny 090add7864
fs: refactoring declaratively with `Array.fromAsync`
Refs: https://github.com/nodejs/node/pull/51912
PR-URL: https://github.com/nodejs/node/pull/54644
Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com>
2024-09-27 11:59:09 +02:00
Jonas 3ed9f989b8
fs: remove unnecessary option argument validation
PR-URL: https://github.com/nodejs/node/pull/53958
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
2024-08-06 18:43:41 +00:00
Rafael Gonzaga 358ff748ea
lib,permission: support Buffer to permission.has
PR-URL: https://github.com/nodejs/node/pull/54104
Fixes: https://github.com/nodejs/node/issues/54100
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
2024-08-03 16:46:57 +00:00
Yagiz Nizipli 7168295e7a
fs: move `rmSync` implementation to c++
PR-URL: https://github.com/nodejs/node/pull/53617
Reviewed-By: Daniel Lemire <daniel@lemire.me>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
2024-07-18 20:02:49 +00:00
Jonas bcec922e3e
fs: remove unnecessary option argument validation
PR-URL: https://github.com/nodejs/node/pull/53861
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
2024-07-17 23:29:56 +00:00
Daniel Bayley 953abf4887
lib: refactor `platform` utility methods
PR-URL: https://github.com/nodejs/node/pull/53817
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
2024-07-15 18:58:11 +00:00
RafaelGSS b9289a6e29 lib,permission: support fs.lstat
PR-URL: https://github.com/nodejs-private/node-private/pull/486/
Fixes: https://hackerone.com/bugs?subject=nodejs&report_id=2145862
Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
CVE-ID: CVE-2024-22018
2024-07-08 15:38:52 -03:00
RafaelGSS 01e9eac912 lib,permission: disable fchmod/fchown when pm enabled
PR-URL: https://github.com/nodejs-private/node-private/pull/584
Refs: https://hackerone.com/reports/2472071
CVE-ID: CVE-2024-36137
2024-07-08 15:38:33 -03:00
Yagiz Nizipli f1ac7df535
fs: fix typings
PR-URL: https://github.com/nodejs/node/pull/53626
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2024-07-04 11:04:37 +00:00
Yagiz Nizipli 399eb338f1
fs: move `ToNamespacedPath` to c++
Co-Authored-By: Daniel Lemire <daniel@lemire.me>
PR-URL: https://github.com/nodejs/node/pull/52135
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
Reviewed-By: Daniel Lemire <daniel@lemire.me>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2024-06-20 02:11:10 +00:00
Feng Yu eae75fe635 doc: add err param to fs.cp callback
PR-URL: https://github.com/nodejs/node/pull/53234
Reviewed-By: LiviaMedeiros <livia@cirno.name>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2024-06-03 22:51:17 +00:00
Feng Yu f3c714b223 doc: add `err` param to fs.copyFile callback
PR-URL: https://github.com/nodejs/node/pull/53234
Reviewed-By: LiviaMedeiros <livia@cirno.name>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2024-06-03 22:51:16 +00:00
Livia Medeiros f202322ea4
fs: adjust typecheck for `type` in `fs.symlink()`
Throws `TypeError` instead of `Error`
Enables autodetection on Windows if `type === undefined`
Explicitly disallows unknown strings and non-string values

PR-URL: https://github.com/nodejs/node/pull/49741
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
2024-05-06 13:18:42 +00:00
Antoine du Hamel 231548b5cf
lib: enforce ASCII order in error code imports
PR-URL: https://github.com/nodejs/node/pull/52625
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
2024-04-23 17:05:38 +00:00
Ruy Adorno 5548928cb4
fs: fix read / readSync positional offset types
This changeset fixes the types in comments to match the implementation.

PR-URL: https://github.com/nodejs/node/pull/52603
Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Reviewed-By: LiviaMedeiros <livia@cirno.name>
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: James M Snell <jasnell@gmail.com>
2024-04-22 06:06:30 +00:00
Tobias Nießen 8c0b723ccb
fs,permission: make handling of buffers consistent
Commit 2000c267dd added explicit handling
of Buffers to fs.symlink, but not to fs.symlinkSync or
fs.promises.symlink. This change adapts the latter two functions to
behave like fs.symlink.

Refs: https://github.com/nodejs/node/pull/49156
Refs: https://github.com/nodejs/node/pull/51212
PR-URL: https://github.com/nodejs/node/pull/52348
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
2024-04-06 07:37:04 +00:00
Yagiz Nizipli 61e5de1268
fs: refactor maybeCallback function
PR-URL: https://github.com/nodejs/node/pull/52129
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2024-03-19 18:32:16 +00:00
Yagiz Nizipli 639c096004 fs: validate fd from cpp on `fchown`
PR-URL: https://github.com/nodejs/node/pull/52051
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
2024-03-14 02:01:26 +00:00
Yagiz Nizipli 9ac1fe05d7 fs: validate fd from cpp on `close`
PR-URL: https://github.com/nodejs/node/pull/52051
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
2024-03-14 02:01:25 +00:00
Yagiz Nizipli 3ec20f25df
fs: validate file mode from cpp
PR-URL: https://github.com/nodejs/node/pull/52050
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
Reviewed-By: Daniel Lemire <daniel@lemire.me>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2024-03-14 01:22:55 +00:00
Moshe Atlow 151d365ad1
fs: expose glob and globSync
PR-URL: https://github.com/nodejs/node/pull/51912
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Nitzan Uziely <linkgoron@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
2024-03-03 23:15:35 +00:00
Jungku Lee 27d839f468
fs: update jsdoc for `filehandle.createWriteStream` and `appendFile`
PR-URL: https://github.com/nodejs/node/pull/51494
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Deokjin Kim <deokjin81.kim@gmail.com>
2024-01-20 15:55:00 +00:00
Rafael Gonzaga 22f4482587
fs,test: add URL to string to fs.watch
Signed-off-by: RafaelGSS <rafael.nunu@hotmail.com>
PR-URL: https://github.com/nodejs/node/pull/51346
Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
2024-01-05 00:49:07 +00:00
Yagiz Nizipli 5155238064
fs: add missing jsdoc parameters to `readSync`
PR-URL: https://github.com/nodejs/node/pull/51225
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
2023-12-22 00:09:08 +01: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
Yagiz Nizipli 202c87222c
fs: improve mkdtemp performance for buffer prefix
PR-URL: https://github.com/nodejs/node/pull/51078
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2023-12-20 10:44:12 +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
Yagiz Nizipli 3551dc07eb
fs: throw fchownSync error from c++
PR-URL: https://github.com/nodejs/node/pull/51075
Refs: https://github.com/nodejs/performance/issues/106
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2023-12-12 00:34:47 +00:00
Jungku Lee 42b238ec9a
fs: update params in jsdoc for createReadStream and createWriteStream
PR-URL: https://github.com/nodejs/node/pull/51063
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Raz Luvaton <rluvaton@gmail.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Reviewed-By: Deokjin Kim <deokjin81.kim@gmail.com>
2023-12-07 19:42:45 +00:00
IlyasShabi 27b2ce5ba6
fs: improve error performance of readvSync
PR-URL: https://github.com/nodejs/node/pull/50100
Refs: https://github.com/nodejs/performance/issues/106
Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
2023-12-05 18:31:23 +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
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
CanadaHonk f11b2061ea
fs: improve error performance for `rmdirSync`
PR-URL: https://github.com/nodejs/node/pull/49846
Refs: https://github.com/nodejs/performance/issues/106
Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
2023-11-26 19:23:41 +00:00
Jungku Lee ec79232938
fs: fix to not return for void function
PR-URL: https://github.com/nodejs/node/pull/50769
Reviewed-By: Matthew Aitken <maitken033380023@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Qingyu Deng <i@ayase-lab.com>
2023-11-24 17:47:59 +00:00
CanadaHonk dd338e3429
fs: replace deprecated `path._makeLong` in copyFile
PR-URL: https://github.com/nodejs/node/pull/50844
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2023-11-23 22:47:36 +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
Aras Abbasi 83e6350b82
errors: improve hideStackFrames
PR-URL: https://github.com/nodejs/node/pull/49990
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2023-11-11 16:25:08 +00:00
Jungku Lee 63494a92b0
fs: update param in jsdoc for `readdir`
PR-URL: https://github.com/nodejs/node/pull/50448
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Deokjin Kim <deokjin81.kim@gmail.com>
2023-10-30 15:51:07 +00:00
Jungku Lee 506858bf13
fs: improve error performance for `readSync`
PR-URL: https://github.com/nodejs/node/pull/50033
Refs: https://github.com/nodejs/performance/issues/106
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
2023-10-21 02:00:00 +00:00
Jungku Lee fbd08ec4f3
fs: improve error performance for `fsyncSync`
PR-URL: https://github.com/nodejs/node/pull/49880
Refs: https://github.com/nodejs/performance/issues/106
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
2023-10-20 23:39:14 +00:00
CanadaHonk c37cf1832c
fs: improve error performance for `mkdirSync`
PR-URL: https://github.com/nodejs/node/pull/49847
Refs: https://github.com/nodejs/performance/issues/106
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
2023-10-20 23:39:03 +00:00
Yagiz Nizipli 1a5db6f173 fs: improve error performance of `realpathSync`
PR-URL: https://github.com/nodejs/node/pull/49962
Refs: https://github.com/nodejs/performance/issues/106
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
2023-10-18 15:56:27 +00:00
Yagiz Nizipli 5f0276d7a0 fs: improve error performance of `lchownSync`
PR-URL: https://github.com/nodejs/node/pull/49962
Refs: https://github.com/nodejs/performance/issues/106
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
2023-10-18 15:56:26 +00:00
Yagiz Nizipli 449dc45691 fs: improve error performance of `symlinkSync`
PR-URL: https://github.com/nodejs/node/pull/49962
Refs: https://github.com/nodejs/performance/issues/106
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
2023-10-18 15:56:25 +00:00
Yagiz Nizipli 7603bf5b81 fs: improve error performance of `readlinkSync`
PR-URL: https://github.com/nodejs/node/pull/49962
Refs: https://github.com/nodejs/performance/issues/106
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
2023-10-18 15:56:24 +00:00
Yagiz Nizipli d68996538c fs: improve error performance of `mkdtempSync`
PR-URL: https://github.com/nodejs/node/pull/49962
Refs: https://github.com/nodejs/performance/issues/106
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
2023-10-18 15:56:23 +00:00