| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 9a7f80f commit 04a886c
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,6 +17,7 @@ const { | |||
| 17 | 17 | Symbol, | |
| 18 | 18 | SymbolAsyncDispose, | |
| 19 | 19 | Uint8Array, | |
| 20 | + uncurryThis, | ||
| 20 | 21 | } = primordials; | |
| 21 | 22 | ||
| 22 | 23 | const { fs: constants } = internalBinding('constants'); | |
@@ -30,6 +31,8 @@ const { | |||
| 30 | 31 | ||
| 31 | 32 | const binding = internalBinding('fs'); | |
| 32 | 33 | const { Buffer } = require('buffer'); | |
| 34 | + const { isBuffer: BufferIsBuffer } = Buffer; | ||
| 35 | + const BufferToString = uncurryThis(Buffer.prototype.toString); | ||
| 33 | 36 | ||
| 34 | 37 | const { | |
| 35 | 38 | AbortError, | |
@@ -1018,8 +1021,13 @@ async function fstat(handle, options = { bigint: false }) { | |||
| 1018 | 1021 | } | |
| 1019 | 1022 | ||
| 1020 | 1023 | async function lstat(path, options = { bigint: false }) { | |
| 1024 | + path = getValidatedPath(path); | ||
| 1025 | + if (permission.isEnabled() && !permission.has('fs.read', path)) { | ||
| 1026 | + const resource = pathModule.toNamespacedPath(BufferIsBuffer(path) ? BufferToString(path) : path); | ||
| 1027 | + throw new ERR_ACCESS_DENIED('Access to this API has been restricted', 'FileSystemRead', resource); | ||
| 1028 | + } | ||
| 1021 | 1029 | const result = await PromisePrototypeThen( | |
| 1022 | - binding.lstat(getValidatedPath(path), options.bigint, kUsePromises), | ||
| 1030 | + binding.lstat(path, options.bigint, kUsePromises), | ||
| 1023 | 1031 | undefined, | |
| 1024 | 1032 | handleErrorFromBinding, | |
| 1025 | 1033 | ); | |
@@ -1067,6 +1075,9 @@ async function unlink(path) { | |||
| 1067 | 1075 | } | |
| 1068 | 1076 | ||
| 1069 | 1077 | async function fchmod(handle, mode) { | |
| 1078 | + if (permission.isEnabled()) { | ||
| 1079 | + throw new ERR_ACCESS_DENIED('fchmod API is disabled when Permission Model is enabled.'); | ||
| 1080 | + } | ||
| 1070 | 1081 | mode = parseFileMode(mode, 'mode'); | |
| 1071 | 1082 | return await PromisePrototypeThen( | |
| 1072 | 1083 | binding.fchmod(handle.fd, mode, kUsePromises), | |
@@ -1107,6 +1118,9 @@ async function lchown(path, uid, gid) { | |||
| 1107 | 1118 | async function fchown(handle, uid, gid) { | |
| 1108 | 1119 | validateInteger(uid, 'uid', -1, kMaxUserId); | |
| 1109 | 1120 | validateInteger(gid, 'gid', -1, kMaxUserId); | |
| 1121 | + if (permission.isEnabled()) { | ||
| 1122 | + throw new ERR_ACCESS_DENIED('fchown API is disabled when Permission Model is enabled.'); | ||
| 1123 | + } | ||
| 1110 | 1124 | return await PromisePrototypeThen( | |
| 1111 | 1125 | binding.fchown(handle.fd, uid, gid, kUsePromises), | |
| 1112 | 1126 | undefined, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,6 +4,8 @@ const common = require('../../common'); | |||
| 4 | 4 | ||
| 5 | 5 | const assert = require('assert'); | |
| 6 | 6 | const fs = require('fs'); | |
| 7 | + const fsPromises = require('node:fs/promises'); | ||
| 8 | + | ||
| 7 | 9 | const path = require('path'); | |
| 8 | 10 | const { pathToFileURL } = require('url'); | |
| 9 | 11 | ||
@@ -469,6 +471,204 @@ const regularFile = __filename; | |||
| 469 | 471 | })); | |
| 470 | 472 | } | |
| 471 | 473 | ||
| 474 | + // fsPromises.readFile | ||
| 475 | + { | ||
| 476 | + assert.rejects(async () => { | ||
| 477 | + await fsPromises.readFile(blockedFile); | ||
| 478 | + }, common.expectsError({ | ||
| 479 | + code: 'ERR_ACCESS_DENIED', | ||
| 480 | + permission: 'FileSystemRead', | ||
| 481 | + resource: path.toNamespacedPath(blockedFile), | ||
| 482 | + })).then(common.mustCall()); | ||
| 483 | + assert.rejects(async () => { | ||
| 484 | + await fsPromises.readFile(blockedFileURL); | ||
| 485 | + }, common.expectsError({ | ||
| 486 | + code: 'ERR_ACCESS_DENIED', | ||
| 487 | + permission: 'FileSystemRead', | ||
| 488 | + resource: path.toNamespacedPath(blockedFile), | ||
| 489 | + })).then(common.mustCall()); | ||
| 490 | + } | ||
| 491 | + | ||
| 492 | + // fsPromises.stat | ||
| 493 | + { | ||
| 494 | + assert.rejects(async () => { | ||
| 495 | + await fsPromises.stat(blockedFile); | ||
| 496 | + }, common.expectsError({ | ||
| 497 | + code: 'ERR_ACCESS_DENIED', | ||
| 498 | + permission: 'FileSystemRead', | ||
| 499 | + resource: path.toNamespacedPath(blockedFile), | ||
| 500 | + })).then(common.mustCall()); | ||
| 501 | + assert.rejects(async () => { | ||
| 502 | + await fsPromises.stat(blockedFileURL); | ||
| 503 | + }, common.expectsError({ | ||
| 504 | + code: 'ERR_ACCESS_DENIED', | ||
| 505 | + permission: 'FileSystemRead', | ||
| 506 | + resource: path.toNamespacedPath(blockedFile), | ||
| 507 | + })).then(common.mustCall()); | ||
| 508 | + assert.rejects(async () => { | ||
| 509 | + await fsPromises.stat(path.join(blockedFolder, 'anyfile')); | ||
| 510 | + }, common.expectsError({ | ||
| 511 | + code: 'ERR_ACCESS_DENIED', | ||
| 512 | + permission: 'FileSystemRead', | ||
| 513 | + resource: path.toNamespacedPath(path.join(blockedFolder, 'anyfile')), | ||
| 514 | + })).then(common.mustCall()); | ||
| 515 | + } | ||
| 516 | + | ||
| 517 | + // fsPromises.access | ||
| 518 | + { | ||
| 519 | + assert.rejects(async () => { | ||
| 520 | + await fsPromises.access(blockedFile, fs.constants.R_OK); | ||
| 521 | + }, common.expectsError({ | ||
| 522 | + code: 'ERR_ACCESS_DENIED', | ||
| 523 | + permission: 'FileSystemRead', | ||
| 524 | + resource: path.toNamespacedPath(blockedFile), | ||
| 525 | + })).then(common.mustCall()); | ||
| 526 | + assert.rejects(async () => { | ||
| 527 | + await fsPromises.access(blockedFileURL, fs.constants.R_OK); | ||
| 528 | + }, common.expectsError({ | ||
| 529 | + code: 'ERR_ACCESS_DENIED', | ||
| 530 | + permission: 'FileSystemRead', | ||
| 531 | + resource: path.toNamespacedPath(blockedFile), | ||
| 532 | + })).then(common.mustCall()); | ||
| 533 | + assert.rejects(async () => { | ||
| 534 | + await fsPromises.access(path.join(blockedFolder, 'anyfile'), fs.constants.R_OK); | ||
| 535 | + }, common.expectsError({ | ||
| 536 | + code: 'ERR_ACCESS_DENIED', | ||
| 537 | + permission: 'FileSystemRead', | ||
| 538 | + resource: path.toNamespacedPath(path.join(blockedFolder, 'anyfile')), | ||
| 539 | + })).then(common.mustCall()); | ||
| 540 | + } | ||
| 541 | + | ||
| 542 | + // fsPromises.copyFile | ||
| 543 | + { | ||
| 544 | + assert.rejects(async () => { | ||
| 545 | + await fsPromises.copyFile(blockedFile, path.join(blockedFolder, 'any-other-file')); | ||
| 546 | + }, common.expectsError({ | ||
| 547 | + code: 'ERR_ACCESS_DENIED', | ||
| 548 | + permission: 'FileSystemRead', | ||
| 549 | + resource: path.toNamespacedPath(blockedFile), | ||
| 550 | + })).then(common.mustCall()); | ||
| 551 | + assert.rejects(async () => { | ||
| 552 | + await fsPromises.copyFile(blockedFileURL, path.join(blockedFolder, 'any-other-file')); | ||
| 553 | + }, common.expectsError({ | ||
| 554 | + code: 'ERR_ACCESS_DENIED', | ||
| 555 | + permission: 'FileSystemRead', | ||
| 556 | + resource: path.toNamespacedPath(blockedFile), | ||
| 557 | + })).then(common.mustCall()); | ||
| 558 | + } | ||
| 559 | + | ||
| 560 | + // fsPromises.cp | ||
| 561 | + { | ||
| 562 | + assert.rejects(async () => { | ||
| 563 | + await fsPromises.cp(blockedFile, path.join(blockedFolder, 'any-other-file')); | ||
| 564 | + }, common.expectsError({ | ||
| 565 | + code: 'ERR_ACCESS_DENIED', | ||
| 566 | + permission: 'FileSystemRead', | ||
| 567 | + resource: path.toNamespacedPath(blockedFile), | ||
| 568 | + })).then(common.mustCall()); | ||
| 569 | + assert.rejects(async () => { | ||
| 570 | + await fsPromises.cp(blockedFileURL, path.join(blockedFolder, 'any-other-file')); | ||
| 571 | + }, common.expectsError({ | ||
| 572 | + code: 'ERR_ACCESS_DENIED', | ||
| 573 | + permission: 'FileSystemRead', | ||
| 574 | + resource: path.toNamespacedPath(blockedFile), | ||
| 575 | + })).then(common.mustCall()); | ||
| 576 | + } | ||
| 577 | + | ||
| 578 | + // fsPromises.open | ||
| 579 | + { | ||
| 580 | + assert.rejects(async () => { | ||
| 581 | + await fsPromises.open(blockedFile, 'r'); | ||
| 582 | + }, common.expectsError({ | ||
| 583 | + code: 'ERR_ACCESS_DENIED', | ||
| 584 | + permission: 'FileSystemRead', | ||
| 585 | + resource: path.toNamespacedPath(blockedFile), | ||
| 586 | + })).then(common.mustCall()); | ||
| 587 | + assert.rejects(async () => { | ||
| 588 | + await fsPromises.open(blockedFileURL, 'r'); | ||
| 589 | + }, common.expectsError({ | ||
| 590 | + code: 'ERR_ACCESS_DENIED', | ||
| 591 | + permission: 'FileSystemRead', | ||
| 592 | + resource: path.toNamespacedPath(blockedFile), | ||
| 593 | + })).then(common.mustCall()); | ||
| 594 | + assert.rejects(async () => { | ||
| 595 | + await fsPromises.open(path.join(blockedFolder, 'anyfile'), 'r'); | ||
| 596 | + }, common.expectsError({ | ||
| 597 | + code: 'ERR_ACCESS_DENIED', | ||
| 598 | + permission: 'FileSystemRead', | ||
| 599 | + resource: path.toNamespacedPath(path.join(blockedFolder, 'anyfile')), | ||
| 600 | + })).then(common.mustCall()); | ||
| 601 | + } | ||
| 602 | + | ||
| 603 | + // fsPromises.opendir | ||
| 604 | + { | ||
| 605 | + assert.rejects(async () => { | ||
| 606 | + await fsPromises.opendir(blockedFolder); | ||
| 607 | + }, common.expectsError({ | ||
| 608 | + code: 'ERR_ACCESS_DENIED', | ||
| 609 | + permission: 'FileSystemRead', | ||
| 610 | + resource: path.toNamespacedPath(blockedFolder), | ||
| 611 | + })).then(common.mustCall()); | ||
| 612 | + } | ||
| 613 | + | ||
| 614 | + // fsPromises.readdir | ||
| 615 | + { | ||
| 616 | + assert.rejects(async () => { | ||
| 617 | + await fsPromises.readdir(blockedFolder); | ||
| 618 | + }, common.expectsError({ | ||
| 619 | + code: 'ERR_ACCESS_DENIED', | ||
| 620 | + permission: 'FileSystemRead', | ||
| 621 | + resource: path.toNamespacedPath(blockedFolder), | ||
| 622 | + })).then(common.mustCall()); | ||
| 623 | + assert.rejects(async () => { | ||
| 624 | + await fsPromises.readdir(blockedFolder, { recursive: true }); | ||
| 625 | + }, common.expectsError({ | ||
| 626 | + code: 'ERR_ACCESS_DENIED', | ||
| 627 | + permission: 'FileSystemRead', | ||
| 628 | + resource: path.toNamespacedPath(blockedFolder), | ||
| 629 | + })).then(common.mustCall()); | ||
| 630 | + } | ||
| 631 | + | ||
| 632 | + // fsPromises.rename | ||
| 633 | + { | ||
| 634 | + assert.rejects(async () => { | ||
| 635 | + await fsPromises.rename(blockedFile, 'newfile'); | ||
| 636 | + }, common.expectsError({ | ||
| 637 | + code: 'ERR_ACCESS_DENIED', | ||
| 638 | + permission: 'FileSystemRead', | ||
| 639 | + resource: path.toNamespacedPath(blockedFile), | ||
| 640 | + })).then(common.mustCall()); | ||
| 641 | + assert.rejects(async () => { | ||
| 642 | + await fsPromises.rename(blockedFileURL, 'newfile'); | ||
| 643 | + }, common.expectsError({ | ||
| 644 | + code: 'ERR_ACCESS_DENIED', | ||
| 645 | + permission: 'FileSystemRead', | ||
| 646 | + resource: path.toNamespacedPath(blockedFile), | ||
| 647 | + })).then(common.mustCall()); | ||
| 648 | + } | ||
| 649 | + | ||
| 650 | + // fsPromises.lstat | ||
| 651 | + { | ||
| 652 | + assert.rejects(async () => { | ||
| 653 | + await fsPromises.lstat(blockedFile); | ||
| 654 | + }, common.expectsError({ | ||
| 655 | + code: 'ERR_ACCESS_DENIED', | ||
| 656 | + permission: 'FileSystemRead', | ||
| 657 | + })).then(common.mustCall()); | ||
| 658 | + assert.rejects(async () => { | ||
| 659 | + await fsPromises.lstat(blockedFileURL); | ||
| 660 | + }, common.expectsError({ | ||
| 661 | + code: 'ERR_ACCESS_DENIED', | ||
| 662 | + permission: 'FileSystemRead', | ||
| 663 | + })).then(common.mustCall()); | ||
| 664 | + assert.rejects(async () => { | ||
| 665 | + await fsPromises.lstat(path.join(blockedFolder, 'anyfile')); | ||
| 666 | + }, common.expectsError({ | ||
| 667 | + code: 'ERR_ACCESS_DENIED', | ||
| 668 | + permission: 'FileSystemRead', | ||
| 669 | + })).then(common.mustCall()); | ||
| 670 | + } | ||
| 671 | + | ||
| 472 | 672 | // fs.lstat | |
| 473 | 673 | { | |
| 474 | 674 | assert.throws(() => { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments