r/Python • u/enterthearena44 • 5d ago
Discussion Microsoft's PyPI package got compromised without a GitHub code change. How is this even possible?
I was reading about yesterday's Microsoft Agent Framework security incident, and something caught my attention.
Apparently, attackers published two malicious versions (1.26.1 and 1.26.2) of Microsoft's official Python package on PyPI. These versions could steal cloud credentials just by starting Python.
Both versions were removed quickly.
What surprised me was that the malicious code wasn't even checked into Microsoft's GitHub repository.
From what I understand:
- Developers write code in GitHub.
- CI/CD builds it into a Python wheel (.whl).
- The wheel gets published to PyPI.
- When we run "pip install", we download that package.
But apparently, someone with the right publishing credentials can upload a malicious wheel directly, without going through the original GitHub repository.
That raises some interesting questions:
How does PyPI verify that a package actually came from the legitimate source code and CI/CD pipeline?
Why isn't a verified GitHub commit or build provenance mandatory for publishing updates to established packages?
If publishing credentials are compromised, what prevents attackers from distributing malicious versions under trusted package names?
Would mandatory attestations, release signing, or an approval process have prevented this?
What protections should developers realistically use beyond simply trusting "pip install"?
I'm still learning about software supply-chain security, so I'd love to hear how experienced Python developers and security engineers think this should work.
87
u/aplarsen 5d ago
PyPI is older than Github. It's older than Git itself.
35
u/Gamecrazy721 5d ago
I expected you to be wrong about this but nope, Torvalds first released git in 2005 and pypi has been around since 2003.
2
44
u/XNo_Notes It works on my machine 5d ago
PyPi is a repository itself. You can upload strait from your terminal if you have the access token associated with the account there. Github is a completely separate entity.
20
u/hstarnaud 5d ago edited 5d ago
"Developers write code in GitHub". That's not quite it, GitHub is just one tool amongst many to publish code. It just happens to be a popular tool.
The criteria to know what is the legitimate source code is the private key / login credentials of the publisher.
Why isn't a verified GitHub commit mandatory? GitHub is just a different organization, they have nothing to do with pypi's criteria for what is a legitimate commit the source code could be hosted exclusively on pypi or anywhere else for that matter. Git (the open source tool used by GitHub and most repo platforms) is a tool to version code, there is a way to sign commits to authenticate who wrote them, but in the end, if you have a private key to log in to pypi authenticated as an authorized publisher, why should they care if you sign your commits or not, you are signed in as the administrator, it's your repository, you manage the content.
Publishing credentials is essentially what prevents attackers to distribute malicious versions in a trusted package. It's like asking, if someone stole the key to your house, what prevents them from opening it. You have maybe cameras or alarm systems but it doesn't prevent anyone from unlocking the door and going in.
what you are asking is essentially the same thing as saying, would authenticating with a private key prevent this. Yes, that's already the case. Should we require two keys to sign in rather than one? Yeah they probably have two factor authentication. Should we have a third factor in the authentication? I mean... You get it
What protections should developers use is a very interesting question deserving a more lengthy answer:
First thing, adopt a policy to never install things published less than one week ago, most vulnerabilities are detected rapidly. Most package manager support applying a configuration to do that.
use lock files instead of continuously updating versions
audit your dependencies using reputable auditing tools. Do so every few weeks in an automated way and verify when updating versions
move off abandoned packages
least privileged principle, don't run as admin a script that doesn't need to be admin
data segregation, store your data out of access of machines that run applications that don't need this sensitive data.
10
u/FastRunningMike 5d ago
"What protections should developers realistically use beyond simply trusting "pip install"?"
>> To answer this question: Always perform a SAST scan before installing or using ANY Python package. Never ever use pip install on anything before validating. PyPI does not validate weaknesses in the packages.
A package being available on PyPI does not mean that the package has been security-audited or that its content can be trusted. There is an important distinction between package availability, artifact integrity, artifact provenance, and software trustworthiness. [2]
A quick look at version 1.3(may 2026) reveals a very concerning Python package from a security point of view, already full of weaknesses that are very hard to mitigate in a decent way. E.g. lines like:
- result = subprocess.run(command, cwd=WORKSPACE_ROOT, check=False)
When using the subprocess library, Python code can invoke arbitrary external executables on the host system.
- getattr(importlib.import_module(IMPORT_PATH), name)
Allowing dynamic module imports makes it easy for attackers to execute arbitrary code.
I count 41 places where importlib.import_module occurs. Anyone who checked this package beforehand with a simple good Python SAST [1] that works directly on PyPI packages should think again before using it.
[1] E.g. https://pypi.org/project/codeaudit/
12
u/MrSlaw 5d ago
Essentially just described a list of reasons why people (and especially corporations) should be using trusted publishing for automated releases.
Prevents a rogue API key spoiling your day at least
18
4
u/DigThatData 4d ago edited 4d ago
How is this even possible?
...
someone with the right publishing credentials can upload a malicious wheel directly
bro you answered your own question.
the unasked question you should be asking here is "what could microsoft have done differently to prevent this?" and the answer to that is they should be regularly cycling their credentials. If they're already doing that, perhaps they could have increased the cycling schedule in light of the recent wave of CVEs.
We (the public) don't and probably will never know how the credentials were exposed, so we can't know if there are other mitigations that might have helped. For example, if this was an insider threat, then the appropriate mitigation might not even be on the engineering side at all but rather HR's responsibility.
2
u/blbd 4d ago
It can't besides M2M and human auth credentials that can be pwned.
Because there are zillions of packages with zillions of repo styles and the repo is sometimes pwned instead of the M2M credentials anyways.
Nothing.
Code signing can make it easier to revoke but code signing certs and signed code get pwned in Windows all the time.
Supply chain, dependency, and SBOM security checkers like GitHub Dependabot and their other security tools.
3
u/reluactivations 5d ago
a `.pth` file that runs before you even import anything. supply chain said "no need to call me, I'll let myself in"
1
u/Physical-Court-7453 4d ago
one thing worth adding for the "what can devs actually do" part: this one ran from a .pth file, so it fired on every python start, no import needed. and it went after CI stuff, pipeline OIDC tokens and managed identity tokens. cooldowns and lockfiles stop you installing it, but if something slips through anyway, it can steal whatever that process can reach
so on the CI side, split your jobs. the step that runs pip install and tests shouldn't have the same identity or token permissions as the step that deploys. on a dev machine, short-lived logins beat credential files sitting in your home dir
also a quick check you can run on any env: list the .pth files in site-packages. most envs only have a couple of known ones (setuptools' distutils-precedence.pth, editable installs), so anything random in there is worth a look
1
u/hornetmadness79 4d ago
I think you're overthinking this. Not everything has to be in GitHub and go through a cicd pipeline. It could be something as simple as a developer typing UV and then uploading the resulting wheels. Your idea of supply chain is more of a contrived idea around that basic process.
0
-2
u/poppy_92 4d ago
Why isn't there a post on DPO on this? The newly elected PPC along with PSRT teams should be looking at these with high priority.
-7
u/real_carddamom 5d ago
Believe in this time and age Github sucks... It is only a frontend or sink for Copilot and company, which is sad
0
4d ago
[deleted]
1
u/MustaKotka 4d ago
Provenance is the name of being able to trace back the path to current state from another prior state while being able to name the involved entities along the way. It's not an em dash. It's an actual word with a unique meaning. Rarely needed but absolutely necessary when needed.
1
u/cunningjames 4d ago
Provenance is an actual word that, yes, gets used in real life occasionally. This post does not especially ping my AI-dar overall, lacking the usual tells.
3
5d ago
[removed] — view removed comment
5
u/damesca 5d ago
Hash pinning doesn't help here.
6
u/OkCardiologist8006 5d ago
for this incident yeah, it was new version numbers, so an exact version pin in a lockfile is what actually protected people.
hash pinning isn't useless against a stolen token though. pypi won't let you reuse a filename, but it does let you add new files to an existing release, so an attacker could upload an extra wheel with a more specific platform tag under an old version and pip might prefer it. `--require-hashes` (or a uv/poetry lockfile, which records hashes) catches that.
1
221
u/Deto 5d ago
It's always worked like that. You don't have to publish directly from GitHub. You can just publish from your source directory on your machine.
Yes if the publishing key is compromised this means you're in trouble.
They probably don't want to require a GH commit because that would force all devs to use GitHub. You could imagine supporting a few alternatives but all that puts more burden on the pypi devs and the package repo is maintained on a shoestring budget.
One things devs can do is require a version to be live for a certain amount of time before it is used in code. Basically relies on the fact that these things are usually caught within a day or two. It's not perfect because still some people will have to get affected.