Skip to content

Commit

Permalink
permission: handle fs.watchFile
Browse files Browse the repository at this point in the history
PR-URL: nodejs-private/node-private#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
  • Loading branch information
RafaelGSS committed Jun 20, 2023
1 parent b607b74 commit 56b1a0f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/node_stat_watcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "memory_tracker-inl.h"
#include "node_external_reference.h"
#include "node_file-inl.h"
#include "permission/permission.h"
#include "util-inl.h"

#include <cstring>
Expand Down Expand Up @@ -111,6 +112,10 @@ void StatWatcher::Start(const FunctionCallbackInfo<Value>& args) {

node::Utf8Value path(args.GetIsolate(), args[0]);
CHECK_NOT_NULL(*path);
THROW_IF_INSUFFICIENT_PERMISSIONS(
wrap->env(),
permission::PermissionScope::kFileSystemRead,
path.ToStringView());

CHECK(args[1]->IsUint32());
const uint32_t interval = args[1].As<Uint32>()->Value();
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 @@ -228,6 +228,17 @@ const regularFile = __filename;
});
}

// fs.watchFile
{
assert.throws(() => {
fs.watchFile(blockedFile, common.mustNotCall());
}, common.expectsError({
code: 'ERR_ACCESS_DENIED',
permission: 'FileSystemRead',
resource: path.toNamespacedPath(blockedFile),
}));
}

// fs.rename
{
assert.throws(() => {
Expand Down

0 comments on commit 56b1a0f

Please sign in to comment.