From 83da3e064b1c41fd510a25726b2161cba65e75ed Mon Sep 17 00:00:00 2001 From: RafaelGSS Date: Wed, 24 Apr 2024 13:25:56 -0300 Subject: [PATCH] src,permission: handle process.chdir on pm --- 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 a7178eddf6ca06..a9e0f8e9b4f6d5 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 aa210243292ed0..02ad3a1511fc10 100644 --- a/test/fixtures/permission/fs-read.js +++ b/test/fixtures/permission/fs-read.js @@ -361,3 +361,14 @@ const regularFile = __filename; resource: path.toNamespacedPath(blockedFile), })); } + +// process.chdir +{ + assert.throws(() => { + process.chdir(blockedFolder); + }, common.expectsError({ + code: 'ERR_ACCESS_DENIED', + permission: 'FileSystemRead', + resource: path.toNamespacedPath(blockedFolder), + })); +} \ No newline at end of file