From ef1c0d7def76369c5ec6d68bccf9a673ed37cbd4 Mon Sep 17 00:00:00 2001 From: Rafael Gonzaga Date: Sat, 1 Jun 2024 12:12:53 -0300 Subject: [PATCH] src,permission: handle process.chdir on pm MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/53175 Reviewed-By: Yagiz Nizipli Reviewed-By: Vinícius Lourenço Claro Cardoso --- src/node_process_methods.cc | 2 ++ test/fixtures/permission/fs-read.js | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/src/node_process_methods.cc b/src/node_process_methods.cc index a7178eddf6c..a9e0f8e9b4f 100644 --- a/src/node_process_methods.cc +++ b/src/node_process_methods.cc @@ -83,6 +83,8 @@ static void Chdir(const FunctionCallbackInfo& args) { CHECK_EQ(args.Length(), 1); CHECK(args[0]->IsString()); Utf8Value path(env->isolate(), args[0]); + THROW_IF_INSUFFICIENT_PERMISSIONS( + env, permission::PermissionScope::kFileSystemRead, path.ToStringView()); int err = uv_chdir(*path); if (err) { // Also include the original working directory, since that will usually diff --git a/test/fixtures/permission/fs-read.js b/test/fixtures/permission/fs-read.js index a4808601fb7..24167344af7 100644 --- a/test/fixtures/permission/fs-read.js +++ b/test/fixtures/permission/fs-read.js @@ -387,6 +387,17 @@ const regularFile = __filename; })); } +// process.chdir +{ + assert.throws(() => { + process.chdir(blockedFolder); + }, common.expectsError({ + code: 'ERR_ACCESS_DENIED', + permission: 'FileSystemRead', + resource: blockedFolder, + })); +} + // fs.lstat { assert.throws(() => {