Skip to content

[glob] readdir causes EACCES: permission denied, scandir #775

Open
@smac89

Description

@smac89

// Push the child items in reverse
const childLevel = item.level + 1
const childItems = (await fs.promises.readdir(item.path)).map(
x => new SearchState(path.join(item.path, x), childLevel)

As you can see from the above snippet, internal-globber.ts doesn't check if the directory is readable before attempting to read it.

There should be a try catch block around that code:

try {
  const childLevel = item.level + 1;
  const childItems = (await fs.promises.readdir(item.path)).map(
    x =>  new SearchState(path.join(item.path, x), childLevel)
  );
  stack.push(...childItems.reverse());
catch (err) {
  if (err.code === 'EACCES') {
    continue;
  }
  throw err;
}

This issue affects the upload-artifacts action, plus I'm sure other actions that depend on this package.

Activity

added
bugSomething isn't working
and removed on Apr 23, 2021
luketomlinson

luketomlinson commented on May 13, 2021

@luketomlinson
Contributor

Hi @smac89 would you be able to give a little more information on your desired use case here? Would your desired behavior be to silently ignore directories without read permission? My main worry about a behavior change is users accidentally not matching a directory and never knowing it.

smac89

smac89 commented on May 14, 2021

@smac89
Author

@luketomlinson No ignoring it would only lead to more problems down the line.

Maybe create a new api function called tryGlob which behaves similar to glob but returns an object which contains (in addition to the list) an error field that can be used to view the error message.
This way doesn't break compatibility with existing users, while allowing them to opt into the new behavior.

howyi

howyi commented on Apr 14, 2022

@howyi

@luketomlinson @smac89
PR created due to a problem.
#1015

smac89

smac89 commented on Apr 18, 2022

@smac89
Author

@howyi that looks good. I'm not a code owner or reviewer, but thanks for creating the PR. Maybe @thboop could take a look

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

    bugSomething isn't workingglob

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @howyi@smac89@luketomlinson@thboop

      Issue actions

        [glob] readdir causes EACCES: permission denied, scandir · Issue #775 · actions/toolkit