[BUG] npm audit signatures shows an opaque JSON error when the registry returns a non-JSON attestations response

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

维护者通常 2 天内回复

@Fariiixm 已经在做这个了。

开始于 2026年11月27日。

  • #10369 来自 @Fariiixm —— 未关闭

评估

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

调研方向

Start by tracing the npm audit signatures command's attestations response handling and the fetch error path that produces the JSON parse message; the issue does not name specific files or tests. Check existing tests for invalid attestations responses and add coverage for a non-JSON response that identifies the package and registry problem. Done when the message is clear while verification still fails closed.

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

描述

Bug Needs Triage
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

When the attestations endpoint returns a non-JSON body (here a CDN-cached text/plain "OK"), npm audit signatures fails with:

npm error code FETCH_ERROR
npm error invalid json response body at https://registry.npmjs.org/-/npm/v1/attestations/@typescript-eslint%[email protected] reason: Unexpected token 'O', "OK
" is not valid JSON

The message does not say that the registry served a bad response or what the user can do. It took header-level debugging (comparing CDN edges) to find out it was a registry-side cache problem: https://github.com/orgs/community/discussions/214163

Expected Behavior

A clear error that names the package and says the registry returned an invalid attestations response, for example:

npm error Could not verify attestations for @typescript-eslint/[email protected]: the registry returned an invalid response (content-type text/plain). This is usually a temporary registry problem; check https://status.npmjs.org or retry later.

Verification should still fail closed. Only the message needs to change.

Steps To Reproduce

From a client routed to the Cloudflare MAD edge (which currently serves a cached text/plain "OK" for this attestations URL):

mkdir repro && cd repro && npm init -y
npm install @typescript-eslint/[email protected] --ignore-scripts
npm audit signatures

Result:

npm error code FETCH_ERROR
npm error invalid json response body at https://registry.npmjs.org/-/npm/v1/attestations/@typescript-eslint%[email protected] reason: Unexpected token 'O', "OK
" is not valid JSON
Environment
  • npm: 12.2.3 (also reproduced with 12.2.2)
  • Node.js: 24 (node:24-alpine)
  • OS Name: Alpine Linux (CI container)
  • System Model Name: CI runner (Docker executor)
  • npm config: defaults (reproduced in an empty project)
主要语言
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 摘要。