Skip to content

fs.glob (async and sync) returns no matches when --allow-fs-read is used #61499

Description

@louiellan

Version

22.22.1 (22.x), 24.14.0 (24.x), 25.8.1 (25.x)

Platform

Linux louiellan-IdeaPad-3-15ITL6 6.14.0-37-generic #37~24.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Nov 20 10:25:38 UTC 2 x86_64 x86_64 x86_64 GNU/Linux

Subsystem

fs, permission

What steps will reproduce the bug?

Create the file

sample1.js

const fs = require('fs')
console.log(fs.globSync('somedir/*'));

Directory Structure

somedir
|--> file1.js
sample1.js

Run the following commands:

node --permission --allow-fs-read=somedir/ ./sample1.js

How often does it reproduce? Is there a required condition?

The bug consistently reproduces if the --allow-fs-read is given a specific directory such as somedir/, but not with the allow all *

What is the expected behavior? Why is that the expected behavior?

  1. fs.globSync should return matches as it has a read access to that given directory
  2. asynchronous fs.glob (also from node:fs/promises) returns matches to that given directory

Code snippet for checking fs.glob working as intended
sample2.js
(works just fine - for comparison)

const fsPromise = require('fs/promises'); 
(async () => {
for await (const entry of fsPromise.glob('somedir/*')) {
    console.log(entry);
}})();

sample3.js
(works just fine - for comparison)

const fs = require('node:fs');
fs.glob('somedir/*', (err, matches) => {
    if (err) throw err;
    console.log(matches);
});

Running the files

node --permission --allow-fs-read=somedir/ ./sample2.js
node --permission --allow-fs-read=somedir/ ./sample3.js

What do you see instead?

Empty matches

[]

Additional information

came across this when @RafaelGSS suggested to include permission model tests while using glob on --watch-path
Refs: #59478

Activity

  1. added
    permissionIssues and PRs related to the Permission Model.
    on Jan 24, 2026
  2. RafaelGSS commented on Jan 24, 2026

    @RafaelGSS
    Member

    Does somedir exists previously? if not, try with --allow-fs-read="somedir/*". I'm not on my computer to test it right now.

  3. louiellan commented on Jan 25, 2026

    @louiellan
    ContributorAuthor

    yep, somedir exists prior to running the sample files. I also did having a somedir/*, it still throws an error

  4. artsiom-malakhau commented on Jan 25, 2026

    @artsiom-malakhau
    Contributor

    I'm working on this issue, and it seems I've found the root of the problem. The thing is, during sync processing, we get a folder access error that we don't handle in any special way. Meanwhile, in cases like glob(), we handle this situation and simply continue traversing the directories. I'm currently working on a fix

  5. louiellan commented on Mar 12, 2026

    @louiellan
    ContributorAuthor

    FWIW, after #60674 was merged, the ERR_ACCESS_DENIED does not show up anymore, but still doesn't show any matches within the directory

  6. changed the title [-]fs.globSync can't traverse on allowed directory by specific `--allow-fs-read`[/-] [+]fs.globSync returns no matches when `--allow-fs-read` is used[/+] on Mar 12, 2026
  7. khalidsaidi commented on Mar 25, 2026

    @khalidsaidi
  8. changed the title [-]fs.globSync returns no matches when `--allow-fs-read` is used[/-] [+]fs.glob returns no matches when `--allow-fs-read` is used[/+] on Mar 27, 2026
  9. github-actions commented on Jul 20, 2026

    @github-actions
    Contributor

    This issue has been marked as stale due to 90 days of inactivity.
    It will be automatically closed in 30 days if no further activity occurs. If this is still relevant, please leave a comment or update it to keep it open.

  10. added
    staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.
    on Jul 20, 2026
  11. added
    confirmed-bugIssues and PRs for confirmed bugs.
    and removed
    staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.
    on Jul 29, 2026
  12. changed the title [-]fs.glob returns no matches when `--allow-fs-read` is used[/-] [+]fs.glob (async and sync) returns no matches when `--allow-fs-read` is used[/+] on Sep 10, 2026
  13. louiellan commented on Sep 10, 2026

    @louiellan
    ContributorAuthor

    Update:
    Asynchronous fs.glob are now also affected by this

    Some workaround (for anyone who might be experiencing the same thing as me):
    Granting --allow-fs-read permission to the parent of the first directory of the glob pattern does the trick

    Example:

    |-- parent-folder/
         |-- a/
               |--- file.js
    

    and that your glob path is

    fs.glob(`a/file.js`, ...)

    Grant by the parent folder and because it's a relative, --allow-fs-read=. instead of the a/ specific folder

    For absolute glob patterns, like /home/user/folder/*, inconveniently, it's granting permission to the root, --allow-fs-read=/

  14. xia-chao commented on Sep 21, 2026

    @xia-chao
    Contributor

    Still happens on current main after native glob. #61552 is the old JS path.
    PR: #66172

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugIssues and PRs for confirmed bugs.permissionIssues and PRs related to the Permission Model.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions