npm / npm/cli

[BUG] Silent failure when cafile has restrictive filesystem permissions (EPERM)

Open
#8,600 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
10.1k
Forks
4.7k
Avg merge
2d 2h
Merged PRs (30d)
19

Description

Summary

Silent failure when npm CLI loads cafile / NODE_EXTRA_CA_CERTS that has restrictive filesystem permissions. npm exits with EPERM stack trace but prints no user-visible error. Even when run with --loglevel verbose.

Environment
  • npm: Reproducible with 10.9.3 and 11.6.0
  • node: Reproducible with 20.20.0 and 24.9.0
  • OS: macOS 15.x
  • Shell: zsh 5.9 (Terminal.app)
  • npm config sources: ~/.npmrc with
    cafile=/Users/<user>/Documents/CA.crt
    NODE_EXTRA_CA_CERTS=/Users/<user>/Documents/CA.crt
    
  • Certificate file has 0000 permissions
Steps to Reproduce
  1. On macOS, create any text file and add a restrictive MACL attribute:
    echo test > /tmp/test.crt
    

chmod 000 /tmp/test.crt

2. Point npm to the file:
```ini
echo "cafile=/tmp/test.crt" >> ~/.npmrc
  1. Run a simple npm command:
    npm -v  # or npm ls --depth=0
    
Expected Behavior

npm should surface an error such as:

Error: cannot read cafile /tmp/test.crt (EPERM) while trying to load `cacert`.

and exit non-zero so users can diagnose quickly.

Actual Behavior

npm prints no error even when run with --loglevel verbose, then shows a stack trace:

Error: EPERM: operation not permitted, open '/tmp/test.crt'
    at readFileSync (node:fs:440:20)
    …

Command exits with code 1; users see nothing, resulting in silent failure.

Additional context

Full verbose stack trace attached below.

Stack trace
Error: EPERM: operation not permitted, open '/Users/.../CA.crt'
    at readFileSync (node:fs:440:20)
    at maybeReadFile (@npmcli/config/lib/definitions/definitions.js:13:12)
    at Definition.flatten (@npmcli/config/lib/definitions/definitions.js:363:19)
    at Config.flatten (@npmcli/config/lib/definitions/index.js:16:11)
    at get flat (@npmcli/config/lib/index.js:217:20)
    at get flatOptions (/Users/.../npm/lib/npm.js:360:13)
    …

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at @npmcli/config/lib/definitions/definitions.js, where maybeReadFile is shown in the stack trace, and follow how the error reaches Config.flatten and npm’s flatOptions. Reproduce with a cafile set to a 000-permission file using npm -v or npm ls --depth=0. Done means the EPERM is visible to the user with a useful cafile-related message and the command exits non-zero.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
cli, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.