← All Exercises
Audit Lockfile Entries for Supply Chain Gaps
intermediatejavascript
Background
Lockfiles are the contract between review and what actually ships. Unpinned tarballs and missing integrity let a compromised registry serve different bytes than the ones that were reviewed.
Problem
Scan resolved dependency entries for missing integrity hashes and plaintext HTTP tarball URLs, and return stable violation strings for the build report.
Input
JSON object: { lockfile: [{ name, resolved, integrity? }], policy: { requireIntegrity, allowHttp } }Output
JSON array of violation strings, sorted
Sample tests
Sample 1
Input: {"lockfile":[{"name":"left-pad","resolved":"https://registry.example.com/left-pad.tgz","integrity":"sha512-abc"}],"policy":{"requireIntegrity":true,"allowHttp":false}}Expected: []
Sample 2
Input: {"lockfile":[{"name":"ok","resolved":"https://registry.example.com/ok.tgz","integrity":"sha512-abc"},{"name":"loose","resolved":"http://mirror.example.com/loose.tgz"},{"name":"nohash","resolved":"https://registry.example.com/nohash.tgz"}],"policy":{"requireIntegrity":true,"allowHttp":false}}Expected: ["loose:insecure-protocol","loose:missing-integrity","nohash:missing-integrity"]
Your solution
Learning objective
Turn supply-chain policy into a checkable rule over the lockfile.