PyPI Package Hijack Without Repo Changes Exposes Source, Build, and Registry Trust Gaps
The Phantom Commit: How a Trusted Package Turned Hostile Without Touching GitHub When teams look at an incident like the Microsoft Agent Framework package compromise on PyPI, the first instinct is to check git log . The commit isn't there. Pull requests look clean, branch protection hasn't visibly broken, and the repository history ends right where it should—yet versions 1.26.1 and 1.26.2…
The Microsoft Agent Framework package on PyPI was compromised without any changes to its GitHub repository. Versions 1.26.1 and 1.26.2 were uploaded to PyPI and contained code designed to steal cloud credentials when Python started up. This discrepancy between the repository history and PyPI's actual content is not a bug in Git, but a result of how source control and artifact registries interact.
PyPI serves as a storage and distribution service for built archives, rather than mirroring a Git repository. When a release is uploaded, PyPI verifies the presenter's authorization to upload to that project name, but does not unpack the wheel, locate a matching commit hash in an upstream repository, or confirm that every .py file inside the archive corresponds to reviewed source lines.
Upload authority is decoupled from commit history, allowing an attacker with a long-lived PyPI token or compromised build environment to create a malicious wheel and upload it directly to PyPI.
This decoupling creates a direct path from credential compromise to execution. When a developer or automated build runner starts Python, the interpreter reads startup files during site configuration and executes arbitrary code before application code loads. If the attacker's wheel contains a startup hook like a .pth file in site-packages, the attacker can read and transmit cloud secrets from memory or environment state during Python's initialization process.
PyPI's default configuration does not require a verified Git commit or build provenance for every update. While enforcing strict cryptographic linkage across an open ecosystem would introduce friction and break legitimate edge cases, it would also close this security gap. However, leaving provenance optional preserves compatibility and velocity, at the cost of allowing unattested uploads to slip through.
To address this issue, teams should consider using OIDC Trusted Publishing with provenance attestations for publishers, and pin exact versions with cryptographic hashes using the --require-hashes flag when consuming packages in production or agent environments. Additionally, it is advisable to avoid trusting unpinned pip install by default, instead adopting a more cautious approach to package updates.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.