| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent c02a7e7 commit 8bcf0a4
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1338,8 +1338,18 @@ static void Link(const FunctionCallbackInfo<Value>& args) { | |||
| 1338 | 1338 | BufferValue src(isolate, args[0]); | |
| 1339 | 1339 | CHECK_NOT_NULL(*src); | |
| 1340 | 1340 | ||
| 1341 | + const auto src_view = src.ToStringView(); | ||
| 1342 | + // To avoid bypass the link target should be allowed to read and write | ||
| 1343 | + THROW_IF_INSUFFICIENT_PERMISSIONS( | ||
| 1344 | + env, permission::PermissionScope::kFileSystemRead, src_view); | ||
| 1345 | + THROW_IF_INSUFFICIENT_PERMISSIONS( | ||
| 1346 | + env, permission::PermissionScope::kFileSystemWrite, src_view); | ||
| 1347 | + | ||
| 1341 | 1348 | BufferValue dest(isolate, args[1]); | |
| 1342 | 1349 | CHECK_NOT_NULL(*dest); | |
| 1350 | + const auto dest_view = dest.ToStringView(); | ||
| 1351 | + THROW_IF_INSUFFICIENT_PERMISSIONS( | ||
| 1352 | + env, permission::PermissionScope::kFileSystemWrite, dest_view); | ||
| 1343 | 1353 | ||
| 1344 | 1354 | FSReqBase* req_wrap_async = GetReqWrap(args, 2); | |
| 1345 | 1355 | if (req_wrap_async != nullptr) { // link(src, dest, req) | |
@@ -2422,6 +2432,8 @@ static void Chmod(const FunctionCallbackInfo<Value>& args) { | |||
| 2422 | 2432 | ||
| 2423 | 2433 | BufferValue path(env->isolate(), args[0]); | |
| 2424 | 2434 | CHECK_NOT_NULL(*path); | |
| 2435 | + THROW_IF_INSUFFICIENT_PERMISSIONS( | ||
| 2436 | + env, permission::PermissionScope::kFileSystemWrite, path.ToStringView()); | ||
| 2425 | 2437 | ||
| 2426 | 2438 | CHECK(args[1]->IsInt32()); | |
| 2427 | 2439 | int mode = args[1].As<Int32>()->Value(); | |
@@ -2485,6 +2497,8 @@ static void Chown(const FunctionCallbackInfo<Value>& args) { | |||
| 2485 | 2497 | ||
| 2486 | 2498 | BufferValue path(env->isolate(), args[0]); | |
| 2487 | 2499 | CHECK_NOT_NULL(*path); | |
| 2500 | + THROW_IF_INSUFFICIENT_PERMISSIONS( | ||
| 2501 | + env, permission::PermissionScope::kFileSystemWrite, path.ToStringView()); | ||
| 2488 | 2502 | ||
| 2489 | 2503 | CHECK(IsSafeJsInt(args[1])); | |
| 2490 | 2504 | const uv_uid_t uid = static_cast<uv_uid_t>(args[1].As<Integer>()->Value()); | |
@@ -2551,6 +2565,8 @@ static void LChown(const FunctionCallbackInfo<Value>& args) { | |||
| 2551 | 2565 | ||
| 2552 | 2566 | BufferValue path(env->isolate(), args[0]); | |
| 2553 | 2567 | CHECK_NOT_NULL(*path); | |
| 2568 | + THROW_IF_INSUFFICIENT_PERMISSIONS( | ||
| 2569 | + env, permission::PermissionScope::kFileSystemWrite, path.ToStringView()); | ||
| 2554 | 2570 | ||
| 2555 | 2571 | CHECK(IsSafeJsInt(args[1])); | |
| 2556 | 2572 | const uv_uid_t uid = static_cast<uv_uid_t>(args[1].As<Integer>()->Value()); | |
@@ -2646,6 +2662,8 @@ static void LUTimes(const FunctionCallbackInfo<Value>& args) { | |||
| 2646 | 2662 | ||
| 2647 | 2663 | BufferValue path(env->isolate(), args[0]); | |
| 2648 | 2664 | CHECK_NOT_NULL(*path); | |
| 2665 | + THROW_IF_INSUFFICIENT_PERMISSIONS( | ||
| 2666 | + env, permission::PermissionScope::kFileSystemWrite, path.ToStringView()); | ||
| 2649 | 2667 | ||
| 2650 | 2668 | CHECK(args[1]->IsNumber()); | |
| 2651 | 2669 | const double atime = args[1].As<Number>()->Value(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,14 +5,11 @@ const common = require('../../common'); | |||
| 5 | 5 | const assert = require('assert'); | |
| 6 | 6 | const fs = require('fs'); | |
| 7 | 7 | const path = require('path'); | |
| 8 | - const os = require('os'); | ||
| 9 | 8 | ||
| 10 | 9 | const blockedFile = process.env.BLOCKEDFILE; | |
| 11 | 10 | const blockedFolder = process.env.BLOCKEDFOLDER; | |
| 12 | 11 | const allowedFolder = process.env.ALLOWEDFOLDER; | |
| 13 | 12 | const regularFile = __filename; | |
| 14 | - const uid = os.userInfo().uid; | ||
| 15 | - const gid = os.userInfo().gid; | ||
| 16 | 13 | ||
| 17 | 14 | // fs.readFile | |
| 18 | 15 | { | |
@@ -106,19 +103,6 @@ const gid = os.userInfo().gid; | |||
| 106 | 103 | }); | |
| 107 | 104 | } | |
| 108 | 105 | ||
| 109 | - // fs.chownSync (should not bypass) | ||
| 110 | - { | ||
| 111 | - assert.throws(() => { | ||
| 112 | - // This operation will work fine | ||
| 113 | - fs.chownSync(blockedFile, uid, gid); | ||
| 114 | - fs.readFileSync(blockedFile); | ||
| 115 | - }, common.expectsError({ | ||
| 116 | - code: 'ERR_ACCESS_DENIED', | ||
| 117 | - permission: 'FileSystemRead', | ||
| 118 | - resource: path.toNamespacedPath(blockedFile), | ||
| 119 | - })); | ||
| 120 | - } | ||
| 121 | - | ||
| 122 | 106 | // fs.copyFile | |
| 123 | 107 | { | |
| 124 | 108 | assert.throws(() => { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -31,6 +31,15 @@ const writeOnlyFolder = process.env.WRITEONLYFOLDER; | |||
| 31 | 31 | permission: 'FileSystemWrite', | |
| 32 | 32 | resource: path.toNamespacedPath(path.join(readOnlyFolder, 'file')), | |
| 33 | 33 | })); | |
| 34 | + assert.throws(() => { | ||
| 35 | + fs.link(path.join(readOnlyFolder, 'file'), path.join(readWriteFolder, 'link-to-read-only'), (err) => { | ||
| 36 | + assert.ifError(err); | ||
| 37 | + }); | ||
| 38 | + }, common.expectsError({ | ||
| 39 | + code: 'ERR_ACCESS_DENIED', | ||
| 40 | + permission: 'FileSystemWrite', | ||
| 41 | + resource: path.toNamespacedPath(path.join(readOnlyFolder, 'file')), | ||
| 42 | + })); | ||
| 34 | 43 | ||
| 35 | 44 | // App will be able to symlink to a writeOnlyFolder | |
| 36 | 45 | fs.symlink(path.join(readWriteFolder, 'file'), path.join(writeOnlyFolder, 'link-to-read-write'), 'file', (err) => { | |
@@ -48,6 +57,21 @@ const writeOnlyFolder = process.env.WRITEONLYFOLDER; | |||
| 48 | 57 | // App will be able to write to the symlink | |
| 49 | 58 | fs.writeFile(path.join(writeOnlyFolder, 'link-to-read-write'), 'some content', common.mustSucceed()); | |
| 50 | 59 | }); | |
| 60 | + fs.link(path.join(readWriteFolder, 'file'), path.join(writeOnlyFolder, 'link-to-read-write2'), (err) => { | ||
| 61 | + assert.ifError(err); | ||
| 62 | + // App will won't be able to read the link | ||
| 63 | + assert.throws(() => { | ||
| 64 | + fs.readFile(path.join(writeOnlyFolder, 'link-to-read-write2'), (err) => { | ||
| 65 | + assert.ifError(err); | ||
| 66 | + }); | ||
| 67 | + }, common.expectsError({ | ||
| 68 | + code: 'ERR_ACCESS_DENIED', | ||
| 69 | + permission: 'FileSystemRead', | ||
| 70 | + })); | ||
| 71 | + | ||
| 72 | + // App will be able to write to the link | ||
| 73 | + fs.writeFile(path.join(writeOnlyFolder, 'link-to-read-write2'), 'some content', common.mustSucceed()); | ||
| 74 | + }); | ||
| 51 | 75 | ||
| 52 | 76 | // App won't be able to symlink to a readOnlyFolder | |
| 53 | 77 | assert.throws(() => { | |
@@ -59,4 +83,13 @@ const writeOnlyFolder = process.env.WRITEONLYFOLDER; | |||
| 59 | 83 | permission: 'FileSystemWrite', | |
| 60 | 84 | resource: path.toNamespacedPath(path.join(readOnlyFolder, 'link-to-read-only')), | |
| 61 | 85 | })); | |
| 86 | + assert.throws(() => { | ||
| 87 | + fs.link(path.join(readWriteFolder, 'file'), path.join(readOnlyFolder, 'link-to-read-only'), (err) => { | ||
| 88 | + assert.ifError(err); | ||
| 89 | + }); | ||
| 90 | + }, common.expectsError({ | ||
| 91 | + code: 'ERR_ACCESS_DENIED', | ||
| 92 | + permission: 'FileSystemWrite', | ||
| 93 | + resource: path.toNamespacedPath(path.join(readOnlyFolder, 'link-to-read-only')), | ||
| 94 | + })); | ||
| 62 | 95 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -80,6 +80,14 @@ const symlinkFromBlockedFile = process.env.EXISTINGSYMLINK; | |||
| 80 | 80 | code: 'ERR_ACCESS_DENIED', | |
| 81 | 81 | permission: 'FileSystemWrite', | |
| 82 | 82 | })); | |
| 83 | + assert.throws(() => { | ||
| 84 | + fs.link(regularFile, blockedFolder + '/asdf', (err) => { | ||
| 85 | + assert.ifError(err); | ||
| 86 | + }); | ||
| 87 | + }, common.expectsError({ | ||
| 88 | + code: 'ERR_ACCESS_DENIED', | ||
| 89 | + permission: 'FileSystemWrite', | ||
| 90 | + })); | ||
| 83 | 91 | ||
| 84 | 92 | // App won't be able to symlink BLOCKEDFILE to REGULARDIR | |
| 85 | 93 | assert.throws(() => { | |
@@ -90,4 +98,12 @@ const symlinkFromBlockedFile = process.env.EXISTINGSYMLINK; | |||
| 90 | 98 | code: 'ERR_ACCESS_DENIED', | |
| 91 | 99 | permission: 'FileSystemRead', | |
| 92 | 100 | })); | |
| 101 | + assert.throws(() => { | ||
| 102 | + fs.link(blockedFile, path.join(__dirname, '/asdf'), (err) => { | ||
| 103 | + assert.ifError(err); | ||
| 104 | + }); | ||
| 105 | + }, common.expectsError({ | ||
| 106 | + code: 'ERR_ACCESS_DENIED', | ||
| 107 | + permission: 'FileSystemRead', | ||
| 108 | + })); | ||
| 93 | 109 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -108,6 +108,17 @@ const absoluteProtectedFolder = path.resolve(relativeProtectedFolder); | |||
| 108 | 108 | })); | |
| 109 | 109 | } | |
| 110 | 110 | ||
| 111 | + // fs.lutimes | ||
| 112 | + { | ||
| 113 | + assert.throws(() => { | ||
| 114 | + fs.lutimes(blockedFile, new Date(), new Date(), () => {}); | ||
| 115 | + }, common.expectsError({ | ||
| 116 | + code: 'ERR_ACCESS_DENIED', | ||
| 117 | + permission: 'FileSystemWrite', | ||
| 118 | + resource: path.toNamespacedPath(blockedFile), | ||
| 119 | + })); | ||
| 120 | + } | ||
| 121 | + | ||
| 111 | 122 | // fs.mkdir | |
| 112 | 123 | { | |
| 113 | 124 | assert.throws(() => { | |
@@ -270,3 +281,101 @@ const absoluteProtectedFolder = path.resolve(relativeProtectedFolder); | |||
| 270 | 281 | }); | |
| 271 | 282 | } | |
| 272 | 283 | } | |
| 284 | + | ||
| 285 | + // fs.chmod | ||
| 286 | + { | ||
| 287 | + assert.throws(() => { | ||
| 288 | + fs.chmod(blockedFile, 0o755, common.mustNotCall()); | ||
| 289 | + }, { | ||
| 290 | + code: 'ERR_ACCESS_DENIED', | ||
| 291 | + permission: 'FileSystemWrite', | ||
| 292 | + }); | ||
| 293 | + assert.rejects(async () => { | ||
| 294 | + await fs.promises.chmod(blockedFile, 0o755); | ||
| 295 | + }, { | ||
| 296 | + code: 'ERR_ACCESS_DENIED', | ||
| 297 | + permission: 'FileSystemWrite', | ||
| 298 | + }); | ||
| 299 | + } | ||
| 300 | + | ||
| 301 | + // fs.lchmod | ||
| 302 | + { | ||
| 303 | + if (common.isOSX) { | ||
| 304 | + assert.throws(() => { | ||
| 305 | + fs.lchmod(blockedFile, 0o755, common.mustNotCall()); | ||
| 306 | + }, { | ||
| 307 | + code: 'ERR_ACCESS_DENIED', | ||
| 308 | + permission: 'FileSystemWrite', | ||
| 309 | + }); | ||
| 310 | + assert.rejects(async () => { | ||
| 311 | + await fs.promises.lchmod(blockedFile, 0o755); | ||
| 312 | + }, { | ||
| 313 | + code: 'ERR_ACCESS_DENIED', | ||
| 314 | + permission: 'FileSystemWrite', | ||
| 315 | + }); | ||
| 316 | + } | ||
| 317 | + } | ||
| 318 | + | ||
| 319 | + // fs.appendFile | ||
| 320 | + { | ||
| 321 | + assert.throws(() => { | ||
| 322 | + fs.appendFile(blockedFile, 'new data', common.mustNotCall()); | ||
| 323 | + }, { | ||
| 324 | + code: 'ERR_ACCESS_DENIED', | ||
| 325 | + permission: 'FileSystemWrite', | ||
| 326 | + }); | ||
| 327 | + assert.rejects(async () => { | ||
| 328 | + await fs.promises.appendFile(blockedFile, 'new data'); | ||
| 329 | + }, { | ||
| 330 | + code: 'ERR_ACCESS_DENIED', | ||
| 331 | + permission: 'FileSystemWrite', | ||
| 332 | + }); | ||
| 333 | + } | ||
| 334 | + | ||
| 335 | + // fs.chown | ||
| 336 | + { | ||
| 337 | + assert.throws(() => { | ||
| 338 | + fs.chown(blockedFile, 1541, 999, common.mustNotCall()); | ||
| 339 | + }, { | ||
| 340 | + code: 'ERR_ACCESS_DENIED', | ||
| 341 | + permission: 'FileSystemWrite', | ||
| 342 | + }); | ||
| 343 | + assert.rejects(async () => { | ||
| 344 | + await fs.promises.chown(blockedFile, 1541, 999); | ||
| 345 | + }, { | ||
| 346 | + code: 'ERR_ACCESS_DENIED', | ||
| 347 | + permission: 'FileSystemWrite', | ||
| 348 | + }); | ||
| 349 | + } | ||
| 350 | + | ||
| 351 | + // fs.lchown | ||
| 352 | + { | ||
| 353 | + assert.throws(() => { | ||
| 354 | + fs.lchown(blockedFile, 1541, 999, common.mustNotCall()); | ||
| 355 | + }, { | ||
| 356 | + code: 'ERR_ACCESS_DENIED', | ||
| 357 | + permission: 'FileSystemWrite', | ||
| 358 | + }); | ||
| 359 | + assert.rejects(async () => { | ||
| 360 | + await fs.promises.lchown(blockedFile, 1541, 999); | ||
| 361 | + }, { | ||
| 362 | + code: 'ERR_ACCESS_DENIED', | ||
| 363 | + permission: 'FileSystemWrite', | ||
| 364 | + }); | ||
| 365 | + } | ||
| 366 | + | ||
| 367 | + // fs.link | ||
| 368 | + { | ||
| 369 | + assert.throws(() => { | ||
| 370 | + fs.link(blockedFile, path.join(blockedFolder, '/linked'), common.mustNotCall()); | ||
| 371 | + }, { | ||
| 372 | + code: 'ERR_ACCESS_DENIED', | ||
| 373 | + permission: 'FileSystemWrite', | ||
| 374 | + }); | ||
| 375 | + assert.rejects(async () => { | ||
| 376 | + await fs.promises.link(blockedFile, path.join(blockedFolder, '/linked')); | ||
| 377 | + }, { | ||
| 378 | + code: 'ERR_ACCESS_DENIED', | ||
| 379 | + permission: 'FileSystemWrite', | ||
| 380 | + }); | ||
| 381 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments