Repository navigation
fix(secrets): read npm lock dependency maps as package names - #216
Merged
Merged
Conversation
In package-lock.json and npm-shrinkwrap.json, the keys of dependency maps are package names and their values version ranges, so js-tokens: ^4.0.0 was reported as a hardcoded credential. Values directly under such a map are now bound to no name; provider patterns, including credentials in resolved URLs, still apply, and other JSON files are judged as before. The module documentation now describes the configuration scan. Refs #210
Review of the dependency-map change: the bin map of a locked package maps command names to paths, so a command such as secretlint was still reported as a credential. Refs #210
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #210 (parts 2 and 3; the line positions of part 1 are left for a separate change, together with #207).
In
package-lock.json, the keys of a dependency map are package names and its values version ranges.config-secretsread them asname = valuepairs, so"js-tokens": "^4.0.0"was ahighhardcoded credential namedjs-tokens. On mitmproxy this gave F086 and F087 (web/package-lock.json).Change
All in
plugins/secrets.py:package-lock.jsonandnpm-shrinkwrap.json, a string value directly underdependencies,devDependencies,peerDependencies,optionalDependencies,requires(package names to version ranges) orbin(command names to paths, added after review:"secretlint": "bin/secretlint.js") is passed to the detector with no bound name. Only the credential-name rule depends on that name; provider patterns and the high-entropy check still judge the value.resolvedURLs (970 in mitmproxy's lock file), integrity hashes and any other field are judged as before, so a private-registry credential in aresolvedURL is still reported.dependenciesmaps package names to objects; the fields of those objects (version,resolved,requires, ...) keep their names.package.jsonincluded, and every TOML file are judged as before.poetry.lockandcomposer.lockhave the same shape but a.locksuffix, which the configuration scan does not read today, so they are not concerned.Validation
New
tests/test_lock_dependency_maps.py(no existing test changed): lockfile v3 and v1 maps of both file names, including abinmap, are not reported (the 4 cases failed before the change); a credential in aresolvedURL, a credential-named key outside a dependency map in a lock file, and adependenciesmap in another JSON file are still reported.Full suite: 1650 passed, 1 failed. The failure,
test_packaging::test_the_version_has_one_source_of_truth, comes from a stale local editable install (metadata 0.8.0 vs 0.21.0) and fails identically onmain.ruff check,ruff format --checkon the new file andmypypass;secrets.pyalready differs fromruff formatonmain, not on the changed lines.mitmproxy at
be75825, enterprise plugins atac35460,[email protected], no baseline, compared with the 87 results of the 2026-10-02 reference: exactly F086 and F087 disappear, nothing else changes. 87 → 85 results,high18 → 16. Plugin digests are identical.Regression snapshots: unchanged (read-only diff of every repository).
Open points
The issue scopes the change to npm lock files, so these are not extended here:
package.jsonhas the same dependency maps, and the false positive is more frequent there:"jsonwebtoken": "^9.0.2"independenciesis reported as a credential.pnpm-lock.yamlis read by the line-based scan and would show the same problem.