Application Security

PyPI's Trusted Publishers Flaw: A New Vector for Python Supply Chain Attacks

By ScanLabs AI Security Team
November 23, 2026
5 min read
Back to Hub
PyPI's Trusted Publishers Flaw: A New Vector for Python Supply Chain Attacks — Application Security illustration | ScanLabs A
Intelligence Brief

The Python Package Index (PyPI), a cornerstone of the Python ecosystem, recently rolled out its "trusted publishers" feature, an initiative designed to enhance security by eliminating the need for long-lived API tokens. This move aimed to leverage OpenID Connect (OIDC) for more secure, short-lived credential exchange, particularly for automated publishing via platforms like GitHub Actions. However, as meticulously detailed by Michał Górny in his October 27, 2026, Gentoo blog post, this well-intentioned security upgrade harbors a critical design flaw. The issue stems from PyPI's current implementation failing to correctly validate GitHub repository identifiers during OIDC assertions, opening a significant new vector for supply chain attacks through package hijacking. This vulnerability could allow malicious actors to impersonate legitimate publishers and inject malicious code into widely used Python packages, impacting potentially millions of users.

The Promise of Trust, Undermined by Implementation

For years, a persistent security challenge in software supply chains has been the management of API tokens and secrets. Often stored in Continuous Integration/Continuous Deployment (CI/CD) environments, these tokens, if compromised, grant attackers direct access to publishing mechanisms, enabling them to push malicious updates. PyPI's "trusted publishers" feature sought to address this by adopting OIDC, a standard for federated authentication. The principle is sound: instead of a static token, a CI/CD workflow (e.g., a GitHub Action) would request a unique, short-lived OIDC token from GitHub. This token, containing verifiable claims about the repository and its owner, would then be presented to PyPI. PyPI would, in turn, validate the token with GitHub and, if the claims match a pre-configured trusted publisher, allow the upload.

The core of the problem, as highlighted by Górny, lies in PyPI's validation logic. While PyPI's configuration expects a specific owner/repository-name pair for a trusted publisher (e.g., gentoo/gentoo), its OIDC assertion processing logic reportedly fails to adequately differentiate between repositories that share the same name but belong to different owners. GitHub, by design, allows multiple users or organizations to have repositories with identical names (e.g., user-A/my-project and user-B/my-project can both exist). The OIDC token issued by GitHub correctly includes the full repository_owner/repository_name claim. The failure occurs because PyPI's backend, when evaluating the OIDC token against its trusted publisher list, is not sufficiently stringent in comparing the full owner/repository-name asserted by GitHub with the full owner/repository-name configured by the legitimate package maintainer.

The Mechanics of a Naming Catastrophe

This oversight creates a straightforward, yet devastating, attack vector. Consider a legitimate Python package, some-package, maintained by project-owner in their GitHub repository project-owner/some-repo. The maintainer configures some-package on PyPI to trust project-owner/some-repo as a publisher via the new OIDC mechanism.

Here's how a malicious actor, malicious-actor, could exploit this:

  1. Reconnaissance: The attacker identifies a target package (some-package) and its legitimate GitHub repository (project-owner/some-repo).
  2. Repo Creation: The attacker creates a new GitHub repository under their own account with the same name as the legitimate repository, for instance, malicious-actor/some-repo. This is perfectly permissible on GitHub.
  3. Malicious Workflow: The attacker sets up a GitHub Actions workflow within malicious-actor/some-repo designed to publish a malicious version of some-package to PyPI.
  4. OIDC Assertion: When this malicious workflow attempts to publish, GitHub issues an OIDC token containing claims such as repository_owner: malicious-actor and repository_name: some-repo.
  5. PyPI Validation Failure: Because PyPI's validation logic does not adequately verify the repository_owner portion of the claim against the project-owner configured for some-package, it might incorrectly perceive the malicious-actor/some-repo as the legitimate project-owner/some-repo due to the matching repository_name.
  6. Package Hijacking: The malicious actor successfully publishes a new, compromised version of some-package to PyPI, overwriting the legitimate package.

This attack directly leverages the weakness in trust delegation, effectively bypassing the intended security benefits of OIDC. It aligns with the MITRE ATT&CK technique T1195.002: Supply Chain Compromise: Compromise Software Supply Chain, specifically targeting the integrity of upstream software components. The consequence is immediate: any user installing or updating some-package would inadvertently download and execute the attacker's malicious code.

Broader Implications for the Python Ecosystem

The implications of this flaw extend far beyond individual packages. PyPI serves as the central hub for Python package distribution, and a vulnerability of this nature shakes the foundational trust in the supply chain. The Python ecosystem, like many others, has increasingly grappled with supply chain security challenges, from the widespread impact of Log4j to the sophisticated SolarWinds attacks. This PyPI issue demonstrates that even well-intentioned security improvements can introduce new vulnerabilities if not meticulously implemented.

The difficulty in detecting such an attack is particularly concerning. From PyPI's perspective, the malicious publish appears to originate from a "trusted" source, making it indistinguishable from a legitimate update without deeper inspection. For package consumers, the malicious version would simply appear as the latest release. This could lead to widespread compromise before the issue is identified and remediated, making the threat particularly insidious. The move towards "shift left" security, emphasizing security early in the development lifecycle, is undermined when core infrastructure components exhibit such fundamental design flaws.

Mitigating the Risk: Recommendations for Defenders

Addressing this vulnerability requires immediate action from PyPI, along with proactive measures from package maintainers and consumers.

For PyPI: The most critical step is to rectify the OIDC validation logic. PyPI must ensure that when evaluating a

Check your own site

Reading about these risks is one thing; knowing whether your own website is exposed is another. Run a free security scan with ScanLabs AI to check your site for the issues covered here and get a clear, prioritised report of what to fix.


Source: blogs.gentoo.org — this analysis is based on reporting from blogs.gentoo.org.

Related reading

#cybersecurity#security#aws#exposed#conti#bec#attack#development

Related articles

ScanLabs AI Security Team

Researched and written by the ScanLabs AI Security Team — the researchers behind ScanLabs AI, an automated website security scanner that checks sites against thousands of known vulnerabilities and the OWASP Top 10. Our team tracks emerging threats daily to help businesses find and fix exposures before attackers do. Articles are AI-assisted and reviewed for technical accuracy.

Run a free security scan