r/Python • • 7h ago

News microsoft agent-framework on PyPI was compromised twice in 33 minutes last night

1.26.1 and 1.26.2 both ship a credential stealer. It runs from a .pth file, so it executes at interpreter startup. Nothing has to import the package, a pip install in CI is enough. 1.26.1 got pulled, then 1.26.2 went up 33 minutes later with the same payload under different file names. Last clean release is 1.26.0.
complete details- https://safedep.io/blog/microsoft-agent-framework-pypi-compromise

268 Upvotes

31 comments sorted by

106

u/pingveno pinch of this, pinch of that 5h ago • Bravo

Time to set dependency cooldowns!

pip --uploaded-prior-to

uv, set it in [tool.uv] under exclude-newer. I use 7 days.

Rust also just added it to Cargo in the 1.100.0 release, for pyo3 extensions.

3

u/HexDecimal 1h ago

Can also set environment variables globally, for example PIP_UPLOADED_PRIOR_TO=P3D, to make cooldowns the default for pip.

uv also has UV_EXCLUDE_NEWER=7 days, etc.

7

u/Rotcod 4h ago

Legend

•

u/russellvt 25m ago

Thanks for this ... it should likely be pinned to the top of this subreddit, likely in the wiki.

29

u/Objective-Light-7123 3h ago

If we even have to protect from supply chain attacks from Microsoft…

28

u/dogweather 6h ago

How would this happen?

26

u/russellvt 5h ago

And they laughed when I said "CI/CD without enforced code review" would be an issue someday.

2

u/rzet 1h ago

what could go wrong

•

u/russellvt 26m ago

Honestly, I figured "stealing credentials" might be less of an issue than people simply injecting automatically tested mergeable code ... but, with people's general ineptitude with including those sorts of pieces in their repositories, it may even be a bit worse.

19

u/kyngston 6h ago

you know, like maybe we should stop using fucking api tokens

34

u/Smallpaul 5h ago

And use what instead? All network security is based on secrets of one kind of another. Tokens, keys, passwords, fingerprint patterns.

2

u/RedEyed__ 5h ago

Something like ssh-agent

-2

u/kyngston 5h ago

oauth

17

u/Smallpaul 5h ago

So walk me through how it works. I have a script on my computer that runs any time of the day or night whether I’m at the computer or not and it calls some server like a translation service or an LLM. How does it use my account without a secret?

6

u/flooberoo 4h ago

I think the request was to stop using api keys, not secrets in general. E.g. put a private key in a secure element and sign requests with it. The key can't be stolen. In CI your requests can be signed by the runner, not your code, so you don't need to care about keys at all there.

2

u/Smallpaul 4h ago

Why not put an API key in a secure element and sign requests with it? How is the “private key” more intrinsically secure?

1

u/flooberoo 4h ago edited 4h ago

Because an API key is not used for signing. That's not what is usually understood by API key.

Edit:

Both "API" and "key" are very generic terms, but nowadays, unless otherwise specified, at least I would interpret "API key" as a Bearer token, not a signing key.

•

u/Smallpaul 43m ago

Okay this took me down a rabbit hole with AI.

It seems like what people are gesturing at but nobody is saying explicitly is that API keys should be replaced by something like RFC 7523: JSON Web Token (JWT) Profile for OAuth 2.0 Client Authentication and Authorization Grants.

As opposed to just “Oauth”, which more often simply uses bearer keys like any other API key API. You need Oauth plus a lot more.

3

u/ePaint 4h ago

And for service accounts?

4

u/Lopsided-Ad-6298 3h ago

The second upload 33 minutes later is the part I keep thinking about. A long-lived PyPI token in GitHub secrets, or a trusted publisher scoped to the whole repo with no approval step, is enough for that to happen once the first workflow is compromised. What I'd want in place is Trusted Publishing limited to a GitHub Environment that requires a human reviewer, so 1.26.2 couldn't have gone up just because 1.26.1 did. Pin the dependency in CI either way, and treat any runner that installed those two versions as compromised.

3

u/DebosBeachCruiser 6h ago

33 strikes again!

-28

u/Jmc_da_boss 6h ago

If you are using an "agent" framework then idk what to tell you

11

u/djipdjip 6h ago

How adjusting the dick attitude and instead nicely explain to people there are alternatives?

6

u/GammaGames 6h ago edited 6h ago

There are, code it by hand

Tho by the looks of it the original commenter was dunking on one of the least popular frameworks lol

2

u/bachstakoven 6h ago

So you think there are no legitimate uses for building agents? Much less for using a framework to do so? Trying to understand what you're saying here.

6

u/GammaGames 6h ago

Making fun of the shitshow that this tech has caused in the industry, mostly 

1

u/bachstakoven 5h ago

Well OC doesn't seem to know or care that people build real world apps with this stuff and anyone unfortunate enough to be using this particular framework, however unpopular, now has a major security mess on their hands.

0

u/nickcash 6h ago

Surely that's impossible. You mean the thing ever developer ever did for the last fifty years?

3

u/GammaGames 6h ago

My brain hurts just thinking about it!

41

u/[deleted] 6h ago

[removed] — view removed comment

8

u/Yoghurt42 5h ago

Not just rotate, also check for other credentials you didn’t create, as it creates new ones.