Validate that all packages come from trusted registries:
lockfile-lint --path package-lock.json --allowed-hosts npm --validate-httpsThis ensures:
Prevent packages from untrusted sources entering your lockfile:
lockfile-lint --path yarn.lock --allowed-hosts yarn --empty-hostname falseThis ensures:
--empty-hostname false)Ensure all packages have sha512 integrity hashes:
lockfile-lint --path package-lock.json --validate-integrityThis ensures:
Prevent package aliasing attacks:
lockfile-lint --path package-lock.json --allowed-hosts npm --validate-package-namesThis ensures:
Allow packages from multiple trusted sources:
lockfile-lint --path yarn.lock --allowed-hosts yarn npm verdaccio --validate-httpsThis is useful for:
Allow private registry and GitHub dependencies:
lockfile-lint --path yarn.lock --allowed-hosts "registry.mycompany.com" github.com --allowed-schemes "https:" "git+https:"This configuration:
Validate multiple lockfiles in a monorepo:
lockfile-lint --path "packages/**/package-lock.json" --validate-https --allowed-hosts npmThis:
- name: Lint Lockfile
run: npx lockfile-lint --path package-lock.json --validate-https --allowed-hosts npm --format plainlockfile-security:
script:
- npm install lockfile-lint
- npx lockfile-lint --path package-lock.json --validate-https --allowed-hosts npm --format plain- run:
name: Validate Lockfile Security
command: npx lockfile-lint --path package-lock.json --validate-https --allowed-hosts npm --format plainstage('Lockfile Security') {
steps {
sh 'npx lockfile-lint --path package-lock.json --validate-https --allowed-hosts npm --format plain'
}
}{
"husky": {
"hooks": {
"pre-commit": "lockfile-lint --path package-lock.json --validate-https --allowed-hosts npm"
}
}
}// .husky/pre-commit
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
npx lockfile-lint --path package-lock.json --validate-https --allowed-hosts npm{
"lint-staged": {
"package-lock.json": [
"lockfile-lint --path package-lock.json --validate-https --allowed-hosts npm"
]
}
}{
"scripts": {
"lint:lockfile": "lockfile-lint --path package-lock.json --validate-https --allowed-hosts npm",
"pretest": "npm run lint:lockfile",
"prepublishOnly": "npm run lint:lockfile"
}
}