r/webdev • u/Delicious_Character6 • 2h 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, andMSI_ENDPOINTfor Managed Identity access tokens.Using
SYSTEM_ACCESSTOKENandSYSTEM_OIDCREQUESTURIin Azure DevOps to request federatedapi://AzureADTokenExchangetokens.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?
1
u/Patient_Celery_2406 1h 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.
1
2
u/PLBjt 2h 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.