File tree Expand file tree Collapse file tree 3 files changed +18
-1
lines changed Expand file tree Collapse file tree 3 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -604,7 +604,8 @@ function openAsBlob(path, options = kEmptyObject) {
604
604
// The underlying implementation here returns the Blob synchronously for now.
605
605
// To give ourselves flexibility to maybe return the Blob asynchronously,
606
606
// this API returns a Promise.
607
- return PromiseResolve ( createBlobFromFilePath ( getValidatedPath ( path ) , { type } ) ) ;
607
+ path = getValidatedPath ( path ) ;
608
+ return PromiseResolve ( createBlobFromFilePath ( pathModule . toNamespacedPath ( path ) , { type } ) ) ;
608
609
}
609
610
610
611
/**
Original file line number Diff line number Diff line change 8
8
#include " node_errors.h"
9
9
#include " node_external_reference.h"
10
10
#include " node_file.h"
11
+ #include " permission/permission.h"
11
12
#include " util.h"
12
13
#include " v8.h"
13
14
@@ -85,6 +86,10 @@ void Concat(const FunctionCallbackInfo<Value>& args) {
85
86
86
87
void BlobFromFilePath (const FunctionCallbackInfo<Value>& args) {
87
88
Environment* env = Environment::GetCurrent (args);
89
+ BufferValue path (env->isolate (), args[0 ]);
90
+ CHECK_NOT_NULL (*path);
91
+ THROW_IF_INSUFFICIENT_PERMISSIONS (
92
+ env, permission::PermissionScope::kFileSystemRead , path.ToStringView ());
88
93
auto entry = DataQueue::CreateFdEntry (env, args[0 ]);
89
94
if (entry == nullptr ) {
90
95
return THROW_ERR_INVALID_ARG_VALUE (env, " Unabled to open file as blob" );
Original file line number Diff line number Diff line change @@ -249,3 +249,14 @@ const regularFile = __filename;
249
249
resource : path . toNamespacedPath ( blockedFile ) ,
250
250
} ) ) ;
251
251
}
252
+
253
+ // fs.openAsBlob
254
+ {
255
+ assert . throws ( ( ) => {
256
+ fs . openAsBlob ( blockedFile ) ;
257
+ } , common . expectsError ( {
258
+ code : 'ERR_ACCESS_DENIED' ,
259
+ permission : 'FileSystemRead' ,
260
+ resource : path . toNamespacedPath ( blockedFile ) ,
261
+ } ) ) ;
262
+ }
You can’t perform that action at this time.
0 commit comments