npm / npm/cli

[BUG] credential checks don't resolve environment variable references

Open
#8,513 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Is there an existing issue for this?
  • I have searched the existing issues
This issue exists in the latest npm version
  • I am using the latest npm
Current Behavior

Commands like npm whoami and npm publish perform a credential check, and can remind you that you need to be logged in. However if a credential configuration setting references an environment variable (${FOO}), the credential check passes regardless of whether the environment variable is set.

Expected Behavior

The credential check first resolves any references to environment variables. If an environment variable is not set, or alternatively the interpolated string is empty, the credential check warning or error message is produced. Optionally "(environment variable FOO is not set)" could be appended to the message.

Steps To Reproduce
  1. Log out of the registry
  2. Run npm whoami or npm publish --dry-run, confirm you get ENEEDAUTH: This command requires you to be logged in
  3. Update .npmrc to include //registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}. Do not set any environment variable.
  4. Run npm whoami or npm publish --dry-run

You should continue to get ENEEDAUTH: This command requires you to be logged in, but don't.

You can reproduce this issue locally, or in a GitHub Actions workflow by using actions/setup-node (ref).

Environment
  • npm: 11.5.2
  • Node.js: v24.4.1
  • OS Name: macOS
  • System Model Name: MacBook Air, Space Gray
  • npm config:
; "user" config from /Users/hashtagchris/.npmrc

//registry.npmjs.org/:_authToken = (protected)

; node bin location = /Users/hashtagchris/.nvm/versions/node/v24.4.1/bin/node
; node version = v24.4.1
; npm local prefix = /private/tmp/dry-run-test
; npm version = 11.5.2
; cwd = /private/tmp/dry-run-test
; HOME = /Users/hashtagchris
; Run `npm config ls -l` to show all defaults.
% cat ~/.npmrc 
//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}

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 by reproducing the behavior with npm whoami or npm publish --dry-run and an .npmrc entry using ${NODE_AUTH_TOKEN} without setting the variable. Trace the credential check and environment-variable resolution, then verify that an unset or empty reference produces the ENEEDAUTH warning or error.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nodejs
Domain
authentication, cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.