Commit Graph

46 Commits

Author SHA1 Message Date
theanarkh bf2384f224
fs: fix return value of fs APIs
PR-URL: https://github.com/nodejs/node/pull/58996
Fixes: https://github.com/nodejs/node/issues/58747
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Jason Zhang <xzha4350@gmail.com>
Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
2025-07-20 06:51:26 +00:00
Kevin Gibbons 9523c84c17 fs: add disposable mkdtempSync
PR-URL: https://github.com/nodejs/node/pull/58516
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: LiviaMedeiros <livia@cirno.name>
2025-07-07 06:44:07 -07:00
Rafael Gonzaga 462c74181d
src,permission: add --allow-net permission
Signed-off-by: RafaelGSS <rafael.nunu@hotmail.com>
PR-URL: https://github.com/nodejs/node/pull/58517
Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
2025-06-17 12:35:23 +00:00
Rafael Gonzaga f58613a64c
src,permission: implicit allow-fs-read to app entrypoint
This commit automatically includes in the allow-fs-read
list all the app's entrypoints.

`--require` and user entry point

Signed-off-by: RafaelGSS <rafael.nunu@hotmail.com>
PR-URL: https://github.com/nodejs/node/pull/58579
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
2025-06-07 13:33:25 +00:00
Rafael Gonzaga 24e4a54471
src,permission: make ERR_ACCESS_DENIED more descriptive
This commit also adds a suggestion flag (if exists)
when ERR_ACCESS_DENIED is thrown, so users don't need
to jump into the documentation to see how to manage
that permission error.

PR-URL: https://github.com/nodejs/node/pull/57585
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2025-04-03 22:24:39 +00:00
Rafael Gonzaga 2cff256065
Revert "test: temporary remove resource check from fs read-write"
This reverts commit 55cc372b96.

PR-URL: https://github.com/nodejs/node/pull/56906
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: LiviaMedeiros <livia@cirno.name>
Reviewed-By: Claudio Wunder <cwunder@gnome.org>
2025-03-04 16:34:07 +00:00
Michaël Zasso c864dea910
lib: unexpose six process bindings
Namely: async_wrap, crypto, http_parser, signal_wrap, url, and v8.

They were runtime-deprecated 4 years ago.

PR-URL: https://github.com/nodejs/node/pull/57149
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Jacob Smith <jacob@frende.me>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2025-02-25 16:07:49 +00:00
Rafael Gonzaga 55cc372b96
test: temporary remove resource check from fs read-write
Since the last security release, the resource check has been
flaky on Windows. This commit temporarily disables those checks
to unblock the next regular release.

PR-URL: https://github.com/nodejs/node/pull/56789
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2025-01-29 15:21:48 +00:00
James M Snell 8caa1dcee6 test: rely less on duplicative common test harness utilities
There are several cleanups here that are not just style nits...

1. The `common.isMainThread` was just a passthrough to the
   `isMainThread` export on the worker_thread module. It's
   use was inconsistent and just obfuscated the fact that
   the test file depend on the `worker_threads` built-in.
   By eliminating it we simplify the test harness a bit and
   make it clearer which tests depend on the worker_threads
   check.
2. The `common.isDumbTerminal` is fairly unnecesary since
   that just wraps a public API check.
3. Several of the `common.skipIf....` checks were inconsistently
   used and really don't need to be separate utility functions.

A key part of the motivation here is to work towards making more
of the tests more self-contained and less reliant on the common
test harness where possible.

PR-URL: https://github.com/nodejs/node/pull/56712
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2025-01-25 07:23:09 +00:00
Rafael Gonzaga 53356c37b7
lib: fix `fs.readdir` recursive async
Fixes: https://github.com/nodejs/node/issues/56006
PR-URL: https://github.com/nodejs/node/pull/56041
Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
2024-12-05 21:25:25 +01:00
Rafael Gonzaga bd0c4f80e4
test: fix permission fixtures lint
PR-URL: https://github.com/nodejs/node/pull/55819
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2024-11-12 17:39:24 +01:00
Rafael Gonzaga 3a0968db43
permission: ignore internalModuleStat on module loading
This improves Permission Model usage when allowing read access to
specifi modules. To achieve that, the permission model check on
internalModuleStat has been removed meaning that on module loading,
uv_fs_stat is performed on files and folders even when the permission
model is enabled. Although a uv_fs_stat is performed, reading/executing
the module will still pass by the permission model check.

Without this PR when an app tries to --allow-fs-read=./a.js
--allow-fs-read=./b.js where `a` attempt to load b, it will fails as
it reads $pwd and no permission has been given to this path.

PR-URL: https://github.com/nodejs/node/pull/55797
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Ulises Gascón <ulisesgascongonzalez@gmail.com>
2024-11-11 17:31:44 +00:00
Rafael Gonzaga c8e12983ad
test: add buffer to fs_permission tests
PR-URL: https://github.com/nodejs/node/pull/55734
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
2024-11-07 21:48:46 +00:00
Antoine du Hamel 4e68b541fd
test: fix improper path to URL conversion
PR-URL: https://github.com/nodejs/node/pull/54509
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2024-08-24 20:10:11 +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 88027e84d8
fs: optimize `fs.cpSync` js calls
PR-URL: https://github.com/nodejs/node/pull/53614
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2024-07-22 16:00:39 +00:00
Daniel Bayley cff7da7749
src,test: further cleanup references to osx
PR-URL: https://github.com/nodejs/node/pull/53820
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
2024-07-15 20:32:26 +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 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
theanarkh 430c026911
src: fix permission inspector crash
PR-URL: https://github.com/nodejs/node/pull/53389
Fixes: https://github.com/nodejs/node/issues/53385
Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Kohei Ueno <kohei.ueno119@gmail.com>
2024-06-10 18:35:55 +00:00
Rafael Gonzaga 02079b6230
src,permission: handle process.chdir on pm
PR-URL: https://github.com/nodejs/node/pull/53175
Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
2024-06-01 15:12:53 +00:00
Rafael Gonzaga 15456e4e57
src,permission: resolve path on fs_permission
Signed-off-by: RafaelGSS <rafael.nunu@hotmail.com>
PR-URL: https://github.com/nodejs/node/pull/52761
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
2024-05-03 03:40:49 +00:00
Rafael Gonzaga 4487e37e70
src,permission: throw async errors on async APIs
PR-URL: https://github.com/nodejs/node/pull/52730
Refs: https://github.com/nodejs/security-wg/issues/898
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
2024-04-30 02:19:55 +00:00
RafaelGSS e9f395e77a lib: use cache fs internals against path traversal
PR-URL: https://github.com/nodejs-private/node-private/pull/516
Fixes: https://hackerone.com/bugs?subject=nodejs&report_id=2259914
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
CVE-ID: CVE-2024-21891
2024-02-14 14:27:35 -03:00
Tobias Nießen 46ce278079 fs: protect against modified Buffer internals in possiblyTransformPath
Use encodeUtf8String from the encoding_binding internal binding to
convert the result of path.resolve() to a Uint8Array instead of using
Buffer.from(), whose result can be manipulated by the user by
monkey-patching internals such as Buffer.prototype.utf8Write.

HackerOne report: https://hackerone.com/reports/2218653

PR-URL: https://github.com/nodejs-private/node-private/pull/497
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
CVE-ID: CVE-2024-21896
2024-02-14 14:27:34 -03:00
Paulo Chaves 09da597535
test: remove common.expectsError calls for asserts
PR-URL: https://github.com/nodejs/node/pull/51504
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2024-01-25 21:47:22 +00:00
Rafael Gonzaga cf68d006c0
test: add URL tests to fs-write
PR-URL: https://github.com/nodejs/node/pull/51352
Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
Reviewed-By: LiviaMedeiros <livia@cirno.name>
2024-01-12 15:28:32 +01:00
Andrés Morelos 09a506fe7d
test: remove unneeded common.expectsError for asserts
PR-URL: https://github.com/nodejs/node/pull/51353
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
2024-01-07 22:08:28 +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
Rafael Gonzaga 335ecda433
test: add URL tests to fs-read in pm
PR-URL: https://github.com/nodejs/node/pull/51213
Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
2023-12-21 12:56:02 +00:00
Tobias Nießen 0c5696248b
test: fix defect path traversal tests
The test never actually tested what it claims to test because it did not
properly insert separators before `..`.

PR-URL: https://github.com/nodejs/node/pull/50124
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
2023-10-16 15:50:28 +00:00
Tobias Nießen f447a4611a permission: fix Uint8Array path traversal
Previous security patches addressed path traversal vulnerabilities for
string and Buffer inputs, but ignored Uint8Array inputs. This commit
fixes the existing logic to account for the latter.

The previous implementation would silently ignore unexpected inputs,
whereas this commit introduces an explicit assertion to prevent that
unsafe behavior.

PR-URL: https://github.com/nodejs-private/node-private/pull/456
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
CVE-ID: CVE-2023-39332
2023-10-13 18:05:15 -03:00
Tobias Nießen 32bcf4ca27 permission: improve path traversal protection
Always use the original implementation of pathModule.resolve. If the
application overwrites the value of pathModule.resolve with a custom
implementation, it should not have any effect on the permission model.

PR-URL: https://github.com/nodejs-private/node-private/pull/456
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
CVE-ID: CVE-2023-39331
2023-10-13 18:05:10 -03:00
RafaelGSS 3868ae0f4f permission: ensure to resolve path when calling mkdtemp
PR-URL: https://github.com/nodejs-private/node-private/pull/440
Refs: https://hackerone.com/bugs?subject=nodejs&report_id=2037887
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
2023-08-09 14:33:14 -03:00
RafaelGSS 1f64147eb6 permission: handle buffer path on fs calls
Signed-off-by: RafaelGSS <rafael.nunu@hotmail.com>
Refs: https://hackerone.com/bugs?subject=nodejs&report_id=2038134
PR-URL: https://github.com/nodejs-private/node-private/pull/439
2023-08-09 14:29:12 -03:00
RafaelGSS 7e97e908c7 permission: handle fstatfs and add pm supported list
PR-URL: https://github.com/nodejs-private/node-private/pull/441
CVE-ID: CVE-2023-32005
2023-08-09 14:28:48 -03:00
RafaelGSS bd7443ad0a lib,permission: restrict process.binding when pm is enabled
PR-URL: https://github.com/nodejs-private/node-private/pull/438
Fixes: https://github.com/nodejs-private/node-private/issues/422
CVE-ID: CVE-2023-32558
2023-08-09 14:28:39 -03:00
RafaelGSS 205f1e643e permission: handle fs path traversal
PR-URL: https://github.com/nodejs-private/node-private/pull/403
Refs: https://hackerone.com/bugs?subject=nodejs&report_id=1952978
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
CVE-ID: CVE-2023-30584
2023-06-20 17:31:47 -03:00
RafaelGSS e15cc4595a permission: handle fs.openAsBlob
Refs: https://hackerone.com/bugs?subject=nodejs&report_id=1966492
PR-URL: https://github.com/nodejs-private/node-private/pull/405
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
CVE-ID: CVE-2023-30583
2023-06-20 17:31:42 -03:00
RafaelGSS 56b1a0fca4 permission: handle fs.watchFile
PR-URL: https://github.com/nodejs-private/node-private/pull/404
Refs: https://hackerone.com/bugs?subject=nodejs&report_id=1966499
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
CVE-ID: CVE-2023-30582
2023-06-20 17:30:08 -03:00
Rafael Gonzaga 1323992672
permission: fix chmod,chown improve fs coverage
Signed-off-by: RafaelGSS <rafael.nunu@hotmail.com>
PR-URL: https://github.com/nodejs/node/pull/47529
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
2023-04-13 14:06:44 +00:00
Rafael Gonzaga 4b80a7b0c4
permission: support fs.mkdtemp
PR-URL: https://github.com/nodejs/node/pull/47470
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Reviewed-By: Zeyu "Alex" Yang <himself65@outlook.com>
2023-04-09 21:35:16 +00:00
Rafael Gonzaga 6fd147c4b0
permission: drop process.permission.deny
PR-URL: https://github.com/nodejs/node/pull/47335
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Beth Griggs <bethanyngriggs@gmail.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
2023-04-04 17:14:04 +00:00
Rafael Gonzaga 1726da9300
permission: add path separator to loader check
Signed-off-by: RafaelGSS <rafael.nunu@hotmail.com>
PR-URL: https://github.com/nodejs/node/pull/47030
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
2023-03-15 14:27:26 +00:00
Rafael Gonzaga 00c222593e
src,process: add permission model
Signed-off-by: RafaelGSS <rafael.nunu@hotmail.com>
PR-URL: https://github.com/nodejs/node/pull/44004
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2023-02-23 18:11:51 +00:00