[BUG] `npm config get` rejects paths with UUID directory names

未关闭
#10,338 1 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

@PCTEJA 已经在做这个了。

开始于 2026年11月24日。

  • #10340 来自 @PCTEJA —— 未关闭
  • #10350 来自 @Kizuno18 —— 未关闭

评估

难度
3/5
预计耗时
1-2 天
新手友好度
65/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
javascript, nodejs
领域
cli

调研方向

Run the reproduction script in a fresh shell to see the differing config get, config list, and config list --json outputs. Then read lib/commands/config.js, focusing on get(), listJson(), displayVar(), and the isPrivate() call, alongside the privacy tests in test/lib/commands/config.js. Trace the UUID matcher in the bundled @npmcli/redact; done means both list modes retain UUID-shaped paths and the protected-key and proxy-redaction tests still pass.

由索引模型根据 Issue 内容生成。

描述

Bug config:global Good First Issue Priority 3 Triage Requested
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
This is not just a request to bump a dependency for a CVE
  • This is not solely a request to bump a dependency for a CVE
Current Behavior

npm config get userconfig refuses an existing npmrc path when a parent directory name has the shape of a UUID. This prevents callers from discovering the configured file location. The same behavior affects other filesystem path settings.

The plain path is printed with exit status 0. For the UUID path, stdout is empty, the exit status is 1, and stderr contains:

npm error The userconfig option is protected, and cannot be retrieved in this way

With analogous UUID and plain paths, config get globalconfig, config get prefix and config get cache show the same distinction. For the UUID case, config list prints userconfig = "$W/***/.npmrc" and config list --json omits userconfig.

Expected Behavior

Each npm config get userconfig call writes its configured path to stdout and exits 0. Both forms of npm config list show that setting with its usable path. The empty npmrc files differ only in their parent directory names.

Steps To Reproduce

Run these commands in a fresh shell with the latest published npm on PATH. The commands create empty configuration files in a temporary directory and change only the environment of that shell.

W=$(mktemp -d "${TMPDIR:-/tmp}/npm-path-repro.XXXXXX")
W=$(cd "$W" && pwd -P)
cd "$W" || exit
uuid=550e8400-e29b-41d4-a716-446655440000
mkdir -p "$W/plain" "$W/$uuid"
touch "$W/plain/.npmrc" "$W/$uuid/.npmrc" "$W/global.npmrc"
export NPM_CONFIG_GLOBALCONFIG="$W/global.npmrc"
export NPM_CONFIG_CACHE="$W/cache"
export NPM_CONFIG_USERCONFIG="$W/plain/.npmrc"
npm config get userconfig
printf 'exit=%s\n' "$?"
export NPM_CONFIG_USERCONFIG="$W/$uuid/.npmrc"
npm config get userconfig
printf 'exit=%s\n' "$?"
npm config list
npm config list --json
Environment
  • macOS arm64, Node.js v26.13.1, isolated empty npmrc files.
  • Reproduced with the latest published npm (12.2.3), its preceding patch (12.2.2), the latest releases on the 11.x and 10.x lines (11.21.3 and 10.9.11), and a fresh clone of latest at 787f1520fa412e91a5792468f1c7f25b166867a6.
  • Release boundary reproduced on the 10.x line. The UUID path was returned in 10.7.0 and refused in 10.8.0.

Evidence

  • Expected source: npm config documentation, Get and List documents returning configuration values. The userconfig definition documents a path and explicitly supports an environment override.
  • Failure source: The local CLI reproduction above used the published package or cloned entry point. In lib/commands/config.js, get() and listJson() call isPrivate(). It classifies any value changed by @npmcli/redact as private. The bundled package's UUID matcher also matches the synthetic directory component in this example. Text listing redacts the same component in displayVar().
  • Evidence provenance: observed
  • Local verification: reproduced
  • Reproduction completeness: complete

Restoration check

With either directory name, npm config get userconfig exits 0 and returns the resolved path, and the text and JSON listings retain that path. The other named settings should also return their paths through config get. The protected-key and proxy-redaction tests in test/lib/commands/config.js should keep passing.

References

Triage assessment

  • Impact level: P2
  • Assessment status: supported
  • Impact basis: Scripts and users lose access to these config values whenever their resolved paths include a UUID-shaped segment. The config files and paths remain in place.
  • Workaround status: unverified
  • Workaround basis: A directory without a UUID produces readable output. Changing the path can be impractical when the caller is trying to discover an existing setting.
主要语言
JavaScript
星标
10.3k
派生
5k
平均合并
4 天 11 小时
30 天内合并 PR
26

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

npm/cli 的其他 Issue

查看 npm/cli 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。