aquasecurity/trivy

fix(nodejs): silently skip package.json files with invalid names

已关闭

#10,607 创建于 2026年5月1日

 (0 条评论) (0 个反应) (0 位负责人)Go (371 个派生)batch import
good first issue

仓库指标

星标
 (35,000 个星标)
PR 合并指标
 (平均合并 5天 2小时) (30 天内合并 53 个 PR)

描述

Discussed in https://github.com/aquasecurity/trivy/discussions/10599

Summary

Trivy logs a DEBUG warning when parsing package.json files that have a slash in the name field (e.g. "name": "rxjs/ajax"). The scan is not affected, but the warning is misleading — these files should be silently skipped instead.

Background

Before Node.js introduced the exports field, libraries used subdirectory package.json files to guide bundlers to the correct CJS/ESM entry point. For example, node_modules/rxjs/ajax/package.json tells webpack/rollup which file to load when a user writes import from 'rxjs/ajax'.

These are not standalone packages:

  • They have no version field
  • They are never published to the npm registry independently
  • They exist solely as module resolution hints

According to the npm docs, name format rules only apply when publishing to the registry — so a slash in name is technically valid for an unpublished file.

Current behavior

Trivy skips these files but logs a DEBUG warning for each one:

DEBUG   Walk error  file_path="node_modules/.pnpm/rxjs@6.6.7/node_modules/rxjs/ajax/package.json" err="unable to parse ...: Name can only contain URL-friendly characters"
DEBUG   Walk error  file_path="node_modules/.pnpm/rxjs@6.6.7/node_modules/rxjs/fetch/package.json" err="unable to parse ...: Name can only contain URL-friendly characters"
DEBUG   Walk error  file_path="node_modules/.pnpm/rxjs@6.6.7/node_modules/rxjs/operators/package.json" err="unable to parse ...: Name can only contain URL-friendly characters"

The scan result is not affected, but the noise is misleading — these are not real errors.

Expected behavior

Silently skip such package.json files without logging an error — the same way Trivy already skips package.json files with no name field.

Fix

When IsValidName returns false, return without an error instead of propagating it as a walk error. Packages without an ID are already skipped by the caller, so the file will be silently ignored.

贡献者指南