r/webdev • u/Delicious_Character6 • 12d ago
Microsoft's official agent-framework PyPI package (190K downloads/mo) was compromised with .pth startup hooks — why are we still running AI agents in flat site-packages?
Versions 1.26.1 and 1.26.2 of Microsoft's official agent-framework package on PyPI were hijacked yesterday (published 33 minutes apart) with a credential stealer. PyPI quarantined both releases quickly, but the mechanics of this attack should bother anyone building AI agent runners or Python backends.
The payload didn't wait for import agent_framework. Both wheels dropped .pth files (agent_framework_meta.pth and af_runtime_diag.pth) directly into site-packages. Because Python executes import lines inside .pth files on every interpreter startup, running python, pytest, or even pip itself triggered the stealer in 0 ms—even in projects that never imported the framework. Worse, it still pulled agent-framework-core as a dependency so applications kept running without throwing a single error.
On top of reading static files on disk (.env, .npmrc, pip.conf, .netrc, .git-credentials, .docker/config.json, Hugging Face tokens, and ~/.azure/*.json), the stealer actively minted new cloud credentials at runtime:
- Querying Azure IMDS (169.254.169.254), IDENTITY_ENDPOINT, and MSI_ENDPOINT for Managed Identity access tokens.
- Using SYSTEM_ACCESSTOKEN and SYSTEM_OIDCREQUESTURI in Azure DevOps to request federated api://AzureADTokenExchange tokens.
- Harvesting GitHub Actions OIDC tokens in 1.26.2.
Everything was compressed, Base64-encoded, and POSTed out. Rotating static secrets on disk doesn't cover tokens minted dynamically during a CI run.
We spend weeks arguing about LLM prompt injection guardrails, yet most dev laptops and CI runners still install agent dependencies into flat, unpinned environments with unrestricted outbound network access.
Are you enforcing --require-hashes and strict egress allowlists on your Python agent runners yet, or is everyone still trusting pip install by default?
7
u/Patient_Celery_2406 12d ago
Where does the 190k come from anyway? PyPI download counts include every CI rebuild and mirror pulling the same wheel, so that number says nothing about how many environments actually got the bad versions.
3
u/Ok-Snow-6553 12d ago
This is absolutely terrifying. I'm a solo dev and I've always just trusted
pip installblindly. I never even knew.pthfiles could execute code on startup like that.It feels like keeping up with AI tools is already hard enough, and now we have to worry about supply chain attacks too. Might be time to finally look into
--require-hashesfor my projects.2
u/leweir 11d ago
The .pth trick is a good reason to stop treating the venv as the boundary and treat the whole run as disposable: a fresh container per job, nothing from your home dir mounted, and no long-lived creds on disk to read. Block 169.254.169.254 and the other metadata endpoints from agent containers unless the job actually needs them, because that's what turns a file stealer into a cloud token minter. Pinning with hashes (--require-hashes or a uv lockfile) plus a short wait before adopting new releases would have skipped both bad versions here. It's also worth grepping site-packages for .pth files with import lines now and then, since legit ones are rare.
2
u/Conscious-Part-9303 10d ago
why are we still letting arbitrary .pth files execute in production containers?
2
u/PLBjt 12d ago
The nasty part is the .pth file, not the import. Python runs lines inside those on every interpreter start, so pytest or even pip in that env executes the payload whether your code ever imports the framework or not. I'd pin the wheel by hash and fail the install if a new release adds a .pth you didn't already expect, then glance at site-packages after the fact instead of trusting that you never call the library. The tradeoff is a hash pin means a real security release doesn't land until you bump it, so review the file list diff and not just the changelog.
1
u/Traditional-Hall-591 12d ago
Are we sure AI didn’t put the malware in itself.
1
u/Federal_Dish4057 12d ago
the real lesson is that installing a wheel is already giving it code execution, and .pth files make that painfully obvious, so agents need the same isolation and dependency pinning as any other
1
u/tanyadev4827 12d ago
relevant
1
u/worldgorger1 12d ago
Honestly fuck AI. If you see any posts praising it or glorifying it, please downvote.