registry_license::npm_policy(root) read .npmrc / .yarnrc.yml only at the archive root. A monorepo project in a subfolder with its own .npmrc (@corp:registry=https://npm.corp.example.com/) had its private-scope package names looked up on registry.npmjs.org, and got public tarball URLs as distribution references.
What changed
New NpmPolicies (in registry_license.rs): the policy of a project directory comes from the .npmrc / .yarnrc.yml in it and in every parent up to the root. The nearest file names a scope's registry (as npm reads them); a non-public default registry (registry= / npmRegistryServer) anywhere on the way stops every lookup for that project. Each directory's files are read once per scan, each project's policy computed once; a location with .. falls back to the root's policy.
How entries map to projects: Syft's CycloneDX output carries syft:location:N:path per component (already used for .NET assemblies). syft.rs now keeps those paths for pkg:npm/ components, and SbomScanner::generate passes a purl -> lockfile paths map to enrich_registry_licenses. No new field is persisted on SbomEntry.
A name found in several projects is looked up only if every one of them takes it from the public registry. An entry without a known location uses the root's policy (old behaviour).
distribution.rs (fallback registry.npmjs.org/.../-/x.tgz URL when a lockfile names none) uses the same per-project policy, from the locations of Syft's JSON artifacts.
registry_license::tests::a_nested_npmrc_keeps_its_projects_names_inside: web/.npmrc routes @corp; only react and the root project's @corp/shared are asked, not web's @corp/pump-ui.
registry_license::tests::the_nearest_npmrc_names_a_scopes_registry: nearest-wins override, a .yarnrc.yml private default registry in a parent, a package in two projects, a .. path.
syft::tests::npm_packages_keep_the_lockfiles_they_were_read_from; distribution::tests::a_private_registry_gets_no_public_url now with a nested web/.npmrc.
cargo test -p compliance-agent --lib pipeline::sbom (100 passed), cargo fmt --all --check, clippy -D warnings for compliance-agent.
Not verified: a real Syft run on a monorepo (the location property format is the one Syft already gives for .NET assemblies, but I did not run Syft here).
Stage re-test
Upload an archive with a root package.json/package-lock.json and a subfolder web/ with its own package.json, package-lock.json and web/.npmrc containing @corp:registry=https://npm.corp.example.com/, with a @corp/... dependency in web/.
Scan it; on the Pakete tab the @corp/... package stays without a licence and without a public download URL, while public packages (e.g. react) get theirs.
In the agent log, no request to registry.npmjs.org/@corp... appears.
Move the .npmrc to the archive root and rescan: same result (root policy still applies to every project).
## What was wrong
`registry_license::npm_policy(root)` read `.npmrc` / `.yarnrc.yml` only at the archive root. A monorepo project in a subfolder with its own `.npmrc` (`@corp:registry=https://npm.corp.example.com/`) had its private-scope package names looked up on `registry.npmjs.org`, and got public tarball URLs as distribution references.
## What changed
- New `NpmPolicies` (in `registry_license.rs`): the policy of a project directory comes from the `.npmrc` / `.yarnrc.yml` in it and in every parent up to the root. The nearest file names a scope's registry (as npm reads them); a non-public default registry (`registry=` / `npmRegistryServer`) anywhere on the way stops every lookup for that project. Each directory's files are read once per scan, each project's policy computed once; a location with `..` falls back to the root's policy.
- How entries map to projects: Syft's CycloneDX output carries `syft:location:N:path` per component (already used for .NET assemblies). `syft.rs` now keeps those paths for `pkg:npm/` components, and `SbomScanner::generate` passes a purl -> lockfile paths map to `enrich_registry_licenses`. No new field is persisted on `SbomEntry`.
- A name found in several projects is looked up only if **every** one of them takes it from the public registry. An entry without a known location uses the root's policy (old behaviour).
- `distribution.rs` (fallback `registry.npmjs.org/.../-/x.tgz` URL when a lockfile names none) uses the same per-project policy, from the `locations` of Syft's JSON artifacts.
- Docs: `docs/guide/sbom.md`, `docs/reference/tools.md`.
## Tests
- `registry_license::tests::a_nested_npmrc_keeps_its_projects_names_inside`: `web/.npmrc` routes `@corp`; only `react` and the root project's `@corp/shared` are asked, not `web`'s `@corp/pump-ui`.
- `registry_license::tests::the_nearest_npmrc_names_a_scopes_registry`: nearest-wins override, a `.yarnrc.yml` private default registry in a parent, a package in two projects, a `..` path.
- `syft::tests::npm_packages_keep_the_lockfiles_they_were_read_from`; `distribution::tests::a_private_registry_gets_no_public_url` now with a nested `web/.npmrc`.
- `cargo test -p compliance-agent --lib pipeline::sbom` (100 passed), `cargo fmt --all --check`, clippy `-D warnings` for compliance-agent.
- Not verified: a real Syft run on a monorepo (the location property format is the one Syft already gives for .NET assemblies, but I did not run Syft here).
## Stage re-test
1. Upload an archive with a root `package.json`/`package-lock.json` and a subfolder `web/` with its own `package.json`, `package-lock.json` and `web/.npmrc` containing `@corp:registry=https://npm.corp.example.com/`, with a `@corp/...` dependency in `web/`.
2. Scan it; on the **Pakete** tab the `@corp/...` package stays without a licence and without a public download URL, while public packages (e.g. `react`) get theirs.
3. In the agent log, no request to `registry.npmjs.org/@corp...` appears.
4. Move the `.npmrc` to the archive root and rescan: same result (root policy still applies to every project).
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
The npm private-registry policy read .npmrc and .yarnrc.yml only at the
archive root, so a monorepo project in a subfolder with its own
`@corp:registry=...` had its private-scope names looked up on
registry.npmjs.org. The policy of an npm package now comes from the files
next to the lockfile Syft read it from and every parent directory up to
the root: the nearest file names a scope's registry, and a non-public
default registry anywhere on the way stops every lookup for that project.
A package found in several projects is looked up only if all of them
take it from the public registry. The same policy gates the fallback
tarball URL in the SBOM's distribution references.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
sharang
merged commit 0f22455db9 into main2026-10-08 21:45:45 +00:00
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
What was wrong
registry_license::npm_policy(root)read.npmrc/.yarnrc.ymlonly at the archive root. A monorepo project in a subfolder with its own.npmrc(@corp:registry=https://npm.corp.example.com/) had its private-scope package names looked up onregistry.npmjs.org, and got public tarball URLs as distribution references.What changed
NpmPolicies(inregistry_license.rs): the policy of a project directory comes from the.npmrc/.yarnrc.ymlin it and in every parent up to the root. The nearest file names a scope's registry (as npm reads them); a non-public default registry (registry=/npmRegistryServer) anywhere on the way stops every lookup for that project. Each directory's files are read once per scan, each project's policy computed once; a location with..falls back to the root's policy.syft:location:N:pathper component (already used for .NET assemblies).syft.rsnow keeps those paths forpkg:npm/components, andSbomScanner::generatepasses a purl -> lockfile paths map toenrich_registry_licenses. No new field is persisted onSbomEntry.distribution.rs(fallbackregistry.npmjs.org/.../-/x.tgzURL when a lockfile names none) uses the same per-project policy, from thelocationsof Syft's JSON artifacts.docs/guide/sbom.md,docs/reference/tools.md.Tests
registry_license::tests::a_nested_npmrc_keeps_its_projects_names_inside:web/.npmrcroutes@corp; onlyreactand the root project's@corp/sharedare asked, notweb's@corp/pump-ui.registry_license::tests::the_nearest_npmrc_names_a_scopes_registry: nearest-wins override, a.yarnrc.ymlprivate default registry in a parent, a package in two projects, a..path.syft::tests::npm_packages_keep_the_lockfiles_they_were_read_from;distribution::tests::a_private_registry_gets_no_public_urlnow with a nestedweb/.npmrc.cargo test -p compliance-agent --lib pipeline::sbom(100 passed),cargo fmt --all --check, clippy-D warningsfor compliance-agent.Stage re-test
package.json/package-lock.jsonand a subfolderweb/with its ownpackage.json,package-lock.jsonandweb/.npmrccontaining@corp:registry=https://npm.corp.example.com/, with a@corp/...dependency inweb/.@corp/...package stays without a licence and without a public download URL, while public packages (e.g.react) get theirs.registry.npmjs.org/@corp...appears..npmrcto the archive root and rescan: same result (root policy still applies to every project).🤖 Generated with Claude Code
https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p