r/Python • u/enterthearena44 • 4d 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.
215
u/Deto 4d 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.
85
u/aplarsen 4d ago
PyPI is older than Github. It's older than Git itself.
43
u/XNo_Notes It works on my machine 4d 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 4d ago edited 4d 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.
10
u/FastRunningMike 4d 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/
[2] https://nocomplexity.github.io/pythonsecurity/pypi-security/#packages-on-pypi-are-not-secure-by-default
12
u/MrSlaw 4d 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
u/Tall-Introduction414 4d ago
Not everyone uses GitHub. I publish to pypi from my terminal with uv.
4
u/DigThatData 3d ago edited 3d ago
...
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 3d ago
3
u/reluactivations 4d 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 3d 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 3d 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
u/habitsofwaste 4d ago
I wonder if this was something to do with the ghostaction campaign n
-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 4d ago
Believe in this time and age Github sucks... It is only a frontend or sink for Copilot and company, which is sad
0
u/[deleted] 3d ago
[deleted] — view deleted comment
3
u/[deleted] 4d ago
[removed] — view removed comment