Key Facts: Keeping a Published Package Safe

The security of a package depends less on its code than on everything around it: who can publish, how releases are built, and how users can verify what they installed. This page condenses the essentials into six panels, each with a short caption and a description of how it would be drawn.

Panel 1: the account is the front door

If an attacker controls your registry account, they can publish a malicious version that users install automatically through version ranges. Registries including npm and PyPI support, and for some situations require, two-factor authentication. Use a hardware key or authenticator app rather than SMS where offered.

Drawn as: a door labelled "registry account" with two locks, one marked "password", one marked "second factor".

Panel 2: tokens should be short-lived and narrow

Drawn as: three keys shrinking in size from "account password" to "scoped token" to "one-time CI credential".

Panel 3: build where people can see

Publishing from a public CI workflow, rather than a laptop, means each release can be traced to a commit and a set of build steps. This is the foundation of the SLSA framework's provenance levels.

Panel 4: provenance and signatures

MechanismWhat it proves
Checksums (for example in go.sum or lockfile integrity fields)The bytes are the same as last time.
Signatures via SigstoreA specific identity signed this artefact, recorded in a public transparency log.
Provenance attestations (npm provenance, PyPI attestations)This artefact was built from this repository and commit by this CI workflow.

Drawn as: a package box with three stamps on its side, each a different shape, captioned with the three rows above.

Panel 5: names can be weapons

Typosquatting, registering a name one keystroke away from a popular package, and dependency confusion, publishing a public package with the same name as a company's internal one, both rely on users or tooling choosing the wrong name. Defences: scope internal packages, configure registries per scope, and check new dependencies' names carefully before adding them.

Panel 6: tell people how to report problems

A SECURITY.md file and private vulnerability reporting on your forge give researchers a safe route. Published advisories, for example through the GitHub Advisory Database or the OSV database, let users' tools warn them automatically.

# SECURITY.md (minimal, illustrative)
## Reporting a vulnerability
Please use private vulnerability reporting on this repository.
Do not open a public issue. We aim to acknowledge reports promptly.

The six facts, in one list

  1. Protect the account with a strong second factor.
  2. Use narrow, short-lived credentials, or none at all.
  3. Build and publish from CI.
  4. Attach provenance or signatures where the registry supports them.
  5. Guard your names, especially internal ones.
  6. Publish a way to report vulnerabilities privately.

Each panel is covered in more depth elsewhere: see the essay on provenance attestations and the notes on typosquatting.