r/Python • • 4d 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

446 Upvotes

58 comments sorted by

216

u/pingveno pinch of this, pinch of that 4d 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.

25

u/HexDecimal 4d 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.

1

u/zurtex 3d ago

FYI uv and pip (26.1+) both accept the same PnD syntax, so you can use P3D or P7D for both.

6

u/russellvt 3d ago

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

3

u/pingveno pinch of this, pinch of that 3d ago

Your comment made me think of making a website, but of course someone already did that.

1

u/russellvt 3d ago

Yeah, I'm sure there's quite a few of them... but, I'm not looking for "a website" or blog - just an easy reference / FAQ here (for now).

8

u/Rotcod 4d ago

Legend

2

u/UloPe 3d ago

And then you get hit with a zero day.

Damned if you don’t, damned if you do…

1

u/pingveno pinch of this, pinch of that 3d ago

Most have an escape hatch, if you need a specific package to be updated. So with uv, if you needed the latest certifi:

[uv.tool.exclude-newer-package]
certifi = false

1

u/UloPe 3d ago

Unless you can see the future I don’t understand how this would help.

1

u/pingveno pinch of this, pinch of that 3d ago

Turn it on temporarily if you need to pull in a package because of a CVE. Unless you're saying literally a zero day? But that's irrelevant, but zero days by definition don't have a fix out.

64

u/Objective-Light-7123 4d ago

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

41

u/dogweather 4d ago

How would this happen?

69

u/russellvt 4d ago

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

6

u/rzet 4d ago

what could go wrong

3

u/russellvt 3d 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.

1

u/Valcorb 3d ago

In case of a dependency version upgrade, Is it the reviewer's responsability to track if the new version is a compromised one? I wouldnt blame this on AI code review, its a bad setup if your project instantly updates to the newest versions without an age or confidence check

1

u/russellvt 3d ago

I think you misunderstand "code review" and where it's mostly useful/applicable.

This is why there's code coverage tests, and why those branches should generally be locked from anyone that's not a core contributor... not to mention, the master branch as a whole.

TLDR; Test Driven Development is truly "the future" - and a key trait of old senior developers.

This is doubly true for people who support key modules.

13

u/Lopsided-Ad-6298 4d 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.

27

u/kyngston 4d ago

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

53

u/Smallpaul 4d ago

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

4

u/RedEyed__ 4d ago

Something like ssh-agent

1

u/Dogeek Expert - 3.9.1 3d ago

Token exchange for automated builds, which is what NPM does, and enforces, specifically because it got hit so much with supply chain issues.

Username / Passwords with 2FA for regular user logins.

It makes it more secure, but if github's (or any other CI provider) private signing key gets owned, then all packages published through them is vulnerable again. In the end, you have to trust someone though.

The alternative is probably to use pure git for dependency management, pinned with a SHA, but updating the dependency becomes even more of a chore. As with anything in security, it's a tradeoff between security and convenience.

1

u/Smallpaul 3d ago

I think we are talking about arbitrary API tokens. For Google maps or twilio or whatever. These supply chain attacks can steal them.

-7

u/kyngston 4d ago

oauth

25

u/Smallpaul 4d 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 4d 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.

4

u/Smallpaul 4d ago

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

2

u/flooberoo 4d ago edited 4d 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.

2

u/Smallpaul 3d 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.

1

u/kyngston 3d ago

you could google oauth…

you login once to get an access token and refresh token

access token is good for 1 hour, refresh token good for 90 day

script uses access token to log in

if the access token is expired, it uses the refresh token to refresh both tokens

stolen access token expires in one hour, as opposed to an api token which lasts forever

0

u/Smallpaul 3d ago

Who is the “you” in the case I described? I described a system that runs 24/7 without me around. So a hacker steals the access token and refresh token using a supply chain attack.

If I can run MY system 24/7 from those two tokens then why can’t they run THEIR system 24/7 from the same tokens?

0

u/kyngston 3d ago edited 3d ago

you as in smallpaul. if you did google it, you would learn about refresh token replay detection

look at you downvoting someone explaining something you know nothing about…

1

u/Smallpaul 3d ago

You are quite an unpleasant person aren’t you.

How can you guarantee who will use the token first and who will be considered the replayer?

1

u/kyngston 3d ago

again if you googled, you would learn that both get revoked.

1

u/Smallpaul 3d ago

So you are saying that my service stops working and that’s a good thing from your point of view?

→ More replies (0)

3

u/ePaint 4d ago

And for service accounts?

4

u/DebosBeachCruiser 4d ago

33 strikes again!

-32

u/Jmc_da_boss 4d ago

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

13

u/djipdjip 4d ago

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

6

u/GammaGames 4d ago edited 4d 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

1

u/nickcash 4d ago

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

2

u/GammaGames 4d ago

My brain hurts just thinking about it!

1

u/bachstakoven 4d 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.

3

u/Jmc_da_boss 3d ago

That is correct, if you need a framework to put an llm in a while loop then i do not know what to tell you other than ngmi

0

u/bachstakoven 3d ago

Ah yes. I suppose you're also the kind of dev who makes requests by carefully assembling bytes onto a raw socket. Let's all bow down before this Real Programmer, we found one in the wild!

Kindly fuck off.

1

u/Jmc_da_boss 3d ago

Get tf out of our online spaces, the competent people are tired of dealing with yall.

0

u/bachstakoven 3d ago

I mean you have laid out your own ignorance for all to see here in your own perfectly vapid "contributions" so I'm not so sure I'd be casting stones.

6

u/GammaGames 4d ago

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

2

u/bachstakoven 4d 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.

41

u/[deleted] 4d ago

[removed] — view removed comment

8

u/Yoghurt42 4d ago

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