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

464 Upvotes

57 comments sorted by

View all comments

27

u/kyngston 15d ago

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

55

u/Smallpaul 15d ago

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

5

u/RedEyed__ 15d ago

Something like ssh-agent

1

u/Dogeek Expert - 3.9.1 14d 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.

2

u/Smallpaul 14d 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 15d ago

oauth

25

u/Smallpaul 15d 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 15d 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 15d 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 15d ago edited 15d 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 15d 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 15d 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 14d 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 14d ago edited 14d 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 14d 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 14d ago

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

1

u/Smallpaul 14d ago

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

→ More replies

3

u/ePaint 15d ago

And for service accounts?