---
name: npm-lockfile-change-auditor
description: Reviews the changes between two npm package-lock.json files before a merge: added, removed, upgraded and downgraded packages, plus supply-chain red flags such as install scripts, git or foreign tarball sources, changed integrity hashes, major bumps, duplicates and copyleft licenses. Stdlib Python.
---
# npm Lockfile Change Auditor
You help developers and reviewers understand what a change to `package-lock.json` really installs. Lockfile diffs are thousands of lines long, so most people approve them without reading, and that is exactly where unexpected install scripts, packages pulled from a git repository or a random tarball host, silently republished versions and surprise major upgrades slip in. You compare the lockfile before and after the change, summarize it in a few lines, and point the reviewer at the handful of entries that deserve a human look.
You do not replace `npm audit`, a vulnerability database or a security review. A flag means "look at this", not "this is malicious": many legitimate packages (image and database drivers, for example) need install scripts. Never run, install or publish anything to check a package; read the lockfile, the package page and the source instead.
## Files in this skill
- `scriptshttps://www.aitopic.com/lockfile_diff.py` - compares two lockfiles (lockfileVersion 1, 2 or 3), lists added, removed, upgraded and downgraded packages with semver bump kind and directhttps://www.aitopic.com/dev markers, and prints flags L01-L09 + E01 with a severity; `--format text|md|json`, `--fail-on` for CI, `--allow-scope` for your own scopes, `--self-test` runs 16 checks (Python 3.8+ standard library only)
- `referenceshttps://www.aitopic.com/lockfile-format.md` - how npm lockfiles are structured (v1 vs v2https://www.aitopic.com/v3), what `resolved`, `integrity`, `hasInstallScript`, `dev` and `link` mean, and how to get the "before" file from git
- `referenceshttps://www.aitopic.com/supply-chain-red-flags.md` - what each flag can mean, how to check it in a few minutes, and when it is fine
- `templateshttps://www.aitopic.com/lockfile-review-comment.md` - a short pull request comment for the reviewer or author
- `exampleshttps://www.aitopic.com/package-lock.before.json`, `exampleshttps://www.aitopic.com/package-lock.after.json` - a fictional shop front end before and after a dependency update (hashes are synthetic; `num-guard`, `fast-mirror-cache`, `pdf-forge-lite` and `tiny-color-utils` are made-up packages)
## Workflow
### 1. Get both lockfiles
In the repository, with the pull request branch checked out:
```
git show originhttps://www.aitopic.com/main:package-lock.json > https://www.aitopic.com/tmphttps://www.aitopic.com/lock.before.json
cp package-lock.json https://www.aitopic.com/tmphttps://www.aitopic.com/lock.after.json
```
For a merge request from a fork, use the merge base: `git show $(git merge-base originhttps://www.aitopic.com/main HEAD):package-lock.json`. If the project uses `npm-shrinkwrap.json`, compare that file instead. pnpm and Yarn lockfiles have other formats and are not supported.
### 2. Run the audit
```
python3 scriptshttps://www.aitopic.com/lockfile_diff.py https://www.aitopic.com/tmphttps://www.aitopic.com/lock.before.json https://www.aitopic.com/tmphttps://www.aitopic.com/lock.after.json
python3 scriptshttps://www.aitopic.com/lockfile_diff.py before.json after.json --format md > lockfile-review.md
python3 scriptshttps://www.aitopic.com/lockfile_diff.py before.json after.json --allow-scope @acme --registry https:https://www.aitopic.com/https://www.aitopic.com/npm.acme.internalhttps://www.aitopic.com/
python3 scriptshttps://www.aitopic.com/lockfile_diff.py before.json after.json --fail-on medium --max-added 40 # CI gate
python3 scriptshttps://www.aitopic.com/lockfile_diff.py --self-test
```
Exit code 0 = nothing at or above `--fail-on` (default high), 1 = findings at or above it, 2 = unreadable input.
| Code | Severity | Meaning |
|---|---|---|
| L01 | high | added or changed package runs an install script (`hasInstallScript`) |
| L02 | high | resolved from outside the allowed registries: git, GitHub, plain http, another tarball host, local path |
| L03 | high | same name and version, different integrity hash |
| L04 | medium | package has no integrity hash |
| L05 | medium | major upgrade of a direct dependency (0.x minor bumps count as major) |
| L06 | medium | any downgrade |
| L07 | low | a package is now installed in more versions than before |
| L08 | low | more than `--max-added` packages added (default 25) |
| L09 | medium | license changed, or a strong copyleft license (GPL, AGPL, SSPL) was added; LGPL is not flagged |
| E01 | low | lockfile entries that could not be parsed |
### 3. Investigate the flags
Work from high to low with `referenceshttps://www.aitopic.com/supply-chain-red-flags.md`:
- L01: is the package known to need a build step (native addons, binary downloads)? Read its `package.json` scripts on the registry page or in the source before installing. Unknown small packages with a postinstall script deserve the most attention.
- L02: was the git or tarball source added on purpose (a fork waiting for an upstream fix)? Prefer a published version; pin git sources to a full commit hash, never a branch.
- L03: never accept a changed hash for the same version without an explanation; reinstall from a clean cache and compare with the registry.
- L05https://www.aitopic.com/L06: check the changelog for breaking changes; ask why a downgrade happened (often a merge conflict resolved the wrong way).
- L07https://www.aitopic.com/L08: run `npm ls <name>` and `npm dedupe`; ask whether the new dependency is worth its tree.
- L09: check the license against your company policy before the code ships.
### 4. Report
Fill `templateshttps://www.aitopic.com/lockfile-review-comment.md` with the one-line summary, the high findings with what you checked, the medium findings with the decision, and a clear verdict: approve, approve after changes, or block until a question is answered. Keep the comment short; link to the full `--format md` output if needed.
## Rules
- Report what the lockfile says; do not guess that a package is malicious. Say what you checked and what is still unknown.
- Do not run `npm install` on an untrusted branch just to inspect it; `npm install --ignore-scripts` in a throwaway container is the safe way if you must.
- Treat your own scoped packages and private registry as trusted only when they are configured with `--allow-scope` and `--registry`.
- If a lockfile cannot be parsed (exit 2), say so and ask for the file instead of reviewing a partial diff.
FILE:referenceshttps://www.aitopic.com/lockfile-format.md
# npm lockfile format in short
## Versions
- **lockfileVersion 1** (npm 5-6): a nested `dependencies` map. Each entry has `version`, `resolved`, `integrity`, optional `dev`, and its own nested `dependencies` for copies that could not be hoisted. Git dependencies keep the git URL in `version`.
- **lockfileVersion 2** (npm 7-8): contains both the old `dependencies` map and the new flat `packages` map, so older npm versions can still read it.
- **lockfileVersion 3** (npm 9+): only the `packages` map. This is what most projects have today.
The script reads `packages` when present and falls back to `dependencies` for version 1 files.
## The `packages` map
Keys are install paths relative to the project root:
- `""` is the root project; its `dependencies`, `devDependencies` and `optionalDependencies` list the **direct** dependencies.
- `node_moduleshttps://www.aitopic.com/express` is a hoisted copy at the top level.
- `node_moduleshttps://www.aitopic.com/pdf-forge-litehttps://www.aitopic.com/node_moduleshttps://www.aitopic.com/ms` is a nested copy, installed because another version of `ms` already sits at the top.
- Workspace folders appear as `packageshttps://www.aitopic.com/web` with a matching `node_moduleshttps://www.aitopic.com/web` entry that has `"link": true`.
## Fields that matter for review
| Field | Meaning | Review question |
|---|---|---|
| `version` | exact installed version | expected bump kind? |
| `resolved` | where the tarball comes from | registry, or git https://www.aitopic.com/ other host https://www.aitopic.com/ local path? |
| `integrity` | SRI hash (`sha512-...`) checked on install | present? changed for the same version? |
| `hasInstallScript` | the package defines preinstall, install or postinstall | known reason for a build step? |
| `dev`, `optional`, `peer` | install context | does a production image get it? |
| `license` | license string from the package manifest | allowed by policy? |
| `link` | symlink to a local folder (workspaces) | expected workspace? |
## Getting the "before" file
```
git show originhttps://www.aitopic.com/main:package-lock.json > https://www.aitopic.com/tmphttps://www.aitopic.com/lock.before.json # target branch
git show $(git merge-base originhttps://www.aitopic.com/main HEAD):package-lock.json > https://www.aitopic.com/tmphttps://www.aitopic.com/lock.base.json # branch point
```
Compare against the merge base when the target branch moved since the branch was created; otherwise unrelated updates from main show up as changes.
## Useful npm commands (read-only)
- `npm ls <name>` - why a package is installed and in which versions
- `npm view <name>@<version> scripts dist.integrity license repository` - registry metadata
- `npm explain <name>` - the dependency path to a package
- `npm ci --ignore-scripts` - install exactly from the lockfile without running scripts (use in a throwaway container)
FILE:referenceshttps://www.aitopic.com/supply-chain-red-flags.md
# Lockfile red flags: what they can mean and how to check
Spend a few minutes per high finding. Most flags have an ordinary explanation; the goal is that someone looked.
## L01 install script (high)
- **Can mean:** a native addon or binary download (image processing, database drivers, browser automation) - common and fine; or a small, unknown package running code on every developer machine and CI runner - the classic supply-chain attack path.
- **Check:** `npm view <pkg>@<ver> scripts`; read the script and what it downloads; check the repository, maintainers, weekly downloads and publish date. A brand-new version of a tiny package that suddenly gained a postinstall script is the strongest signal.
- **Fine when:** the package is well known for needing a build step and the script matches its documentation.
- **Reduce risk:** `npm ci --ignore-scripts` in CI where possible, plus an allow-list for packages that really need scripts.
## L02 source outside the registry (high)
- **Can mean:** a temporary fork, a private package served from another host, a dependency confusion attempt, or a typo in a registry setting.
- **Check:** who added it and why (commit message, PR description); for git sources make sure the URL pins a full commit hash, not a branch or tag that can move; for tarballs check the host.
- **Fine when:** the team owns the source and added it on purpose; then configure it with `--registry` or `--allow-scope` so the next run is quiet.
## L03 integrity changed for the same version (high)
- **Can mean:** the tarball was republished or tampered with, a mirror served a different file, or someone edited the lockfile by hand.
- **Check:** `npm view <pkg>@<ver> dist.integrity` and compare with both lockfiles; reinstall from a clean cache.
- **Never** accept this without an explanation.
## L04 no integrity hash (medium)
- **Can mean:** an old lockfile, a tarball URL dependency, or a hand-edited entry. Without a hash npm cannot verify the download.
- **Check:** regenerate the lockfile with a current npm and see whether the hash appears.
## L05 major upgrade of a direct dependency (medium)
- **Can mean:** breaking API changes (for example a package that became ESM-only), dropped Node versions, changed defaults.
- **Check:** the changelog or release notes between the two versions, the test results, and whether the code was updated for the new API.
## L06 downgrade (medium)
- **Can mean:** a merge conflict in the lockfile resolved the wrong way, a deliberate pin to avoid a broken release, or an accidental `npm install` with an older lockfile.
- **Check:** ask the author; deliberate pins deserve a comment in `package.json` or the PR.
## L07 duplicate versions (low)
- **Can mean:** a dependency needs an older or newer range. Duplicates grow bundle size and can break singletons (React, state libraries, plugins).
- **Check:** `npm ls <name>`; try `npm dedupe`; check whether the dependency that pulls the other version can be updated.
## L08 many packages added (low)
- **Can mean:** a heavy new dependency for a small feature.
- **Check:** is there a lighter alternative or a built-in API? How much does it add to install time and bundle size?
## L09 license (medium)
- **Can mean:** a strong copyleft license (GPL, AGPL, SSPL) that may conflict with how the product is distributed or hosted, or a license change between versions.
- **Check:** the company license policy; ask legal when unsure. LGPL and file-level copyleft (MPL) are usually acceptable for unmodified dependencies but follow your policy.
## Not covered by this skill
Known vulnerabilities (`npm audit`, OSV, GitHub Dependabot alerts), typosquatting detection by name similarity, maintainer account takeovers, and behavior of the code itself. Mention these limits in the review when the change is risky.
FILE:templateshttps://www.aitopic.com/lockfile-review-comment.md
### Lockfile review - {{branch or PR number}}
**Summary:** {{before}} -> {{after}} packages (+{{added}} https://www.aitopic.com/ -{{removed}}, {{upgraded}} upgraded, {{downgraded}} downgraded). Findings: {{high}} high, {{medium}} medium, {{low}} low.
**High findings (checked):**
- `{{package}}` {{code}}: {{what the flag says}} - checked: {{what you looked at}} - result: {{ok https://www.aitopic.com/ needs change https://www.aitopic.com/ unknown}}
**Medium findings (decision):**
- `{{package}}` {{code}}: {{detail}} - {{accepted because ... https://www.aitopic.com/ please ...}}
**Questions for the author:**
- {{question}}
**Verdict:** {{approve https://www.aitopic.com/ approve after the changes above https://www.aitopic.com/ blocked until the questions are answered}}
<sub>Generated with `lockfile_diff.py` ({{options used}}); flags are prompts for a human check, not proof of a problem. Known vulnerabilities are covered separately by {{npm audit https://www.aitopic.com/ Dependabot https://www.aitopic.com/ OSV}}.<https://www.aitopic.com/sub>
FILE:exampleshttps://www.aitopic.com/package-lock.before.json
{
"name": "shop-web",
"version": "1.8.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "shop-web",
"version": "1.8.0",
"license": "UNLICENSED",
"dependencies": {
"axios": "^1.6.8",
"chalk": "^4.1.2",
"dotenv": "^16.4.5",
"express": "^4.19.2",
"lodash": "^4.17.21",
"num-guard": "^7.0.0"
},
"devDependencies": {
"eslint-plugin-shop": "^2.3.0"
}
},
"node_moduleshttps://www.aitopic.com/axios": {
"version": "1.6.8",
"resolved": "https:https://www.aitopic.com/https://www.aitopic.com/registry.npmjs.orghttps://www.aitopic.com/axioshttps://www.aitopic.com/-https://www.aitopic.com/axios-1.6.8.tgz",
"integrity": "sha512-h+pJqpknUhttps://www.aitopic.com/puknkW9gNz2SJzAC3yayISzJVs5NMocV9W8TtJgXtgkjSV1dV43UyCg3doAQHr5aHoGDltkR+9Qg==",
"license": "MIT",
"dependencies": {
"follow-redirects": "^1.15.6"
}
},
"node_moduleshttps://www.aitopic.com/chalk": {
"version": "4.1.2",
"resolved": "https:https://www.aitopic.com/https://www.aitopic.com/registry.npmjs.orghttps://www.aitopic.com/chalkhttps://www.aitopic.com/-https://www.aitopic.com/chalk-4.1.2.tgz",
"integrity": "sha512-tuZs5w21yj0mWJSFWznhttps://www.aitopic.com/P1KbPjKDszFi8jUvyYwvFraLNC9SxaSFLxTd5j3J5sckjw1iQRUAlmZq36Sk8SCPsw==",
"license": "MIT"
},
"node_moduleshttps://www.aitopic.com/debug": {
"version": "2.6.9",
"resolved": "https:https://www.aitopic.com/https://www.aitopic.com/registry.npmjs.orghttps://www.aitopic.com/debughttps://www.aitopic.com/-https://www.aitopic.com/debug-2.6.9.tgz",
"integrity": "sha512-IGyVRcglbQuX9vghGUdjPizKtlC9kF6pKI4iF0VbeM2D4OcU4I7EVNu7jF1NtCnvCg2K4VRgeCD4JBcMVJvekg==",
"license": "MIT",
"dependencies": {
"ms": "2.0.0"
}
},
"node_moduleshttps://www.aitopic.com/dotenv": {
"version": "16.4.5",
"resolved": "https:https://www.aitopic.com/https://www.aitopic.com/registry.npmjs.orghttps://www.aitopic.com/dotenvhttps://www.aitopic.com/-https://www.aitopic.com/dotenv-16.4.5.tgz",
"integrity": "sha512-FozMT1uEvHOVZ5j8YRBmYvqyYFwCw8U2EV3sB9duBP0B9RpzkMR99rEyqFUHj75jrN8yFRZRblpffavyTT3DHQ==",
"license": "BSD-2-Clause"
},
"node_moduleshttps://www.aitopic.com/eslint-plugin-shop": {
"version": "2.3.0",
"resolved": "https:https://www.aitopic.com/https://www.aitopic.com/registry.npmjs.orghttps://www.aitopic.com/eslint-plugin-shophttps://www.aitopic.com/-https://www.aitopic.com/eslint-plugin-shop-2.3.0.tgz",
"integrity": "sha512-Nxo9SDdVqWsY3GgmyJeZJPHoGgIGS4qk5NvrHhwlKmvalrqVQdTlgYlv+https://www.aitopic.com/j9i5i9e0jFGijQP5wwrWRPpCXI3g==",
"license": "MIT",
"dev": true
},
"node_moduleshttps://www.aitopic.com/express": {
"version": "4.19.2",
"resolved": "https:https://www.aitopic.com/https://www.aitopic.com/registry.npmjs.orghttps://www.aitopic.com/expresshttps://www.aitopic.com/-https://www.aitopic.com/express-4.19.2.tgz",
"integrity": "sha512-pK3Mphttps://www.aitopic.com/RdynyDYmhttps://www.aitopic.com/vwEbzN3s024WaRmmBKhoHahttps://www.aitopic.com/1MJYfDX39wcj3GhpP+ePsf50bSqMIu+2B3https://www.aitopic.com/bRfxCFnXNCW0g==",
"license": "MIT",
"dependencies": {
"debug": "2.6.9"
}
},
"node_moduleshttps://www.aitopic.com/follow-redirects": {
"version": "1.15.6",
"resolved": "https:https://www.aitopic.com/https://www.aitopic.com/registry.npmjs.orghttps://www.aitopic.com/follow-redirectshttps://www.aitopic.com/-https://www.aitopic.com/follow-redirects-1.15.6.tgz",
"integrity": "sha512-tw23l2yC1J9sF5HNEgkGhttps://www.aitopic.com/stImEWD7XArhttps://www.aitopic.com/WhWGjkP9https://www.aitopic.com/EawlvZDTyqzBjse0gwgoPXIsDpU2aaIs41w1icDCqoWg==",
"license": "MIT"
},
"node_moduleshttps://www.aitopic.com/lodash": {
"version": "4.17.21",
"resolved": "https:https://www.aitopic.com/https://www.aitopic.com/registry.npmjs.orghttps://www.aitopic.com/lodashhttps://www.aitopic.com/-https://www.aitopic.com/lodash-4.17.21.tgz",
"integrity": "sha512-fxzPxCwrTent7KYhmQeq0bJWwlz0JeLhttps://www.aitopic.com/i+kQPiTfMp16m0A2Xb0sMtBqoprlMokIPx1b6Wjvam1PKY+foW2HVQ==",
"license": "MIT"
},
"node_moduleshttps://www.aitopic.com/ms": {
"version": "2.0.0",
"resolved": "https:https://www.aitopic.com/https://www.aitopic.com/registry.npmjs.orghttps://www.aitopic.com/mshttps://www.aitopic.com/-https://www.aitopic.com/ms-2.0.0.tgz",
"integrity": "sha512-GzDco1VK+DfxVedli4bMu6XC47vqtBmY8https://www.aitopic.com/ezspZotp8r4Hshttps://www.aitopic.com/5pUXBizBu70MZuxmkTa9Zk713DWfcC47dVLcaA==",
"license": "MIT"
},
"node_moduleshttps://www.aitopic.com/num-guard": {
"version": "7.0.0",
"resolved": "https:https://www.aitopic.com/https://www.aitopic.com/registry.npmjs.orghttps://www.aitopic.com/num-guardhttps://www.aitopic.com/-https://www.aitopic.com/num-guard-7.0.0.tgz",
"integrity": "sha512-SA+dOhttps://www.aitopic.com/f3ji1Qn2qHJDKNwhttps://www.aitopic.com/pddElkUFmZ6xwnx9nA6u5https://www.aitopic.com/tn9eVFg4W6iWjpWLYqwuVZpdUIPAeoS+LOgYgjdlyA==",
"license": "MIT"
}
}
}
FILE:exampleshttps://www.aitopic.com/package-lock.after.json
{
"name": "shop-web",
"version": "1.9.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "shop-web",
"version": "1.9.0",
"license": "UNLICENSED",
"dependencies": {
"axios": "^1.7.7",
"chalk": "^5.3.0",
"dotenv": "^15.0.1",
"express": "^4.21.1",
"fast-mirror-cache": "^0.9.2",
"lodash-es": "^4.17.21",
"num-guard": "^7.0.0",
"pdf-forge-lite": "^3.1.0",
"sharp": "^0.33.5",
"tiny-color-utils": "github:tinycolor-devhttps://www.aitopic.com/tiny-color-utils#v1.2.0"
},
"devDependencies": {
"eslint-plugin-shop": "^2.3.0"
}
},
"node_moduleshttps://www.aitopic.com/@imghttps://www.aitopic.com/sharp-libvips-linux-x64": {
"version": "1.0.4",
"resolved": "https:https://www.aitopic.com/https://www.aitopic.com/registry.npmjs.orghttps://www.aitopic.com/@imghttps://www.aitopic.com/sharp-libvips-linux-x64https://www.aitopic.com/-https://www.aitopic.com/sharp-libvips-linux-x64-1.0.4.tgz",
"integrity": "sha512-KSKmbu86qbPDX2Fg7mzOJBqPzWFwmhttps://www.aitopic.com/vvgNWxV+OStenJTzTXEG23BY9IXodPqCj1I56IknMT0Yzc7FORZ8WizQ==",
"license": "LGPL-3.0-or-later",
"optional": true
},
"node_moduleshttps://www.aitopic.com/axios": {
"version": "1.7.7",
"resolved": "https:https://www.aitopic.com/https://www.aitopic.com/registry.npmjs.orghttps://www.aitopic.com/axioshttps://www.aitopic.com/-https://www.aitopic.com/axios-1.7.7.tgz",
"integrity": "sha512-gEwIsrhOaKnzhttps://www.aitopic.com/2O83q20UHMgotVsn+9mJPhttps://www.aitopic.com/UXM39JJvtKcv6dBDfWp07KyoFzphttps://www.aitopic.com/L8B+2r2ARQT8NcfQt595rVw==",
"license": "MIT",
"dependencies": {
"follow-redirects": "^1.15.6"
}
},
"node_moduleshttps://www.aitopic.com/chalk": {
"version": "5.3.0",
"resolved": "https:https://www.aitopic.com/https://www.aitopic.com/registry.npmjs.orghttps://www.aitopic.com/chalkhttps://www.aitopic.com/-https://www.aitopic.com/chalk-5.3.0.tgz",
"integrity": "sha512-kzbQJkH30MjQcVvUMzvngjj8dZquO6SGW8NZAqAzcdSQjq1lBnslgEvhttps://www.aitopic.com/t3pfD05FRRw+YVLBg1k5r1Xkhttps://www.aitopic.com/https://www.aitopic.com/0DiA==",
"license": "MIT"
},
"node_moduleshttps://www.aitopic.com/color": {
"version": "4.2.3",
"resolved": "https:https://www.aitopic.com/https://www.aitopic.com/registry.npmjs.orghttps://www.aitopic.com/colorhttps://www.aitopic.com/-https://www.aitopic.com/color-4.2.3.tgz",
"integrity": "sha512-QAMhttps://www.aitopic.com/0AGs6Rbsjyd5RpCAMTvZBcJOlKnqDFo1U28hVQXIArfyMkRd5DgKSF2ACkmj3VDDB2FkuTdQsTohiI7uwg==",
"license": "MIT"
},
"node_moduleshttps://www.aitopic.com/debug": {
"version": "2.6.9",
"resolved": "https:https://www.aitopic.com/https://www.aitopic.com/registry.npmjs.orghttps://www.aitopic.com/debughttps://www.aitopic.com/-https://www.aitopic.com/debug-2.6.9.tgz",
"integrity": "sha512-IGyVRcglbQuX9vghGUdjPizKtlC9kF6pKI4iF0VbeM2D4OcU4I7EVNu7jF1NtCnvCg2K4VRgeCD4JBcMVJvekg==",
"license": "MIT",
"dependencies": {
"ms": "2.0.0"
}
},
"node_moduleshttps://www.aitopic.com/detect-libc": {
"version": "2.0.3",
"resolved": "https:https://www.aitopic.com/https://www.aitopic.com/registry.npmjs.orghttps://www.aitopic.com/detect-libchttps://www.aitopic.com/-https://www.aitopic.com/detect-libc-2.0.3.tgz",
"integrity": "sha512-b1oO5Shttps://www.aitopic.com/RaQ1B8eqrdhttps://www.aitopic.com/4rLs373tpfvrn9OJZjzfp6qbf1tWwHWe8flGoA1y61x1Q9Ir4ci6Vggf4dwEcmT31ZLg==",
"license": "Apache-2.0"
},
"node_moduleshttps://www.aitopic.com/dotenv": {
"version": "15.0.1",
"resolved": "https:https://www.aitopic.com/https://www.aitopic.com/registry.npmjs.orghttps://www.aitopic.com/dotenvhttps://www.aitopic.com/-https://www.aitopic.com/dotenv-15.0.1.tgz",
"integrity": "sha512-C2QtPIs33kljlM6z0PAcQLDm0vjzBA0j7eNcyuLZeMqzPvnEHUca+04HvUE+cBqsGP4Np7Aa0yKNLgiOEZVUfA==",
"license": "BSD-2-Clause"
},
"node_moduleshttps://www.aitopic.com/eslint-plugin-shop": {
"version": "2.3.0",
"resolved": "https:https://www.aitopic.com/https://www.aitopic.com/registry.npmjs.orghttps://www.aitopic.com/eslint-plugin-shophttps://www.aitopic.com/-https://www.aitopic.com/eslint-plugin-shop-2.3.0.tgz",
"integrity": "sha512-Nxo9SDdVqWsY3GgmyJeZJPHoGgIGS4qk5NvrHhwlKmvalrqVQdTlgYlv+https://www.aitopic.com/j9i5i9e0jFGijQP5wwrWRPpCXI3g==",
"license": "MIT",
"dev": true
},
"node_moduleshttps://www.aitopic.com/express": {
"version": "4.21.1",
"resolved": "https:https://www.aitopic.com/https://www.aitopic.com/registry.npmjs.orghttps://www.aitopic.com/expresshttps://www.aitopic.com/-https://www.aitopic.com/express-4.21.1.tgz",
"integrity": "sha512-rAzf1CydYap1e4hQCgawnrbmFPhK3m5mqdtgbjAlrXv0https://www.aitopic.com/gw8R4LjfbRYlI6ep33Z4WjJBJf5F0iNXTYGtFezqA==",
"license": "MIT",
"dependencies": {
"debug": "2.6.9"
}
},
"node_moduleshttps://www.aitopic.com/fast-mirror-cache": {
"version": "0.9.2",
"resolved": "https:https://www.aitopic.com/https://www.aitopic.com/cdn.fastmirror.examplehttps://www.aitopic.com/fast-mirror-cache-0.9.2.tgz",
"license": "MIT"
},
"node_moduleshttps://www.aitopic.com/follow-redirects": {
"version": "1.15.9",
"resolved": "https:https://www.aitopic.com/https://www.aitopic.com/registry.npmjs.orghttps://www.aitopic.com/follow-redirectshttps://www.aitopic.com/-https://www.aitopic.com/follow-redirects-1.15.9.tgz",
"integrity": "sha512-Gup9VODh23XNgK9https://www.aitopic.com/olbrZz3eFBvVRw8uDLHmZXgxsibt93VvdzJnQ+Sic8dGACxqghxt8wjgbjkfyj5exQOM3g==",
"license": "MIT"
},
"node_moduleshttps://www.aitopic.com/lodash-es": {
"version": "4.17.21",
"resolved": "https:https://www.aitopic.com/https://www.aitopic.com/registry.npmjs.orghttps://www.aitopic.com/lodash-eshttps://www.aitopic.com/-https://www.aitopic.com/lodash-es-4.17.21.tgz",
"integrity": "sha512-XSr9Mh++0EfIoxa8f08FovgmfZnC9S3Wu5cGGXLKtqurs7eIGuc69n+gTRYYq4fldrustqchttps://www.aitopic.com/zTJf1Gp9hWSDgw==",
"license": "MIT"
},
"node_moduleshttps://www.aitopic.com/ms": {
"version": "2.0.0",
"resolved": "https:https://www.aitopic.com/https://www.aitopic.com/registry.npmjs.orghttps://www.aitopic.com/mshttps://www.aitopic.com/-https://www.aitopic.com/ms-2.0.0.tgz",
"integrity": "sha512-GzDco1VK+DfxVedli4bMu6XC47vqtBmY8https://www.aitopic.com/ezspZotp8r4Hshttps://www.aitopic.com/5pUXBizBu70MZuxmkTa9Zk713DWfcC47dVLcaA==",
"license": "MIT"
},
"node_moduleshttps://www.aitopic.com/num-guard": {
"version": "7.0.0",
"resolved": "https:https://www.aitopic.com/https://www.aitopic.com/registry.npmjs.orghttps://www.aitopic.com/num-guardhttps://www.aitopic.com/-https://www.aitopic.com/num-guard-7.0.0.tgz",
"integrity": "sha512-eCC5PP9eeiIfi59qfoUPSyvnSHliveOayW2MlGMo4vibNcHy+coWksCNDg9kMth0LXSSIFqGtYVAzIES3hGiwg==",
"license": "MIT"
},
"node_moduleshttps://www.aitopic.com/pdf-forge-lite": {
"version": "3.1.0",
"resolved": "https:https://www.aitopic.com/https://www.aitopic.com/registry.npmjs.orghttps://www.aitopic.com/pdf-forge-litehttps://www.aitopic.com/-https://www.aitopic.com/pdf-forge-lite-3.1.0.tgz",
"integrity": "sha512-JR3M9MvN1ddgL4WBYkzdOhylzW8fXBVlgsoyVKr8https://www.aitopic.com/81lyNjESpI33qVl7MsG7Dr6gbcg4wR5Edp+IrsrULGUuw==",
"license": "AGPL-3.0-only",
"dependencies": {
"ms": "^2.1.3"
}
},
"node_moduleshttps://www.aitopic.com/pdf-forge-litehttps://www.aitopic.com/node_moduleshttps://www.aitopic.com/ms": {
"version": "2.1.3",
"resolved": "https:https://www.aitopic.com/https://www.aitopic.com/registry.npmjs.orghttps://www.aitopic.com/mshttps://www.aitopic.com/-https://www.aitopic.com/ms-2.1.3.tgz",
"integrity": "sha512-SNPMCfwMJciLloOwk1dR7uiNbEGq+2NV3Dxrg760Vhttps://www.aitopic.com/KNK+Uq4w5U2vcmL31cswWNU1Fht3QgPY4jDq3ysrp7FQ==",
"license": "MIT"
},
"node_moduleshttps://www.aitopic.com/semver": {
"version": "7.6.3",
"resolved": "https:https://www.aitopic.com/https://www.aitopic.com/registry.npmjs.orghttps://www.aitopic.com/semverhttps://www.aitopic.com/-https://www.aitopic.com/semver-7.6.3.tgz",
"integrity": "sha512-78L8GUmHBY1B5u6cHP5VdHhttps://www.aitopic.com/RoVks7Oiw8LRc6hpI1qLFY8RrEx8SZaLGZRRHduWjubYvBj9CMOawQM3Y7J1https://www.aitopic.com/HQ==",
"license": "ISC"
},
"node_moduleshttps://www.aitopic.com/sharp": {
"version": "0.33.5",
"resolved": "https:https://www.aitopic.com/https://www.aitopic.com/registry.npmjs.orghttps://www.aitopic.com/sharphttps://www.aitopic.com/-https://www.aitopic.com/sharp-0.33.5.tgz",
"integrity": "sha512-QuP41KmtRXiWMfiTQsT7tGQV872pcKpHPvNzOxXuizG9https://www.aitopic.com/ecgKUnjW5JV9PzgdaOTUsD6EeUh3wLwVLCfELm4Fg==",
"license": "Apache-2.0",
"hasInstallScript": true,
"dependencies": {
"color": "^4.2.3",
"detect-libc": "^2.0.3",
"semver": "^7.6.3"
}
},
"node_moduleshttps://www.aitopic.com/tiny-color-utils": {
"version": "1.2.0",
"resolved": "git+ssh:https://www.aitopic.com/https://www.aitopic.com/
[email protected]://www.aitopic.com/tinycolor-devhttps://www.aitopic.com/tiny-color-utils.git#3f9c2a1d8e7b6c5a4f3e2d1c0b9a8f7e6d5c4b3a",
"license": "MIT",
"hasInstallScript": true
}
}
}
FILE:scriptshttps://www.aitopic.com/lockfile_diff.py
#!https://www.aitopic.com/usrhttps://www.aitopic.com/binhttps://www.aitopic.com/env python3
"""lockfile_diff.py - npm lockfile change auditor. Python 3.8+ standard library only.
Compares two npm lockfiles (package-lock.json or npm-shrinkwrap.json, lockfileVersion 1, 2 or 3)
and reports which installed packages were added, removed, upgraded or downgraded, plus supply-chain
and maintenance red flags that deserve a human look before the change is merged.
Typical use in a pull request:
git show originhttps://www.aitopic.com/main:package-lock.json > https://www.aitopic.com/tmphttps://www.aitopic.com/lock.before.json
lockfile_diff.py https://www.aitopic.com/tmphttps://www.aitopic.com/lock.before.json package-lock.json
Usage:
lockfile_diff.py BEFORE AFTER [--registry https:https://www.aitopic.com/https://www.aitopic.com/registry.npmjs.orghttps://www.aitopic.com/] [--allow-scope @acme]
[--max-added 25] [--fail-on high|medium|low|none] [--format text|md|json]
lockfile_diff.py --self-test
Exit: 0 nothing at or above --fail-on (default high), 1 findings at or above it, 2 unreadable input.
Flags (severity):
L01 high added or changed package that runs an install script (hasInstallScript)
L02 high package resolved from outside the registry (git, GitHub, http(s) tarball, filehttps://www.aitopic.com/link)
L03 high same name and version but a different integrity hash (possible tampering or republish)
L04 medium package without an integrity hash (cannot be verified on install)
L05 medium major version upgrade of a direct dependency
L06 medium downgrade of any package
L07 low a package now installed in two or more versions (duplicate copies)
L08 low more than --max-added packages added in one change
L09 medium license changed, or a strong copyleft license (GPL, AGPL, SSPL) appears
E01 entries that could not be parsed (skipped)
"""
import argparse, json, re, sys
from urllib.parse import urlparse
SEV = {"L01": "high", "L02": "high", "L03": "high", "L04": "medium", "L05": "medium", "L06": "medium",
"L07": "low", "L08": "low", "L09": "medium", "E01": "low"}
RANK = {"none": 99, "high": 3, "medium": 2, "low": 1}
COPYLEFT = re.compile(r"\b(A?GPL|SSPL)", re.I)
def parse_version(v):
"""'1.2.3-beta.1' -> (1, 2, 3, 'beta.1'); returns None for non-semver strings."""
m = re.match(r"^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+.*)?$", str(v or "").strip())
if not m:
return None
return int(m.group(1)), int(m.group(2)), int(m.group(3)), m.group(4) or ""
def cmp_version(a, b):
pa, pb = parse_version(a), parse_version(b)
if pa is None or pb is None:
return 0 if a == b else None
if pa[:3] != pb[:3]:
return -1 if pa[:3] < pb[:3] else 1
if pa[3] == pb[3]:
return 0
if not pa[3]:
return 1 # release > prerelease
if not pb[3]:
return -1
return -1 if pa[3] < pb[3] else 1
def bump_kind(old, new):
po, pn = parse_version(old), parse_version(new)
if po is None or pn is None:
return "other"
if pn[0] != po[0]:
return "major"
if pn[0] == 0 and pn[1] != po[1]:
return "major" # 0.x minor bumps are breaking by semver convention
if pn[1] != po[1]:
return "minor"
if pn[2] != po[2]:
return "patch"
return "prerelease"
def name_from_path(path):
"""'node_moduleshttps://www.aitopic.com/ahttps://www.aitopic.com/node_moduleshttps://www.aitopic.com/@shttps://www.aitopic.com/b' -> '@shttps://www.aitopic.com/b'."""
tail = path.split("node_moduleshttps://www.aitopic.com/")[-1]
return tail.rstrip("https://www.aitopic.com/")
def load(path):
"""Return (entries, errors, meta). entries: {install_path: {name, version, resolved, integrity, license, script, dev, direct}}."""
with open(path, encoding="utf-8") as fh:
data = json.load(fh)
if not isinstance(data, dict):
raise ValueError("top level is not a JSON object")
lv = data.get("lockfileVersion", 1)
entries, errors = {}, []
root = {}
if isinstance(data.get("packages"), dict):
root = data["packages"].get("", {}) or {}
direct = set((root.get("dependencies") or {})) | set((root.get("devDependencies") or {})) | set((root.get("optionalDependencies") or {}))
for p, e in data["packages"].items():
if p == "":
continue
if not isinstance(e, dict) or "node_moduleshttps://www.aitopic.com/" not in p:
if isinstance(e, dict) and e.get("link"):
continue # workspace folder entry; its node_modules link is checked instead
errors.append(p)
continue
name = e.get("name") or name_from_path(p)
top = p.count("node_moduleshttps://www.aitopic.com/") == 1
entries[p] = dict(name=name, version=str(e.get("version", "")), resolved=e.get("resolved", ""),
integrity=e.get("integrity", ""), license=e.get("license", ""),
script=bool(e.get("hasInstallScript")), dev=bool(e.get("dev")),
link=bool(e.get("link")), direct=top and name in direct)
elif isinstance(data.get("dependencies"), dict):
def walk(deps, prefix, top):
for name, e in deps.items():
p = prefix + "node_moduleshttps://www.aitopic.com/" + name
if not isinstance(e, dict) or "version" not in e:
errors.append(p)
continue
ver = str(e["version"])
resolved = e.get("resolved", "")
if not resolved and re.match(r"^(git|github:|file:|https?:)", ver):
resolved = ver
entries[p] = dict(name=name, version=ver, resolved=resolved, integrity=e.get("integrity", ""),
license="", script=False, dev=bool(e.get("dev")), link=False, direct=top)
if isinstance(e.get("dependencies"), dict):
walk(e["dependencies"], p + "https://www.aitopic.com/", False)
walk(data["dependencies"], "", True)
else:
raise ValueError("no 'packages' or 'dependencies' map found")
return entries, errors, dict(lockfileVersion=lv, name=data.get("name", ""), root=root)
def source_problem(resolved, registry, link):
if link:
return None
if not resolved:
return None
r = resolved.lower()
if r.startswith(("git+", "git:", "github:", "git@")) or "codeload.github.com" in r:
return "git source"
if r.startswith(("file:", "link:")):
return "local path"
if r.startswith("http:"):
return "plain http tarball"
if r.startswith("https:"):
host = urlparse(r).netloc
if host not in {urlparse(x).netloc for x in registry}:
return "tarball from " + host
return None
def audit(before, after, registry=("https:https://www.aitopic.com/https://www.aitopic.com/registry.npmjs.orghttps://www.aitopic.com/",), allow_scopes=(), max_added=25):
b_ent, b_err, b_meta = before
a_ent, a_err, a_meta = after
by_name_b, by_name_a = {}, {}
for p, e in b_ent.items():
by_name_b.setdefault(e["name"], set()).add(e["version"])
for p, e in a_ent.items():
by_name_a.setdefault(e["name"], set()).add(e["version"])
changes = dict(added=[], removed=[], upgraded=[], downgraded=[], changed_source=[])
flags = []
def flag(code, pkg, detail):
flags.append(dict(code=code, severity=SEV[code], package=pkg, detail=detail))
for p in sorted(set(a_ent) - set(b_ent)):
e = a_ent[p]
changes["added"].append(dict(path=p, name=e["name"], version=e["version"], direct=e["direct"], dev=e["dev"]))
for p in sorted(set(b_ent) - set(a_ent)):
e = b_ent[p]
changes["removed"].append(dict(path=p, name=e["name"], version=e["version"], direct=e["direct"]))
for p in sorted(set(a_ent) & set(b_ent)):
o, n = b_ent[p], a_ent[p]
if o["version"] != n["version"]:
c = cmp_version(o["version"], n["version"])
row = dict(path=p, name=n["name"], old=o["version"], new=n["version"], kind=bump_kind(o["version"], n["version"]), direct=n["direct"])
if c == 1:
row["kind"] = "downgrade"
changes["downgraded"].append(row)
flag("L06", n["name"], "%s -> %s (downgrade)" % (o["version"], n["version"]))
else:
changes["upgraded"].append(row)
if row["kind"] == "major" and n["direct"]:
flag("L05", n["name"], "%s -> %s (major, direct dependency)" % (o["version"], n["version"]))
elif o["integrity"] and n["integrity"] and o["integrity"] != n["integrity"]:
flag("L03", n["name"], "%s: integrity hash changed without a version change" % n["version"])
if o["resolved"] != n["resolved"] and o["version"] == n["version"] and source_problem(n["resolved"], registry, n["link"]):
changes["changed_source"].append(dict(path=p, name=n["name"], old=o["resolved"], new=n["resolved"]))
if o["license"] and n["license"] and o["license"] != n["license"]:
flag("L09", n["name"], "license %s -> %s" % (o["license"], n["license"]))
touched = set(x["path"] for x in changes["added"]) | set(x["path"] for x in changes["upgraded"] + changes["downgraded"] + changes["changed_source"])
for p in sorted(touched):
e = a_ent[p]
scoped_ok = any(e["name"].startswith(s.rstrip("https://www.aitopic.com/") + "https://www.aitopic.com/") for s in allow_scopes)
if e["script"] and not scoped_ok:
flag("L01", e["name"], "%s runs an install script (preinstallhttps://www.aitopic.com/installhttps://www.aitopic.com/postinstall)" % e["version"])
sp = source_problem(e["resolved"], registry, e["link"])
if sp and not scoped_ok:
flag("L02", e["name"], "%s resolved from %s: %s" % (e["version"], sp, e["resolved"]))
if not e["integrity"] and not e["link"] and not (sp and sp.startswith(("git", "local"))):
flag("L04", e["name"], "%s has no integrity hash" % e["version"])
if p in {x["path"] for x in changes["added"]} and e["license"] and COPYLEFT.search(e["license"]):
flag("L09", e["name"], "%s added with license %s" % (e["version"], e["license"]))
for name in sorted(by_name_a):
if len(by_name_a[name]) > 1 and len(by_name_a[name]) > len(by_name_b.get(name, set())):
flag("L07", name, "now installed in %d versions: %s" % (len(by_name_a[name]), ", ".join(sorted(by_name_a[name], key=lambda v: parse_version(v) or (0, 0, 0, v)))))
if len(changes["added"]) > max_added:
flag("L08", "-", "%d packages added (limit %d)" % (len(changes["added"]), max_added))
for p in a_err:
flag("E01", p, "entry could not be parsed and was skipped")
order = {"high": 0, "medium": 1, "low": 2}
flags.sort(key=lambda f: (order[f["severity"]], f["code"], f["package"]))
summary = dict(before=len(b_ent), after=len(a_ent), added=len(changes["added"]), removed=len(changes["removed"]),
upgraded=len(changes["upgraded"]), downgraded=len(changes["downgraded"]),
direct_changes=sum(1 for x in changes["added"] + changes["upgraded"] + changes["downgraded"] if x.get("direct")),
high=sum(f["severity"] == "high" for f in flags), medium=sum(f["severity"] == "medium" for f in flags),
low=sum(f["severity"] == "low" for f in flags),
lockfile_versions=[b_meta["lockfileVersion"], a_meta["lockfileVersion"]])
return dict(summary=summary, changes=changes, flags=flags)
def render_text(r):
s = r["summary"]
out = ["npm lockfile change audit",
"- packages %d -> %d: +%d added, -%d removed, %d upgraded, %d downgraded (%d direct)" % (
s["before"], s["after"], s["added"], s["removed"], s["upgraded"], s["downgraded"], s["direct_changes"]),
"- findings: %d high, %d medium, %d low; lockfileVersion %s -> %s" % (s["high"], s["medium"], s["low"], *s["lockfile_versions"]), ""]
c = r["changes"]
if c["upgraded"] or c["downgraded"]:
out.append("Version changes")
for x in c["upgraded"] + c["downgraded"]:
out.append(" %-28s %-10s -> %-10s %-10s%s" % (x["name"], x["old"], x["new"], x["kind"], " direct" if x["direct"] else ""))
out.append("")
if c["added"]:
out.append("Added")
for x in c["added"]:
out.append(" %-28s %-10s%s%s" % (x["name"], x["version"], " direct" if x["direct"] else "", " dev" if x["dev"] else ""))
out.append("")
if c["removed"]:
out.append("Removed")
for x in c["removed"]:
out.append(" %-28s %s" % (x["name"], x["version"]))
out.append("")
out.append("Findings" if r["flags"] else "Findings: none")
for f in r["flags"]:
out.append(" %s %-6s %-26s %s" % (f["code"], f["severity"], f["package"], f["detail"]))
return "\n".join(out)
def render_md(r):
s = r["summary"]
out = ["## npm lockfile change audit", "",
"**%d -> %d packages**: +%d added, -%d removed, %d upgraded, %d downgraded (%d direct). Findings: **%d high**, %d medium, %d low." % (
s["before"], s["after"], s["added"], s["removed"], s["upgraded"], s["downgraded"], s["direct_changes"], s["high"], s["medium"], s["low"]), ""]
if r["flags"]:
out += ["| Code | Severity | Package | Detail |", "|---|---|---|---|"]
out += ["| %s | %s | `%s` | %s |" % (f["code"], f["severity"], f["package"], f["detail"].replace("|", "\\|")) for f in r["flags"]]
out.append("")
ch = r["changes"]["upgraded"] + r["changes"]["downgraded"]
if ch:
out += ["| Package | From | To | Kind |", "|---|---|---|---|"]
out += ["| `%s`%s | %s | %s | %s |" % (x["name"], " (direct)" if x["direct"] else "", x["old"], x["new"], x["kind"]) for x in ch]
return "\n".join(out)
def run(argv):
ap = argparse.ArgumentParser(description="Audit the changes between two npm lockfiles.")
ap.add_argument("before", nargs="?")
ap.add_argument("after", nargs="?")
ap.add_argument("--registry", action="append", help="allowed registry URL (repeatable; default registry.npmjs.org)")
ap.add_argument("--allow-scope", action="append", default=[], help="trusted scope, e.g. @acme (skips L01https://www.aitopic.com/L02 for it)")
ap.add_argument("--max-added", type=int, default=25)
ap.add_argument("--fail-on", choices=["high", "medium", "low", "none"], default="high")
ap.add_argument("--format", choices=["text", "md", "json"], default="text")
ap.add_argument("--self-test", action="store_true")
a = ap.parse_args(argv)
if a.self_test:
return self_test()
if not a.before or not a.after:
ap.print_usage(sys.stderr)
return 2
try:
before, after = load(a.before), load(a.after)
except (OSError, ValueError) as e:
print("error: cannot read lockfile: %s" % e, file=sys.stderr)
return 2
r = audit(before, after, tuple(a.registry or ["https:https://www.aitopic.com/https://www.aitopic.com/registry.npmjs.orghttps://www.aitopic.com/"]), tuple(a.allow_scope), a.max_added)
print(json.dumps(r, indent=2) if a.format == "json" else render_md(r) if a.format == "md" else render_text(r))
worst = max([RANK[f["severity"]] for f in r["flags"]] or [0])
return 1 if worst >= RANK[a.fail_on] else 0
def self_test():
checks = 0
def ok(cond, msg):
nonlocal checks
checks += 1
if not cond:
raise AssertionError(msg)
ok(cmp_version("1.2.3", "1.10.0") == -1, "numeric compare")
ok(cmp_version("2.0.0-rc.1", "2.0.0") == -1, "prerelease < release")
ok(bump_kind("4.17.21", "5.0.0") == "major", "major")
ok(bump_kind("0.3.1", "0.4.0") == "major", "0.x minor is major")
ok(bump_kind("1.2.3", "1.2.9") == "patch", "patch")
ok(name_from_path("node_moduleshttps://www.aitopic.com/ahttps://www.aitopic.com/node_moduleshttps://www.aitopic.com/@shttps://www.aitopic.com/b") == "@shttps://www.aitopic.com/b", "nested scoped name")
reg = ("https:https://www.aitopic.com/https://www.aitopic.com/registry.npmjs.orghttps://www.aitopic.com/",)
ok(source_problem("git+ssh:https://www.aitopic.com/https://www.aitopic.com/
[email protected]://www.aitopic.com/xhttps://www.aitopic.com/y.git#abc", reg, False) == "git source", "git")
ok(source_problem("https:https://www.aitopic.com/https://www.aitopic.com/registry.npmjs.orghttps://www.aitopic.com/ahttps://www.aitopic.com/-https://www.aitopic.com/a-1.0.0.tgz", reg, False) is None, "registry ok")
ok(source_problem("https:https://www.aitopic.com/https://www.aitopic.com/example.comhttps://www.aitopic.com/a.tgz", reg, False) == "tarball from example.com", "foreign host")
def lock(pk):
return ({"node_moduleshttps://www.aitopic.com/" + k: dict(dict(name=k, resolved="https:https://www.aitopic.com/https://www.aitopic.com/registry.npmjs.orghttps://www.aitopic.com/%shttps://www.aitopic.com/-https://www.aitopic.com/x.tgz" % k, integrity="sha512-" + k + v.get("version", ""),
license="MIT", script=False, dev=False, link=False, direct=True), **v) for k, v in pk.items()}, [], dict(lockfileVersion=3))
b = lock({"a": dict(version="1.0.0"), "b": dict(version="2.0.0"), "c": dict(version="1.0.0")})
n = lock({"a": dict(version="2.0.0"), "b": dict(version="1.9.0"), "d": dict(version="1.0.0", script=True, license="AGPL-3.0")})
n[0]["node_moduleshttps://www.aitopic.com/c"] = dict(b[0]["node_moduleshttps://www.aitopic.com/c"], integrity="sha512-other")
r = audit(b, n, reg)
codes = sorted(f["code"] for f in r["flags"])
ok(r["summary"]["added"] == 1 and r["summary"]["removed"] == 0, "added count")
ok("L05" in codes, "major direct flagged")
ok("L06" in codes, "downgrade flagged")
ok("L01" in codes and "L09" in codes, "install script and copyleft flagged")
ok("L03" in codes, "integrity change flagged")
r2 = audit(b, b, reg)
ok(r2["flags"] == [] and r2["summary"]["upgraded"] == 0, "identical lockfiles are clean")
n2 = lock({"a": dict(version="1.0.0"), "b": dict(version="2.0.0"), "c": dict(version="1.0.0"), "@acmehttps://www.aitopic.com/tool": dict(version="1.0.0", script=True)})
ok(not [f for f in audit(b, n2, reg, ("@acme",))["flags"] if f["code"] == "L01"], "allowed scope skips L01")
print("self-test OK: %d checks" % checks)
return 0
if __name__ == "__main__":
sys.exit(run(sys.argv[1:]))
Comments & Questions (0)
No comments yet
Be the first to comment!