Skip to content

Commit

Permalink
src,permission: handle process.chdir on pm
Browse files Browse the repository at this point in the history
PR-URL: nodejs#53175
Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
  • Loading branch information
RafaelGSS authored and pull[bot] committed Jun 26, 2024
1 parent 83fd53c commit 76cab5f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/node_process_methods.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ static void Chdir(const FunctionCallbackInfo<Value>& 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
Expand Down
11 changes: 11 additions & 0 deletions test/fixtures/permission/fs-read.js
Original file line number Diff line number Diff line change
Expand Up @@ -385,4 +385,15 @@ const regularFile = __filename;
permission: 'FileSystemRead',
resource: path.toNamespacedPath(blockedFile),
}));
}

// process.chdir
{
assert.throws(() => {
process.chdir(blockedFolder);
}, common.expectsError({
code: 'ERR_ACCESS_DENIED',
permission: 'FileSystemRead',
resource: blockedFolder,
}));
}

0 comments on commit 76cab5f

Please sign in to comment.