Skip to content

Commit c39a43b

Browse files
committed
permission: handle fs.watchFile
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
1 parent 4ba246b commit c39a43b

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/node_stat_watcher.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "memory_tracker-inl.h"
2626
#include "node_external_reference.h"
2727
#include "node_file-inl.h"
28+
#include "permission/permission.h"
2829
#include "util-inl.h"
2930

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

112113
node::Utf8Value path(args.GetIsolate(), args[0]);
113114
CHECK_NOT_NULL(*path);
115+
THROW_IF_INSUFFICIENT_PERMISSIONS(
116+
wrap->env(),
117+
permission::PermissionScope::kFileSystemRead,
118+
path.ToStringView());
114119

115120
CHECK(args[1]->IsUint32());
116121
const uint32_t interval = args[1].As<Uint32>()->Value();

test/fixtures/permission/fs-read.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,17 @@ const regularFile = __filename;
228228
});
229229
}
230230

231+
// fs.watchFile
232+
{
233+
assert.throws(() => {
234+
fs.watchFile(blockedFile, common.mustNotCall());
235+
}, common.expectsError({
236+
code: 'ERR_ACCESS_DENIED',
237+
permission: 'FileSystemRead',
238+
resource: path.toNamespacedPath(blockedFile),
239+
}));
240+
}
241+
231242
// fs.rename
232243
{
233244
assert.throws(() => {

0 commit comments

Comments
 (0)