Skip to content

AI Compass / Knowledge cards

Securing package updates

pin your versions, then wait

Checked Automation

A supply-chain attack doesn’t target you directly, but a package you trust. The attacker publishes a new version with malware, and anyone who automatically installs the latest version picks it up. In Python, a startup file ending in .pth is all it takes: Python reads it every time it starts and runs any line in it that begins with import, even if your program never uses the package.

What it is for

Most poisoned versions are noticed quickly and blocked, often within minutes or hours. If you pin your versions and only adopt new ones after a short delay, you stay out of that window.

Steps

  1. Pin versions: list every package with an exact version number, such as package==1.2.3 in requirements.txt, or use a lock file that records all versions.
  2. Enforce hashes: a hash is a fingerprint of the file. With pip install --require-hashes -r requirements.txt, pip only installs files whose fingerprint matches your list. For this to work, every package has to be listed with a fixed version and a hash.
  3. Update with a delay: only adopt new versions after a few days. The uv tool can do this for you: with the exclude-newer setting and a duration such as 1 week, it only takes files uploaded before that point.
  4. Apply updates deliberately: update on purpose and read what has changed first, instead of blindly pulling the latest version on every run. This matters most for automated workflows such as CI pipelines.
  5. Keep secrets to a minimum: give an environment only the credentials it really needs. What isn’t there can’t be stolen.
  6. If in doubt, don’t start Python: every start, including pip, can trigger the malware again. Search the file system for the reported files instead, rebuild the environment and replace every credential that could be reached from it.

Limits

Sources

Status

Checked 19.11.2026 · Maturity proven · Pinned versions and hashes have been documented pip features for years; the uv setting is newer, so check it in your own version before relying on it.

You can try this with your team in the AI Lab. See the AI Lab