---
title: "Securing Python projects from supply-chain attacks"
description: "Hash-pinning is the core defense against compromised maintainer accounts or hacked distribution servers, because version pins alone fail when PyPI files can be added post-release and GitHub Action tags can be force-pushed."
url: "https://swe.quest/articles/securing-python-projects-from-supply-chain-attacks-9ecc242dbcff9bf0"
canonical: "https://astral.sh/blog/securing-from-supply-chain-attacks"
source: "Astral"
published: "2026-11-23"
difficulty: "medium"
kind: "How-to"
reading_minutes: 7
tags: ["supply-chain-security","python","ci-cd","build-systems"]
---

# Securing Python projects from supply-chain attacks

A post on [Astral](https://swe.quest/sources/astral.md), published 2026-11-23, 7 min read, How-to. Original: [https://astral.sh/blog/securing-from-supply-chain-attacks](https://astral.sh/blog/securing-from-supply-chain-attacks)

## Summary

Hash-pinning is the core defense against compromised maintainer accounts or hacked distribution servers, because version pins alone fail when PyPI files can be added post-release and GitHub Action tags can be force-pushed. Concrete hardening steps for Python projects on GitHub: pin Actions by commit SHA (via pinact, Dependabot or Renovate), verify SHA-256 hashes of downloaded binaries in Bash, Python or TypeScript, use PyPI Trusted Publishing over OIDC, require approvals on release environments, and lint workflows with zizmor. With uv, add dependency cooldowns via exclude-newer, lock CI tools as dependency groups and run them with UV\_LOCKED, lock PEP 723 scripts, and set no-build to avoid executing source-distribution build backends.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Supply chain security](https://swe.quest/tags/supply-chain-security.md) (Security)
- [Python](https://swe.quest/tags/python.md) (Languages)
- [CI/CD](https://swe.quest/tags/ci-cd.md) (Reliability & operations)
- [Build systems](https://swe.quest/tags/build-systems.md) (Engineering practices)

## Prerequisites

- GitHub Actions workflows ([easy posts on CI/CD](https://swe.quest/tags/ci-cd.md?difficulty=easy))
- Python packaging and PyPI ([easy posts on Python](https://swe.quest/tags/python.md?difficulty=easy))
- dependency lockfiles

## Keywords

uv, GitHub Actions, PyPI Trusted Publishing, zizmor, pinact, Dependabot, Renovate, PEP 723

## Related posts

- [Defending Your Software Supply Chain: What Every Engineering Team Should Do Now](https://swe.quest/articles/defending-your-software-supply-chain-what-every-engineering-team-should-do-now-434c4d75b0885a00.md): Docker · 2026-04-02 · Medium · 9 min read · Supply chain security, CI/CD, Containers, AI agents
  Recent supply chain compromises (the axios npm hijack attributed to Lazarus Group, the TeamPCP campaign via Trivy's GitHub Action, Shai-Hulud, GlassWorm) share one root cause: implicit trust in mutable tags, broad long-lived tokens and unsandboxed runners.
- [Dependency prefixes are a supply chain risk: let's fix them](https://swe.quest/articles/dependency-prefixes-are-a-supply-chain-risk-let-s-fix-them-9228bb37d2c90199.md): Sourcegraph · 2026-05-22 · Medium · 5 min read · Supply chain security, JavaScript, Build systems, Refactoring & migrations
  SemVer range prefixes like ^, ~ and wildcards in package.json act as a trust policy that lets compromised or hijacked packages flow into CI and production on the next install.
- [Protecting your Supabase projects from npm supply chain attacks](https://swe.quest/articles/protecting-your-supabase-projects-from-npm-supply-chain-attacks-fac18687d5c6f3f1.md): Supabase · 2026-05-26 · Medium · 8 min read · Supply chain security, JavaScript, CI/CD, AI for coding
  npm supply chain attacks reach Supabase users through three common paths: maintainer compromise, typosquatting (including a real \`supabase-javascript\` package and AI-hallucinated names), and build pipeline compromise like the TanStack attack via \`pull\_request\_target\` and a poisoned Actions cache.
- [Our response to the TanStack npm supply chain attack](https://swe.quest/articles/our-response-to-the-tanstack-npm-supply-chain-attack-a4ee1bd194da9989.md): OpenAI · 2026-05-13 · Easy · 6 min read · Supply chain security, Incidents & postmortems, JavaScript, CI/CD
  Two OpenAI employee devices were compromised via the malicious TanStack npm package in the Mini Shai-Hulud supply chain attack, leading to credential-focused exfiltration from a limited set of internal repositories that held code-signing certificates for iOS, macOS and Windows apps.
- [Securing the Docker MCP Catalog: Commit Pinning, Agentic Auditing, and Publisher Trust Levels](https://swe.quest/articles/securing-the-docker-mcp-catalog-commit-pinning-agentic-auditing-and-publisher-91efbeaa90e18d9c.md): Docker · 2025-12-03 · Medium · 8 min read · Supply chain security, AI agents, Sandboxing & isolation, Containers, CI/CD
  Docker's MCP Registry now pins every Docker-built MCP server to a specific Git commit, enforced in CI and propagated to the org.opencontainers.image.revision label, so builds are deterministic and verifiable with docker inspect or cosign.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
