Dependency Management Security
Third-party dependencies are the most common initial access vector in modern supply chain attacks. Every package you install is code you didn't write, audit, or control — and it runs with full process privileges the moment it is installed.
Breadth layernotes-security-core-knowledge.md Also see: GitHub/CI Security · OWASP CI/CD Risks · Linux SBOM
Start here: the basics in plain words
Modern software is mostly other people's code. A typical web app has a few dozen packages listed by its developers, and those packages pull in their own packages, so the real total is often hundreds or thousands. Each one is downloaded from a public package registry (npm for JavaScript, PyPI for Python, crates.io for Rust, Maven Central for Java) and runs with the same permissions as your own code.
What actually happens when a developer types npm install:
- npm reads
package.json(the list of packages the developer asked for, with allowed version ranges). - It asks the registry for the newest versions that fit those ranges, then repeats for every package's own dependencies.
- It downloads them all and runs any install scripts the packages define, on your laptop or CI runner, before you've used a single line.
- It writes the exact versions it chose into a lockfile (
package-lock.json), so the next install gets the same ones.
A supply chain attack targets step 2 or 3. Take over one popular package's publishing account and push a new version with malware, and every project that installs it next runs the malware automatically.
A package your code uses. Direct = you listed it; transitive = something you listed pulled it in.
The public server packages are downloaded from. Anyone can usually publish to it.
^1.4.0 means "any 1.x from 1.4.0 up". Convenient, but it means a brand-new malicious 1.4.9 gets picked up automatically.
The exact version and checksum of every package installed. It turns "whatever is newest" into "exactly what we reviewed".
Code a package runs automatically during install (preinstall, postinstall, setup.py). The most common malware trigger.
Publishing a malicious package with a name one typo away from a popular one, e.g. reqeusts instead of requests.
Memory hook
npm installmeans "run code from strangers, as me, right now". Lockfiles, pinned versions and disabling install scripts are about turning that into "run code I already checked".
The Supply Chain Threat Model
Your application: ├── Direct dependencies (you chose these — listed in package.json / Cargo.toml / etc.) │ └── Transitive deps (their dependencies — you may never have reviewed these) │ └── Deep transitive deps (you definitely haven't reviewed these) │ ├── Build toolchain (compilers, bundlers, linters — also dependencies) ├── CI/CD pipeline (GitHub Actions, Docker base images) └── Infrastructure-as-code (Terraform modules, Helm charts)
Memory hookyou don't install a package, you install a tree. When you add one dependency, you're trusting its dependencies, and theirs, recursively — often hundreds of packages, maintained by hundreds of strangers, that you've never read. A modern npm app pulling in a thousand transitive packages is trusting a thousand maintainer accounts not to get compromised. That's why a single popular low-level library (left-pad, event-stream, xz) can break or backdoor millions of projects: it sits deep in everyone's tree. The mental model interviewers want: "my real attack surface isn't my dependencies, it's my dependencies' dependencies" — the transitive tree, plus the build toolchain and CI, which are dependencies too.
What makes dependencies dangerous
| Risk | Why |
|---|---|
| You don't read the code | Most developers install packages without auditing source |
postinstall scripts run automatically | npm install executes arbitrary shell commands on your machine immediately |
| Transitive exposure | A widely-used package (event-stream, xz-utils) affects millions of projects when compromised |
| Version ranges | ^1.0.0 in npm can silently pull a new 1.9.9 that didn't exist when you wrote the code |
| Maintainer trust is not permanent | Accounts get compromised; projects get abandoned and transferred |
The 7-Day Window — Why Recency Is a Risk Signal
The security community detects most malicious packages within 24–72 hours of publication on npm and PyPI. The window comes from:
Socket.dev, npm security team bots, PyPI malware detection scan new uploads
Security researchers actively monitor new packages and version bumps on high-value namespaces
New packages with install scripts that make network connections, read environment variables, or write outside the package directory get flagged quickly
A package with zero prior downloads suddenly getting thousands (dependency confusion) triggers alerts
Typical detection timeline for obvious malicious packages:
Hour 0 → package published
Hour 2-8 → automated scanners flag it
Hour 24 → community reports / security advisories posted
Hour 48 → registry removes it or marks deprecated
Day 3-7 → CVE assigned, NVD entry, Dependabot/Snyk rules updated
Sophisticated, targeted attacks (XZ Utils, event-stream) can stay hidden for months to years.The practical rulerefuse any dependency whose first publication or last update is less than 7 days old in production pipelines. This eliminates the detection gap for opportunistic malware while still allowing community review to catch obvious cases.
Memory hook"let the herd test it first." Malicious packages are usually caught within 24–72 hours by scanners and researchers, then pulled. So a deliberate cooldown — don't auto-adopt any version less than ~7 days old — means you're never the canary for opportunistic malware; you let the community absorb the bad versions before they reach your build. It's cheap, automatable (npm's
minimumReleaseAge, Renovate'sminimumReleaseAge), and catches the common case. The honest caveat to state: it does nothing against patient, targeted attacks like XZ Utils, where the malicious code was built up over two years and the package was old and trusted. So pair it with hash pinning and behavioral analysis. Mnemonic: age is a cheap filter for the dumb attacks, not the smart ones.
# npm: check when a package was first published and last updated
npm view <package-name> time | head -5
# time.created = first publication date
# time.modified = last update
# Example — a package published yesterday is suspicious:
npm view suspicious-package time.created
# 2026-06-09T14:22:31.000Z ← published yesterday
# Check the publish history of all versions
npm view <package-name> time --json | jq 'to_entries | sort_by(.value) | reverse | .[0:5]'
# PyPI: check upload dates
pip index versions <package> # list versions
curl https://pypi.org/pypi/<package>/json | jq '.releases | keys | .[-3:]'
# Then check each version's upload_time:
curl https://pypi.org/pypi/<package>/<version>/json | jq '.urls[].upload_time'Important nuanceThe 7-day rule catches new packages and new versions. It does not protect against:
- Long-planted backdoors that activate on a specific date or condition
- Sophisticated attackers like in XZ Utils (2+ year build-up)
- Account takeover where the package is old but the new version is malicious
Combine the rule with hash pinning (verify the exact bytes you expect, not just the version number).
Attack Vectors In Depth
1. Typosquatting
Register a package name visually similar to a popular one. Wait for developers to mistype.
Real package → Typosquatted package
requests → reqeusts, request, requests2
lodash → lodahs, 1odash, l0dash
express → expres, expressjs, expresss
react → recat, reakt, reeact
django → djano, diango, dajngo
urllib3 → urlib3, urllib, urliib3# Detecting typosquatting before install
# Check the package on the registry before installing
npm view <package-name> # inspect downloads, author, links
pip show <package-name> # after install — check homepage, author
# Red flags:
# - Tiny download count compared to the real package
# - Publish date in the last few days
# - Author/maintainer you don't recognise
# - No GitHub repo or homepage
# - install script that doesn't match the package's stated purposeDefenceUse IDE plugins that flag package name anomalies. Enforce SCA scanning in CI. Audit package.json / requirements.txt changes in PRs.
2. Dependency Confusion
An attacker registers a public package with the same name as your private internal package. Package managers that check both public and private registries may pull the public (attacker-controlled) version, especially if the attacker publishes a higher version number.
Your private registry: company-utils@1.0.0
Attacker publishes: company-utils@9999.0.0 on public npm
npm install company-utils
→ Resolves from npm public registry (higher version wins)
→ Downloads attacker's package instead of your internal oneReal incidentAlex Birsan (2021) exploited this in 35 major companies (Microsoft, Apple, PayPal, Tesla) and received $130k+ in bug bounties.
Memory hookdependency confusion = "highest version wins, and the public registry plays." The resolver's innocent rule — pull the highest version of a name — becomes a weapon when the same name exists in two registries: the attacker publishes
yourpkg@9999.0.0publicly and the build grabs that instead of your private1.0.0. Note how it differs from typosquatting (which relies on a developer's typo,reqeusts): dependency confusion needs no mistake — your correct internal name is the bait. The fix is to make your private names unclaimable publicly: scope/namespace them (@company/utils) and pin the resolver so scoped names only ever come from the private registry. Mnemonic: typosquatting tricks the human, confusion tricks the resolver.
# Detecting if you are vulnerable
# 1. Any unscoped package names in your private registry are at risk
# e.g., "internal-auth" instead of "@company/internal-auth"
# 2. Check npm config to see which registries are queried
npm config get registry
cat .npmrc
# Safe .npmrc configuration — force all @company-scoped packages to private registry only:
@company:registry=https://registry.company.com/
//registry.company.com/:_authToken=${NPM_TOKEN}
# Unscoped packages still go to public registry — scope everything internalFix
@company/package-name prevents namespace collision on npm
in pip, use --index-url (not --extra-index-url) so only your private registry is checked
to claim the namespace
# pip — WRONG: checks both registries, public can win
pip install --index-url https://private.registry/ --extra-index-url https://pypi.org/ company-utils
# pip — RIGHT: only private registry
pip install --index-url https://private.registry/ company-utils
# Cargo — namespace private crates to prevent confusion
# In .cargo/config.toml:
[source.crates-io]
replace-with = "company-registry"
[source.company-registry]
registry = "https://cargo.company.com/"3. Account Takeover → Malicious Version Bump
A maintainer's registry account is compromised (weak password, no MFA, phished). The attacker publishes a new minor/patch version with malicious code. Because developers have ^1.0.0 in their manifests, they automatically receive the malicious update.
TimelineCompromised → published → developers install → malware runs → detected. Can be hours.
# Check who has publish access to a package
npm access list collaborators <package-name>
# If a package has 20 collaborators, 20 accounts are attack surfaces
# Check the diff between the last two versions before upgrading
# npx (run without installing):
npx package-diff <package-name>@<old-version> <package-name>@<new-version>
# Or manually: download both tarballs and diffDefenceExact version pinning + lock files. A lock file records the exact version last reviewed; it must be updated intentionally (not automatically on npm install).
4. Protestware and Intentional Sabotage
A maintainer of a widely-used package intentionally introduces malicious or destructive code, often for political or ideological reasons.
| Incident | Package | What happened |
|---|---|---|
| node-ipc (2022) | node-ipc | Maintainer added code to wipe files on machines with Russian/Belarusian IP addresses |
| colors.js + faker.js (2022) | colors, faker | Maintainer published infinite-loop versions to protest not being paid; broke thousands of apps |
| event-stream (2018) | event-stream | Maintainer transferred to unknown party; new version added wallet theft targeting Copay app |
Why it's hard to defend againstThe maintainer has legitimate access — no account compromise, no phishing. The only defence is code review of version updates.
# Review the diff before updating a dependency
# Using npm pack to inspect the tarball
npm pack <package-name>@<version>
tar -xzf <package-name>-<version>.tgz
find package/ -name "*.js" | xargs grep -E 'exec|eval|child_process|fs\.write|net\.|axios|fetch'
# Look specifically at install scripts
cat package/package.json | jq '.scripts'
# "postinstall", "preinstall", "install" scripts run automatically
# Any network calls, file writes outside the package, env var reads = red flag5. Subdependency / Transitive Attack
Attacking a package deep in the dependency tree that many projects depend on transitively.
Your app
└── webpack
└── terser
└── source-map-support
└── [compromised-deep-transitive-dep]
└── malicious code runs at build timeThe compromised package may have millions of dependents but individually low download numbers per project, making it hard to track.
# Map your full dependency tree (npm)
npm ls --all # full tree
npm ls <package-name> # find where a specific package comes from
# Check if a package is in your transitive tree
npm why <package-name> # shows dependency path
# Cargo
cargo tree # full dependency tree
cargo tree -p <crate> # subtree for specific crate
# Python
pipdeptree # install: pip install pipdeptree
pipdeptree -p <package>npm / pnpm / yarn — JavaScript and TypeScript
Lock Files
npm → package-lock.json (lockfileVersion 3 in npm 7+)
yarn → yarn.lock
pnpm → pnpm-lock.yamlAlways commit lock files. A lock file records exact resolved versions and integrity hashes for every package in the tree. Without it, npm install may resolve different versions on different machines.
# npm — integrity hashes in package-lock.json
# Every package has an "integrity" field: sha512-<base64>
# npm verifies this hash against what it downloads — tampered packages are rejected
cat package-lock.json | jq '.packages["node_modules/lodash"].integrity'
# "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gAzMVEqhO3Wj88qqFZaUzvqGENqHbJ6t4nGbYe/mMqxuuAdTntoMBiTOBfw=="Version Range Dangers
// package.json — the ^ and ~ wildcards silently accept new versions
{
"dependencies": {
"lodash": "^4.17.21", // accepts 4.x.x — any new minor or patch
"express": "~4.18.0", // accepts 4.18.x — any new patch
"axios": "1.6.0", // exact version — safest
"react": "*" // any version — never do this in production
}
}# Lock your dependencies to exact versions
# Option 1: use exact specifiers in package.json
npm install --save-exact lodash # adds "lodash": "4.17.21" (no ^)
# Option 2: .npmrc to always save exact
echo "save-exact=true" >> .npmrc
# Option 3: pnpm — by default uses exact versions in pnpm-lock.yaml
# pnpm-lock.yaml always stores resolved + integrity — more deterministic than npmInstall Script Auditing
npm, yarn, and pnpm all run preinstall, install, and postinstall scripts automatically. This is the most common malware delivery mechanism.
# Review install scripts before running npm install
# Use --ignore-scripts to suppress all install hooks
npm install --ignore-scripts
# Audit install scripts in all dependencies
npx can-i-ignore-scripts # lists which packages use install scripts
# pnpm — explicitly approved install scripts only
# In package.json:
{
"pnpm": {
"onlyBuiltDependencies": ["esbuild", "sharp"]
// only these packages are allowed to run install scripts
}
}
# Or use pnpm's allowedDeprecatedVersions / overrides to control installsnpm Audit and Dependency Scanning
# Built-in vulnerability scanning
npm audit
npm audit --audit-level=high # fail only on high/critical
npm audit fix # auto-upgrade to patched versions
# pnpm
pnpm audit
pnpm audit --fix
# yarn
yarn audit
# Check for outdated packages
npm outdated
# View full info on a package (check author, homepage, repo)
npm view <package-name>
# Look at download counts to assess legitimacy
# A package with 5 downloads/week claiming to do something important is suspicious
npm view <package-name> downloads-last-weekpnpm-Specific Security Features
pnpm has stronger supply-chain defaults than npm:
# .npmrc or package.json pnpm config
# Strict hoisting — no phantom dependencies
# (packages can only use what's listed in their own package.json)
node-linker=isolated # pnpm's default; npm has hoisted mode which is more permissive
# Frozen lockfile in CI — fail if pnpm-lock.yaml would change
# package.json scripts:
"ci": "pnpm install --frozen-lockfile"
# Disable install scripts globally (then approve individually)
# .npmrc:
ignore-scripts=trueCargo — Rust
Cargo (Rust's package manager) has several security advantages by design, and a growing set of auditing tools.
Cargo.lock and Exact Pinning
Cargo always generates a Cargo.lock with exact versions and checksums for every dependency. Unlike npm, Cargo uses this consistently:
# Cargo.lock (generated — do NOT manually edit, but DO commit it for binaries)
[[package]]
name = "serde"
version = "1.0.195"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "63261df402c1e1b9607b6cf450f462bee1f4e34df7fe6f2d4a4e8f6d50b6deef"
dependencies = [
"serde_derive",
]The checksum field is a SHA-256 of the crate tarball. If crates.io serves a different file, Cargo refuses to build. This is significantly stronger than npm's optional integrity checking.
# Cargo.toml — version specifiers
[dependencies]
serde = "1.0" # accepts >=1.0.0 <2.0.0 (SemVer compatible)
tokio = "=1.35.1" # exact version (pinned)
reqwest = { version = "0.11", features = ["json"] }# Commit Cargo.lock for binaries and applications
# Library crates: Cargo.lock is not published to crates.io anyway
# Binary projects: always commit Cargo.lock
# Verify checksums manually
cargo fetch --locked # fails if Cargo.lock would changecargo audit — RustSec Advisory Database
# Install
cargo install cargo-audit
# Scan all dependencies for known CVEs
cargo audit
# Example output:
# Crate: openssl
# Version: 0.10.55
# Warning: unmaintained
# Title: Unsafe use of deprecated functions
# ID: RUSTSEC-2023-0072
# Fail CI on high severity
cargo audit --deny warnings # treat all advisories as errors
cargo audit --deny unsound # only fail on unsound/memory-safety issuescargo deny — Comprehensive Policy Enforcement
cargo deny goes beyond CVE scanning — it enforces license policies, bans specific crates, checks for duplicate versions, and validates sources.
cargo install cargo-deny
# Generate initial config
cargo deny init# deny.toml
[advisories]
db-path = "~/.cargo/advisory-db"
db-urls = ["https://github.com/rustsec/advisory-db"]
vulnerability = "deny" # deny = fail build on any vulnerability
unmaintained = "warn"
yanked = "deny"
[licenses]
unlicensed = "deny"
allow = ["MIT", "Apache-2.0", "BSD-3-Clause"]
deny = ["GPL-3.0"] # no GPL in this commercial product
[bans]
multiple-versions = "warn" # alert on diamond dependency conflicts
deny = [
{ name = "openssl", reason = "use rustls instead" },
]
[sources]
unknown-registry = "deny" # only allow crates.io and listed alternatives
unknown-git = "deny"
allow-git = [] # explicitly allow specific git sourcescargo deny check # run all checks
cargo deny check advisories # only CVE check
cargo deny check licenses # only license checkpip / Poetry / uv — Python
Python's ecosystem has historically had weaker supply-chain controls than Rust or Go, but tooling has improved significantly.
When Python Package Code Runs
Last verified2026-10
What is this?A pull request that only adds one line, say helpful-utils==1.0 to requirements.txt or pyproject.toml, adds no Python code to your repository. But it changes which code runs on every machine that installs your project's dependencies. Installing a Python package can run that package's code before you ever import it.
Why it matters"Just a dependency bump" is one of the easiest changes to approve without reading. After merge, that one line runs on every developer laptop, every CI job (including deploy jobs that hold production secrets) and every container build.
How it worksPackages come in two file types, and the difference decides whether installing runs code:
A pre-built zip archive. Installing it mostly means unpacking files into place: no package code runs at install time.
Source code that must be built on your machine first. Building runs the package's setup.py or the build backend named in its pyproject.toml: arbitrary code, with your permissions.
pip falls back to the sdist whenever no wheel matches your platform. An attacker can simply publish only an sdist to make sure their build code runs.
The moments a package's code can execute:
-
1. Resolving and downloadingattackbefore anything is installed
- For an sdist, pip may build it just to read its metadata (name, dependencies). Even
pip downloadcan run build code.
- For an sdist, pip may build it just to read its metadata (name, dependencies). Even
-
2. Buildingattacksdists only
setup.pyor the PEP 517 build backend runs. The[build-system] requireslist pulls in more packages, which also run.
-
3. Installingattackfiles land in site-packages
- A package can drop a
.pthfile next to its code (wheels included).
- A package can drop a
-
4. Every Python startattackeven if nobody imports the package
- Lines in a
.pthfile that start withimportrun each time the interpreter starts. A quiet persistence trick.
- Lines in a
-
5. Importattackwhen your code imports it
- The package's
__init__.pyruns. This is what thetorchtritonincident used (below).
- The package's
-
6. Commands it installsattackentry points
- Console scripts can shadow a common command name on your PATH.
In practiceWhat the two hooks look like when you inspect a package (illustration, not working malware):
helpful-utils-1.0.tar.gz
└── setup.py
from setuptools import setup
# ← any code written here runs during "pip install" on the installing machine
setup(name="helpful-utils", version="1.0", packages=["helpful_utils"])
helpful_utils-1.0-py3-none-any.whl (unzip -l)
helpful_utils/__init__.py
helpful_utils-startup.pth ← a .pth file in a wheel: check what it importsWhat this means for a fork pull request that only adds a dependency:
pull_requestthe install runs in a sandbox with no secrets and a read-only token. Little to steal, but it still has internet access.
pull_request_target with the PR's code checked outthe install runs next to the token, caches and secrets (see questions 3–5).
this is the real risk. Every pip install everywhere runs it, including privileged pipelines.
Security angle: defences
Check that the package exists and how old it is, who maintains it, and whether its name is one typo away from a popular package. Check whether it ships only an sdist, and whether its wheel contains a .pth file. Check that the source repository link matches the published files.
pip install --only-binary :all: or uv pip install --no-build rejects sdists, so no build code runs. (.pth files and import-time code still can.)
A lockfile with hashes (--require-hashes, uv.lock, poetry.lock) means a new malicious version can't slip in silently.
A cooldown such as uv's --exclude-newer, or a registry proxy that holds new versions for a few days, avoids most hijacked releases, which are usually caught within days.
Build the environment or image in a job without credentials, then pass the result to the job that deploys.
📰Real incident — torchtriton (2022). PyTorch's nightly builds depended on a package called
torchtritonthat they hosted on their own index. Someone uploaded a package with the same name to the public PyPI, and pip preferred it (dependency confusion). Around 25–30 December 2022, anyone who installed PyTorch nightly got the malicious version. When imported, it collected system information, SSH keys and files from the home directory and sent them out. Lesson: code can run at import, not only at install, and a name collision is enough to get it onto machines.
📰Real incident — ctx (2022). An attacker took over the PyPI package
ctxby re-registering the expired email domain of its maintainer and resetting the account password. New versions sent the installing machine's environment variables, including AWS keys, to the attacker. Lesson: a dependency that was trustworthy for years can change owner overnight. Pins and hashes are what stop an update from silently swapping it.
🎯On the job. In code review, treat changes to
requirements*.txt,pyproject.toml,setup.cfg, lockfiles and.pth-shipping packages as code changes that need a security-aware reviewer (CODEOWNERS). The same applies to npm:preinstall/postinstallscripts run onnpm install, andnpm ci --ignore-scriptsdisables them.
Hash Pinning in requirements.txt
The safest requirements.txt approach pins exact version and the SHA-256 hash of the wheel/sdist:
# Generate hash-pinned requirements
pip-compile --generate-hashes requirements.in > requirements.txt
# requirements.txt output (hash-pinned):
requests==2.31.0 \
--hash=sha256:58cd2187423d55f2b2e0168b27e279faa7e1a3fea5b4fdc36e1e4c5a4c62d2a2 \
--hash=sha256:1533d2b771b8f34a81a9e73d93be889bc8d012e6af79c1d4f18a3c3f4c5b1c4e
# Two hashes = sha256 of the wheel for different platforms
# Install must verify hashes (automatic when hashes are present in requirements.txt)
pip install --require-hashes -r requirements.txt
# If hash doesn't match → installation fails with errorPoetry
Poetry uses poetry.lock which stores SHA-256 content hashes for every package:
# poetry.lock (generated — commit this)
[[package]]
name = "requests"
version = "2.31.0"
description = "Python HTTP for Humans."
optional = false
python-versions = ">=3.7"
files = [
{file = "requests-2.31.0-py3-none-any.whl", hash = "sha256:58cd2187..."},
{file = "requests-2.31.0.tar.gz", hash = "sha256:942c5a758f98d7..."},
]# Install locked — fail if lock would change
poetry install --no-update
# In CI — strict mode
poetry install --frozen
# Check for vulnerabilities
poetry run pip-audit # pip-audit works with poetry virtualenvsuv — Fast Python Package Manager (Astral)
uv is a new Rust-based Python package manager that is significantly faster than pip and has better security defaults:
# Install uv
pip install uv # or: curl -LsSf https://astral.sh/uv/install.sh | sh
# Create a project
uv init myproject
uv add requests # adds to pyproject.toml, updates uv.lock
# uv.lock stores exact versions + hashes — similar to Cargo.lock
# Always commit uv.lock
# Install from lock (fail if lock would change)
uv sync --frozen
# Audit for vulnerabilities
uv run pip-auditpip-audit — CVE Scanning
pip install pip-audit
# Scan current environment
pip-audit
# Scan a requirements file
pip-audit -r requirements.txt
# Scan with SBOM output (CycloneDX)
pip-audit -r requirements.txt --format cyclonedx-json > sbom.cdx.json
# Fix known vulnerabilities (upgrades to patched versions)
pip-audit --fixPyPI Threat-Specific Defences
# Check package metadata before installing
pip index versions <package-name> # see all versions
pip show <package-name> # check author, homepage (after install)
# Use the API to check publication date
curl https://pypi.org/pypi/<package>/json | python3 -c "
import json, sys
data = json.load(sys.stdin)
for ver, files in sorted(data['releases'].items())[-5:]:
if files:
print(ver, files[0]['upload_time'])
"
# Verify checksums for downloaded packages
pip download <package>==<version>
sha256sum <package>-<version>.whl
# Compare against PyPI's listed hash
# Private PyPI mirror — only serve vetted packages
# In pip.conf:
[global]
index-url = https://pypi.company.com/simple/
trusted-host = pypi.company.comGo Modules
Go's module system has some of the strongest supply-chain security properties of any ecosystem by default.
go.sum — Cryptographic Verification
Every module has two entries in go.sum:
# go.sum entries
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt38=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
# h1: is a Hash/1 tree hash of the module zip contents
# go.mod hash verifies the module's go.mod file specificallygo.sum is a tamper-evident log — if the upstream module is modified and serves different content, go get / go build will fail because the new hash won't match go.sum.
# go.sum is automatically updated by go get / go mod tidy
# Always commit go.sum — it is the security anchor of your build
# Build with exact locked dependencies
go build -mod=readonly ./... # fails if go.sum would need updating
# In CI, use:
GOFLAGS=-mod=readonly go build ./...
# Verify module checksums against the checksum database (sum.golang.org)
go mod verify
# The checksum database (sum.golang.org) is a global transparency log
# Every module version uploaded is logged, and go verifies against this log
# Tampering with a published module version is detectable globallygovulncheck — Go Vulnerability Scanner
# Install
go install golang.org/x/vuln/cmd/govulncheck@latest
# Scan current module
govulncheck ./...
# Scan a specific binary
govulncheck -mode=binary ./myapp
# Output structured JSON for CI
govulncheck -json ./...
# Example output:
# Vulnerability #1: GO-2023-1558
# More info: https://pkg.go.dev/vuln/GO-2023-1558
# Module: golang.org/x/net
# Found in: golang.org/x/net@v0.0.0-20230301155059-4b61b3831e6e
# Fixed in: golang.org/x/net@v0.8.0GONOSUMCHECK and GONOSUMDB
# GONOSUMDB: skip checksum database for private modules
# (needed for private repos that aren't in the public checksum database)
GONOSUMDB=*.company.com
GONOSUMDB=github.com/company/*
# GOFLAGS for CI security
GONOSUMCHECK="" # always check sum (default) — don't override in production
GOFLAGS="-mod=readonly"
GOTELEMETRY=off # disable telemetryMaven / Gradle — Java and Kotlin
Maven — Dependency Management
<!-- pom.xml — specify exact versions, not ranges -->
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>3.2.1</version> <!-- exact version — no [1.0,2.0) ranges -->
</dependency>
</dependencies>
<!-- Enforce consistent versions across multi-module projects -->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.16.1</version>
</dependency>
</dependencies>
</dependencyManagement># Check for dependency vulnerabilities
mvn dependency:check # requires OWASP Dependency-Check plugin in pom.xml
# View effective dependency tree (resolve conflicts)
mvn dependency:tree
# Check for available updates
mvn versions:display-dependency-updates
# Build reproducibly (Maven 3.9+)
mvn -Dmaven.artifact.threads=1 -Dartifact.buildinfo.attach=true verifyGradle
// build.gradle.kts — exact versions with verification metadata
dependencies {
implementation("com.google.guava:guava:33.0.0-jre")
// Avoid dynamic versions:
// implementation("com.google.guava:guava:+") // bad
// implementation("com.google.guava:guava:33.+") // bad
}
// Enable dependency verification (generates checksums)
// gradle/verification-metadata.xml# Generate verification metadata (checksums for all deps)
./gradlew --write-verification-metadata sha256
# gradle/verification-metadata.xml is generated:
# <component group="com.google.guava" name="guava" version="33.0.0-jre">
# <artifact name="guava-33.0.0-jre.jar">
# <sha256 value="d3b189cd..." origin="Generated by Gradle"/>
# </artifact>
# </component>
# Subsequent builds verify against these checksums
./gradlew build # fails if checksums don't match
# OWASP Dependency-Check for Gradle
./gradlew dependencyCheckAnalyzeRuby Gems
# Gemfile.lock — always commit for applications
# The lock file pins exact versions and checksums
# Audit for vulnerabilities
gem install bundler-audit
bundle audit # check against Ruby Advisory Database
bundle audit update # update the advisory DB first
# Check for outdated gems
bundle outdated
# Generate a hash-verified Gemfile
bundle config set --global frozen true # prevents Gemfile.lock from changing
# In CI: install without updating the lock
bundle install --deployment # treats Gemfile.lock as authoritativeUniversal Best Practices
1. Commit All Lock Files
npm → package-lock.json or pnpm-lock.yaml ✓ commit
cargo → Cargo.lock (for binaries) ✓ commit
python → poetry.lock or uv.lock ✓ commit
go → go.sum ✓ commit
maven → pom.xml versions are the lock ✓ commit
gradle → gradle/verification-metadata.xml ✓ commit
ruby → Gemfile.lock ✓ commitLock files are security artifacts — losing them means losing your verification chain.
2. Exact Version Pinning Over Ranges
| Specifier | Meaning | Risk |
|---|---|---|
^1.0.0 (npm) | >=1.0.0 <2.0.0 | Any minor/patch accepted |
~1.0.0 (npm) | >=1.0.0 <1.1.0 | Any patch accepted |
>=1.0 (pip) | Anything from 1.0 | All future versions |
1.0.0 | Exactly 1.0.0 | Safe, explicit |
1.0.0 + hash | Exact content | Safest — bytes verified |
# npm — set save-exact globally
npm config set save-exact true
# pip — pin with hashes
pip-compile --generate-hashes requirements.in
# Cargo — use = prefix for exact
serde = "=1.0.195"3. The 7-Day Rule in CI
# GitHub Actions — custom check for new packages
- name: Check dependency ages
run: |
# For npm: check all direct dependencies
node -e "
const pkg = require('./package.json');
const { execSync } = require('child_process');
const deps = {...pkg.dependencies, ...pkg.devDependencies};
const SEVEN_DAYS = 7 * 24 * 60 * 60 * 1000;
const now = Date.now();
for (const [name, version] of Object.entries(deps)) {
const exactVersion = version.replace(/[\^~>=<]/, '');
try {
const info = JSON.parse(execSync(\`npm view \${name}@\${exactVersion} time --json\`, {encoding:'utf8'}));
const published = new Date(Object.values(info).pop()).getTime();
if (now - published < SEVEN_DAYS) {
console.error(\`FAIL: \${name}@\${exactVersion} was published less than 7 days ago\`);
process.exit(1);
}
} catch(e) { console.log(\`Could not check \${name}: \${e.message}\`); }
}
console.log('All dependencies passed the 7-day rule');
"4. Minimal Dependency Principle
Every dependency is an attack surface. Before adding a package:
Questions to ask before adding a dependency:
1. Can I implement this in < 50 lines without the dependency?
2. How many of this package's own dependencies would I also be pulling in?
npm ls <package> --all | wc -l
3. How many maintainers does this have? (single-maintainer = single point of failure)
npm view <package> maintainers
4. When was it last updated? (abandoned packages don't get security patches)
5. Does it have install scripts?
npm view <package> scripts
6. Does this package actually need to make network connections? (if no, flag if it does)5. Build Script Auditing
# List all packages that have install scripts (npm)
cat node_modules/.package-lock.json | python3 -c "
import json,sys
data = json.load(sys.stdin)
for pkg, info in data.get('packages', {}).items():
if any(s in info.get('scripts', {}) for s in ['preinstall','install','postinstall']):
print(pkg, info.get('scripts', {}))
"
# pnpm — approve install scripts explicitly
# pnpm-workspace.yaml or package.json:
{
"pnpm": {
"onlyBuiltDependencies": [
"esbuild", # these are explicitly reviewed and trusted
"sharp",
"@swc/core"
]
}
}
# If an unexpected package is running an install script: STOP and investigate6. Private Registry Mirroring
7. Reproducible Builds
Deep diveNix, Melange/Apko and hermetic reproducible builds — derivations and store paths, fixed-output derivations, binary-cache signing, SLSA L3 on self-hosted runners, the bootstrap problem.
A reproducible build produces byte-for-byte identical output given the same source and toolchain, regardless of when or where it runs.
# Go — reproducible by default (module graph is deterministic with go.sum)
go build -trimpath ./... # -trimpath removes local path info from binary
# Rust — cargo is mostly reproducible; use same toolchain
# Pin toolchain version in rust-toolchain.toml:
[toolchain]
channel = "1.75.0" # exact version, not "stable"
# Docker — use digest-pinned base images
# Instead of:
FROM node:20-alpine
# Use:
FROM node:20-alpine@sha256:bf6c61db4... # exact image digest
# npm -- ensure CI uses the lock
npm ci # always use 'npm ci' in CI, not 'npm install'
# npm ci: deletes node_modules, installs exactly from package-lock.json
# fails if package-lock.json is missing or out of sync with package.json
# pnpm
pnpm install --frozen-lockfile
# cargo
cargo build --locked # fails if Cargo.lock would need updatingIn practiceThe most common lockfile mistake in CI is using the install command that is allowed to change the lockfile:
$ npm install # resolves ranges like ^4.17.0 again → may pull a version published 10 minutes ago
$ npm ci # installs exactly what package-lock.json says, fails if it's out of sync ← use this in CI🎯On the job. In pull requests, read lockfile changes, not just
package.json: a one-line feature change that adds 300 lines topackage-lock.jsonhas pulled in new transitive packages. Look for packages you've never heard of, versions published in the last few days, andresolvedURLs that don't point at your registry.
Deep in the Tree: Transitive Vulnerabilities and Licences
Last verified2026-10
This section explains how licences generally work so you can spot the risk and ask the right questions. It is not legal advice: rules differ between countries, and real cases need a lawyer.
What is this?Your project lists, say, 20 packages. Those packages list their own, and so on, until your build contains several hundred packages that nobody on your team chose. Each one brings two kinds of risk that travel up the tree to you: security risk (a vulnerable or malicious version) and licence risk (terms you aren't allowed to meet, or terms that change).
your-app ← you ship this, so you answer for everything below
├── web-framework 4.2 MIT
│ └── template-engine 2.0 MIT
│ └── fast-parser 1.3 MIT → becomes "non-commercial" in 1.4 ← licence change, 3 levels down
└── pdf-export 1.1 Apache-2.0
└── image-lib 0.9 BSD
└── codec 2.1 CVE-2026-XXXXX (critical) ← vulnerability, 3 levels downWhy it matters"We didn't add it, a dependency did" doesn't change who ships it. Your customers, auditors, regulators (the EU Cyber Resilience Act makes manufacturers responsible for the components in their products) and, for licences, the copyright holder all look at the product you ship as a whole.
A vulnerable package deep in the tree
How it worksThe scanner says codec 2.1 is vulnerable, but you never asked for codec. The questions, in order:
-
1. Is it really there, and how did it get in?defendfind the path
npm ls codec,pipdeptree -r -p codec,cargo tree -i codec,mvn dependency:tree,go mod why, or search the SBOM
-
2. Can the vulnerable code actually be reached?defendreachability
- Is the vulnerable function called by anything in your app's paths, with attacker-controlled input? Many deep findings are not reachable
- If not, record that decision as a VEX statement (Vulnerability Exploitability eXchange: "not affected, because …") so the finding doesn't come back every week
-
3. Fix from the top if you cantlscleanest
- Upgrade the direct dependency (
pdf-export) to a version that pulls in a fixedcodec
- Upgrade the direct dependency (
-
4. Force the fixed version if the middle hasn't movedtlsoverride
- npm
overrides, yarnresolutions, pnpmoverrides, MavendependencyManagement, Gradle constraints, pip constraints files, uvoverride-dependencies, Cargo[patch] - Run the tests: the middle package was never tested with the newer version
- npm
-
5. If no fix existsattackcontain it
- Patch a fork, switch to an alternative, disable the feature that uses it, or add a compensating control (input validation, WAF rule), and track it as accepted risk with an owner and a date
In practiceForcing a fixed version deep in an npm tree:
{
"dependencies": { "pdf-export": "1.1.0" },
"overrides": {
"codec": "2.1.4" ← every copy of codec in the tree, at any depth, uses the fixed release
}
}📰Real incident — Log4Shell (CVE-2021-44228, 2021). Most affected companies had never added Log4j themselves: it came in through application servers, frameworks and vendor products, sometimes as a copy bundled inside another
.jar. The first week was spent answering "where is it?" rather than patching. Lesson: you can't fix a transitive dependency you can't find, which is why SBOMs and dependency-tree tooling matter before the incident.
A licence change deep in the tree
What happensA licence is attached to each released version, not to the project forever. When a project changes licence, the change applies to new versions. Versions already released under an open-source licence generally stay usable under that licence (permissive licences such as Apache 2.0 say the grant is perpetual and irrevocable), which is also why communities can fork the last open version.
Moved from Apache 2.0 to the SSPL and the Elastic License, which restrict offering them as a managed service. AWS forked the last Apache version as OpenSearch. An AGPL option was added in 2024.
HashiCorp moved from MPL 2.0 to the Business Source License (BUSL 1.1), which limits competing commercial use. The community forked the last MPL version as OpenTofu.
Moved from BSD to a dual source-available licence (RSALv2 / SSPL). The Linux Foundation forked the last BSD version as Valkey. Redis 8 (2025) added AGPL as an option.
Where the risk comes fromNot the change itself, but silently upgrading into it: a loose version range (^1.3) or an automated bump pulls in the new version under the new terms, and nobody reads licences on a Tuesday dependency update. The controls:
so new versions arrive only through a reviewed change.
that compares every package's licence, including transitive ones, against an allow-list, and fails the build on anything unknown or denied.
in update PRs. Some scanners flag it explicitly.
stay on the last open version for now (and accept no further fixes), move to the community fork, or buy the commercial licence.
A licence you aren't allowed to use, three levels down
Does it make the whole product illegal? No, not in the sense of "the software is now illegal". What happens is narrower and more practical: you are using or distributing that one component outside the permission its licence gives you. That is a copyright problem for that component, and it needs fixing. The consequences depend on the licence type:
Commercial use itself isn't permitted. Using it in a paid product, or even internally at a company, is outside the licence. Fix: remove or replace it, or buy a commercial licence from the author.
Commercial use is allowed. The obligation is triggered by distributing the software: if you ship a combined work, you must offer its source under the GPL. It does not automatically turn your code into GPL code; if you don't comply, you are infringing, and the usual outcomes are "comply, or stop distributing", plus possible damages. Running it only on your own servers (SaaS) generally doesn't count as distribution.
Like the GPL, but letting users interact with a modified version over a network also triggers the source obligation. This is the one that matters for SaaS.
Obligations cover the library or the files you changed, not your whole program, provided you follow the rules (for example dynamic linking for the LGPL, or keeping modified MPL files open).
Not "free to use": default copyright applies, so you have no permission. A missing licence field (NOASSERTION, UNKNOWN) in your scan needs a human decision.
Who is responsible?The company shipping the product, even when the component came in through someone else's package. "We didn't know" doesn't make it permitted, though it can affect how a dispute ends. The intermediate package might itself be breaking the licence by bundling it, but that doesn't give you permission.
What actually tends to happenMost cases end without a court: the copyright holder or a compliance group asks you to comply, you remove or replace the component, release source where required, or buy a licence. The serious costs show up as injunction risk (being ordered to stop shipping), customer contract breaches (enterprise contracts often promise no copyleft or no unlicensed code), and due diligence when the company is sold or raises money, when licence findings can reduce the price or block the deal.
📰Real case — Artifex v. Hancom (2017). Hancom used Artifex's Ghostscript PDF library, available under the GPL or a paid commercial licence, in its office suite without either releasing its source or paying. A US federal court refused to dismiss Artifex's claims, treating the GPL as an enforceable licence and contract. The parties settled. Lesson: open-source licence terms are enforceable, and "free to download" is not "free to ship".
🎯On the job. Make licences part of the same pipeline as vulnerabilities:
- Generate an SBOM with licence fields (SPDX identifiers).
- Enforce an allow-list in CI, including transitive packages (ScanCode, ORT, FOSSA,
cargo-deny,license-checker,pip-licenses). A typical policy: MIT, BSD and Apache allowed; MPL and LGPL need a check; GPL needs review for distributed products; AGPL, SSPL and non-commercial denied for products.- Route exceptions to legal.
- Keep the decisions on record, because the same question comes back at every audit and acquisition.
Private Registry Mirroring
A private registry proxy sits between your build system and the public registry. It:
- Caches and serves packages from your network (faster, no public internet dependency)
- Allows scanning before packages are served
- Blocks packages not on an allowlist
- Prevents dependency confusion by controlling namespace resolution
Build system → Private Nexus/Artifactory/Verdaccio → (approved packages only) → Public registryTools
| Tool | Supports | Deployment |
|---|---|---|
| Artifactory (JFrog) | npm, PyPI, Maven, Cargo, Go, Docker | Enterprise SaaS/self-hosted |
| Nexus Repository | npm, PyPI, Maven, Go | Enterprise self-hosted |
| Verdaccio | npm only | Simple self-hosted (Node.js) |
| Cloudsmith | npm, PyPI, Maven, Cargo, Docker | Cloud SaaS |
| GitHub Packages | npm, Maven, Gradle, NuGet, Docker | GitHub-hosted |
| AWS CodeArtifact | npm, PyPI, Maven | AWS-native |
Configuration Examples
# npm / pnpm — point to private registry
# .npmrc in project root:
registry=https://nexus.company.com/repository/npm-proxy/
//nexus.company.com/repository/npm-proxy/:_authToken=${NPM_TOKEN}
# Scoped packages route to private, everything else to public proxy
@company:registry=https://nexus.company.com/repository/npm-private/
# Python — pip.conf or .pip/pip.conf
[global]
index-url = https://nexus.company.com/repository/pypi-proxy/simple/
trusted-host = nexus.company.com
# Cargo — .cargo/config.toml
[source.crates-io]
replace-with = "company-mirror"
[source.company-mirror]
registry = "https://nexus.company.com/repository/cargo/"
# Maven — settings.xml
<mirror>
<id>company-nexus</id>
<mirrorOf>*</mirrorOf>
<url>https://nexus.company.com/repository/maven-proxy/</url>
</mirror>SCA and Behavioural Analysis Tools
Traditional SCA (CVE-based)
| Tool | Languages | CI integration |
|---|---|---|
| Snyk | npm, PyPI, Maven, Cargo, Go, Ruby | GitHub, GitLab, CLI |
| Dependabot | npm, PyPI, Maven, Cargo, Go, Ruby | GitHub-native |
| OWASP Dependency-Check | Java, .NET, Ruby, Node | Maven, Gradle, CLI |
| Trivy | npm, PyPI, Maven, Cargo, Go | CLI, Docker, Kubernetes |
| Grype | npm, PyPI, Maven, Cargo, Go | CLI |
| pip-audit | Python | CLI |
| cargo audit | Rust | CLI |
| govulncheck | Go | CLI |
Behavioural Analysis (Beyond CVEs)
Socket.dev — analyses npm and PyPI packages for suspicious behaviour, not just known CVEs. It detects:
- Install scripts that make network connections
- Code that reads environment variables (potential credential theft)
eval()or dynamic code execution- Obfuscated JavaScript
- Packages that were updated very recently (flagged for review)
- Typosquatting patterns
# Install Socket CLI
npm install -g socket
# Audit your package.json before installing
socket npm install <package-name> # replaces 'npm install', shows risk report
# In CI — fail on high-risk packages
socket ci npm install --strictOSS-Fuzz — Google's continuous fuzzing for open-source projects. Check if a dependency is covered (fuzz-tested projects are less likely to have memory corruption bugs).
Renovate and Dependabot — Automated Updates
Automated update bots keep your lock files current with security patches:
# renovate.json — Renovate configuration
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": ["config:recommended"],
"packageRules": [
{
"matchUpdateTypes": ["minor", "patch"],
"automerge": true, // auto-merge safe updates
"minimumReleaseAge": "7 days" // enforce the 7-day rule!
},
{
"matchUpdateTypes": ["major"],
"automerge": false, // require review for major updates
"minimumReleaseAge": "14 days"
}
],
"vulnerabilityAlerts": {
"enabled": true,
"minimumReleaseAge": "0 days" // security patches bypass the wait
}
}# .github/dependabot.yml
version: 2
updates:
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "weekly"
open-pull-requests-limit: 10
ignore:
- dependency-name: "*"
update-types: ["version-update:semver-major"] # don't auto-majorReal-World Incidents Reference
| Year | Package | Ecosystem | Attack type | Impact |
|---|---|---|---|---|
| 2018 | event-stream | npm | Ownership transfer → malicious code | Targeted Copay Bitcoin wallet; millions of downloads |
| 2020 | SolarWinds Orion | Enterprise | Build pipeline injection | SUNBURST backdoor; ~18k organisations |
| 2021 | ua-parser-js | npm | Account takeover | Cryptominer + credential stealer in 8M+ downloads/week package |
| 2021 | rc, coa | npm | Account takeover (same attacker) | Postinstall malware; broke many CI pipelines |
| 2021 | Multiple | npm/PyPI | Dependency confusion | Alex Birsan PoC — 35 major companies affected |
| 2022 | PyTorch-nightly | PyPI | Dependency confusion | torchtriton internal name squatted on PyPI |
| 2022 | colors.js, faker.js | npm | Protestware (maintainer) | Infinite loop; broke thousands of dependent apps |
| 2022 | node-ipc | npm | Protestware (maintainer) | File wiping on RU/BY IPs; affected vue-cli |
| 2022 | ctx (PyPI) | PyPI | Expired maintainer email domain re-registered → account takeover | Stole env vars (AWS keys) |
| 2024 | xz | Linux (Debian/Fedora sid) | Insider + social engineering | SSH backdoor via systemd-sshd; 2-year build-up by "Jia Tan"; caught pre-wide-release by Andres Freund (CVE-2024-3094) |
| 2025 | tj-actions/changed-files | GitHub Actions | Workflow token theft | CI secrets exposed across thousands of repos (CVE-2025-30066) |
| 2025 | nx ("s1ngularity") | npm | Compromised publish token via a vulnerable workflow | Malicious versions used developers' installed AI coding CLIs to hunt for secrets and uploaded them to public GitHub repos |
| 2025 | chalk, debug + 16 others | npm | Maintainer phished (fake npm 2FA-reset email) | Crypto-wallet-hijacking code in packages with billions of weekly downloads; pulled within hours |
| 2025 | "Shai-Hulud" worm | npm | Self-replicating: stolen npm tokens used to republish the victim's own packages | Hundreds of packages infected; secrets harvested and leaked to public GitHub repos |
Key lessons from these incidents
MFA on all registry accounts prevents most account-takeover attacks
when event-stream's maintainer transferred the project, no audit was done
XZ Utils passed every automated check; only caught by performance regression
SolarWinds and tj-actions show that compromising the build is as good as compromising the code
Interview Questions and Answers
Dependency confusionattacker publishes a public package with the same name as an internal private package at a higher version number — the package manager picks the "better" public version. Exploits namespace conflicts in package resolution. Typosquatting: attacker publishes reqeusts (deliberate typo of requests) hoping developers mistype. Dependency confusion exploits the package manager's own resolution logic; typosquatting exploits human error.
npm install --ignore-scripts improve security? What breaks if you use it?Malicious packages commonly run code in postinstall/preinstall lifecycle hooks during npm install — this is how most npm supply chain attacks exfiltrate tokens or install persistence. --ignore-scripts prevents all lifecycle scripts from running. What breaks: packages that need to compile native code (esbuild, node-sass, Puppeteer) won't build. Mitigation: use pnpm's onlyBuiltDependencies to allow only an explicitly approved list of packages to run install scripts.
npm install and npm ci? Which do you use in CI and why?npm install may update node_modules and can modify package-lock.json to resolve new versions. npm ci deletes node_modules entirely and installs exactly what's in the existing package-lock.json — deterministic, fast, and fails if the lock file is out of sync with package.json. Always use npm ci in CI/CD to guarantee exact dependency versions and prevent silent lock file drift.
A lock file (package-lock.json, Cargo.lock) pins exact versions and integrity hashes of all direct and transitive dependencies. Prevents: ^1.0.0 silently pulling a later malicious 1.0.5 release. Doesn't prevent: an attacker who compromises the package maintainer account and republishes the exact same pinned version with malicious code — some registries allow overwriting a version's content without changing the version number (npm historically allowed npm unpublish + republish with same version).
The 7-day rule delays dependency updates for at least 7 days after a new version is published. Most community-detected supply chain attacks (typosquatting, dependency confusion, early malicious packages) are reported within the first week — the community notices and removes the package before you've installed it. Doesn't catch: long-lived sleeper packages that appear legitimate for months before activating a payload (e.g., XZ Utils — Jia Tan contributed for 2+ years before inserting the backdoor).
go.sum provide stronger security guarantees than package-lock.json?go.sum records the expected hash of every module version AND the hash of its go.mod file, committed to the repository. The Go module proxy (sum.google.com) provides a public transparency log — every module hash is publicly auditable and tamper-evident; any future change to a published module is detectable. package-lock.json pins versions and hashes but there's no independent public log; npm allows packages to be yanked and republished with different content.
cargo deny and what can it enforce beyond CVE scanning?cargo deny is a policy-as-code tool for Rust/Cargo. Beyond CVE scanning (RustSec advisory DB), it enforces: licenses (allow-list MIT/Apache-2.0, deny GPL-3.0), dependency bans (block specific crate versions or deprecated crates), duplicate detection (alert if two versions of the same crate are pulled), and sources (only allow crates.io + approved git sources — blocks private registry confusion). Configured via deny.toml.
pip install --require-hashes work? What does it verify?--require-hashes requires every package in the requirements file to have an explicit --hash=sha256:... annotation. The installer downloads the wheel/sdist and computes its hash — if it doesn't match, installation fails with an error. This guarantees integrity: even if a registry is compromised or a typosquat package is published, the hash won't match. Generate the hashes with pip-compile --generate-hashes (pip-tools).
event-stream v3.3.6 added flatmap-stream as a new dependency. flatmap-stream contained an encrypted payload that decrypted only when it found Copay's Bitcoin wallet configuration in the environment, then exfiltrated private keys. What would have caught it: Socket.dev behavioral analysis (new dependency making network calls in install script); version pinning to 3.3.5 with hash verification; npm ci with a locked hash (would require explicit review of the new dependency). Standard CVE scanners wouldn't catch it — no CVE existed yet.
"Jia Tan" (likely state-sponsored) contributed legitimately to xz/liblzma for 2+ years and gained maintainer trust. In 2024 they inserted a backdoor in release tarballs (not in the git source) that patched sshd via systemd on affected systems. Automated scanners missed it because: no CVE existed, the malicious code was in build artifacts not source, and the manipulation was extremely subtle (test file modification). Andres Freund discovered it accidentally by noticing high CPU usage in sshd.
(1) Publish all internal packages with a scoped name (@company/package-name). (2) Configure .npmrc: @company:registry=https://private.registry.company. (3) In the private registry, configure a scope isolation policy that blocks any request for @company/ packages from being proxied to the public npm registry — so there's no fallback path to the public registry for your scope. (4) Disable upstream proxy for internal package names entirely.
Snyk and Dependabot are CVE-database-driven — they alert on packages with known published vulnerabilities. They're blind to a brand-new malicious package with no CVE. Socket.dev performs behavioral analysis of the package code itself: network calls in install scripts, shell execution, newly created maintainer accounts (<7 days old), newly added permissions, obfuscated code. It detects novel malicious packages before they have CVEs.
minimumReleaseAge Renovate setting and why is it important?minimumReleaseAge: "7 days" tells Renovate not to open a dependency-update PR until the new version is at least 7 days old. This implements the 7-day community detection window in automation — even if a malicious version is published, Renovate won't auto-update you to it before the community has had a chance to discover and remove it. Configure in renovate.json.
Option 1: npm install --ignore-scripts first, then inspect package.json for preinstall/postinstall fields before deciding to allow them. Option 2: run npm install inside a network-isolated sandbox and check strace -e trace=network npm install or tcpdump — any outbound connection during install is suspicious. Option 3: npx socket npm install <package> (Socket.dev CLI) intercepts and analyzes the package before installation completes.
* or >=1.0 as version specifiers in production?* or >=1.0 means any future version satisfies the constraint — every npm install may pull a different, potentially malicious version. An attacker who compromises a package maintainer account can publish 1.2.0 with a backdoor and all consumers of >=1.0 automatically receive it on next install. This also breaks reproducible builds. Always pin to exact versions or narrow semver ranges (~1.2.3) combined with a lock file and hash verification.
The PR adds no code to the repo, but it changes what code every install runs. Source distributions are built on the installing machine by running setup.py or the build backend, a package can ship a .pth file that runs on every Python start, and its init.py runs on import, which is how the torchtriton package stole SSH keys from PyTorch nightly users in 2022. In the PR's own pull_request CI that runs in a sandbox with no secrets, but after merge it runs on every laptop and pipeline, including deploys. So I review it like code: who publishes it, how old it is, whether it's a typosquat, whether it's sdist-only. Then I pin it with hashes, install with --only-binary where possible, and install dependencies in jobs that hold no secrets.
Not the product as a whole: the problem is that one component is being used outside its licence, which is a copyright issue for that component, and the company shipping the product is responsible no matter how deep it came in. The fix is to find the path with the dependency tree or SBOM, then remove or replace the package, override it to a compatible alternative, or buy a commercial licence, and record the decision. It's different from GPL, which allows commercial use but requires offering source when you distribute a combined work. Most cases end in a compliance request rather than a lawsuit, but courts do enforce these licences, as Artifex v. Hancom showed. That's why licence checks belong in CI next to vulnerability scans.
First confirm the path and whether the vulnerable code is reachable from our app; if it isn't, I record a VEX "not affected" statement with the reasoning. If it is reachable, I force the fixed version with the package manager's override mechanism, like npm overrides or Maven dependencyManagement, and run the test suite because the middle package wasn't tested with it. If there's no fixed version anywhere, I patch a fork, replace the library or disable the feature, add a compensating control, and track it as accepted risk with an owner and a date. Log4Shell showed the hardest part is finding these, so an SBOM has to exist before the incident.