Skip to content

An access problem in eslint-module-utils/resolve.js #2433

Open
@lerayne

Description

@lerayne

Hi!

recently ran into an access issue when working with eslint-plugin-import and found this problem:

the file is in the dependency eslint-module-utils which seem to not have it's own repo but is linked to this project

The file is resolve.js

here to check if a directory exists the code tries to access a list of files in its parent dir and then find parsedPath.base in received list. This makes an issue when script executor doesn't have access to the directory above

const parsedPath = path.parse(filepath);
const dir = parsedPath.dir;

let result = fileExistsCache.get(filepath, cacheSettings);
if (result != null) return result;

// base case
if (dir === '' || parsedPath.root === filepath) {
  result = true;
} else {
  const filenames = fs.readdirSync(dir);
  if (filenames.indexOf(parsedPath.base) === -1) {
    result = false;
  } else {
    result = fileExistsWithCaseSync(dir, cacheSettings, strict);
  }
}

The same functionality can be implemented this way:

if (dir === '' || parsedPath.root === filepath) {
  result = true;
} else {
  if (!fs.existsSync(path.join(dir, parsedPath.base))) {
    result = false;
  } else {
    result = fileExistsWithCaseSync(dir, cacheSettings, strict);
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions