DEV Community

Cover image for 55 minutes: Microsoft's agent library was hijacked on PyPI
frank chu
frank chu

Posted on

55 minutes: Microsoft's agent library was hijacked on PyPI

55 minutes: Microsoft's agent library was hijacked on PyPI

55 minutes. That is how long two poisoned versions of Microsoft's agent-framework sat on PyPI on November 17 — long enough to steal credentials from anyone who installed or upgraded in that window, and short enough that most people will never know they were exposed.

Versions 1.26.1 (uploaded 20:35 UTC) and 1.26.2 (21:08 UTC) were repackaged from the legitimate 1.26.0 wheel and published through the project's real publishing identity. They were not typosquats. A pinned package name, a trusted publisher, and a lockfile all pointed straight at them. By roughly 21:30 UTC both were gone from the index. Wiz, which reported the releases to Microsoft the same day, says the attacker "appears to have compromised a client certificate and private key for Microsoft ESRP" — the release and signing path, not the git history. Microsoft's own source tree is clean.

The payload runs before your code does

Both wheels added a .pth file — agent_framework_meta.pth in 1.26.1, af_runtime_diag.pth in 1.26.2 — alongside a small Python module. A .pth file is not a dependency, a plugin, or an import. CPython executes lines starting with import in .pth files at every interpreter start, in every environment where the package is installed. No import needed. No import agent_framework needed. You just run python.

I verified that part myself, because it is the part that sounds too easy to be true. In a fresh venv I dropped in a one-line .pth file that writes a marker file, then ran Python with a -c that imports nothing:

$ python -m venv demo-venv
$ cat demo-venv/lib/python3.12/site-packages/evil.pth
import pathlib; pathlib.Path("/tmp/pwned-by-pth.txt").write_text("ran at interpreter startup, no import needed")

$ ./demo-venv/bin/python -c "print('hello from a clean -c')"
hello from a clean -c
$ cat /tmp/pwned-by-pth.txt
ran at interpreter startup, no import needed
Enter fullscreen mode Exit fullscreen mode

The marker appeared. My -c never imported anything — the .pth hook ran first. (One nuance worth recording: python --version did not trigger it, because --version exits before site initialization. Every real run does.)

The real payload did considerably more than write a marker. Per the OSV advisory (PYSEC-2026-4388, published 2026-11-17T23:18:29Z), it forked a background process that collected environment variables matching TOKEN, SECRET, KEY, AZURE, AWS, GITHUB, OPENAI, and CI names; credential files including ~/.azure, pip.conf, .npmrc, .netrc, .git-credentials, Docker config, the Hugging Face token file, Azure DevOps agent .credentials, and .env files under /app and /workspace; secrets from other processes via /proc/*/environ; Azure DevOps OIDC tokens; and Azure managed-identity tokens for ARM, Graph, Key Vault, Storage, ACR, Azure DevOps, and AzureADTokenExchange, plus instance metadata. Version 1.26.2 added GitHub Actions OIDC token theft and runner temp files. Everything was zlib-compressed, base64-encoded, and POSTed to a webhook.site endpoint. The webhook's counter recorded 50 requests.

What I checked after the fact

PyPI JSON API, agent-framework, checked Nov 19:
  latest version:  1.26.0
  releases named 1.26.x:  ['1.26.0']     <- 1.26.1 and 1.26.2 are gone entirely, not yanked

GitHub API, checked Nov 19:
  microsoft/agent-framework  -> HTTP 404
  microsoft/onnxruntime      -> HTTP 404
Enter fullscreen mode Exit fullscreen mode

The versions were deleted from PyPI outright — there is nothing to yank, and nothing to diff against unless you kept the wheel. The two wheel hashes, if you want to grep your caches: 1.26.1 d27fa34414e6201d5e03e559ef634f020057554d7b3f4898dd5d7cd3e989e110, 1.26.2 3d20a8bc91351a9a16b6db243b848ceca0206b7a8623b02d2af553a9c9f7e0a9.

The GitHub 404s are the stranger part. Eight Microsoft repositories — onnxruntime, onnxruntime-genai, onnxruntime-extensions, three more onnxruntime-* support repos, the Swift package repo, and agent-framework itself — went unreadable on November 17 and were still 404 when I checked on November 19. Microsoft told The Register on November 18 at 17:23 UTC that it has "made some repositories private," and neither Microsoft nor researchers have linked the ONNX repos going private to the malware campaign. The timing is suggestive and the causal link is unestablished; both of those things are true at once. I am not going to fill that gap with a guess.

The check that actually matters

If you installed or upgraded agent-framework on November 17, do not trust the version number. Check for the files:

site-packages/agent_framework_meta.pth
site-packages/agent_framework_meta/_telemetry.py
site-packages/af_runtime_diag.pth
site-packages/af_runtime_diag.py
Enter fullscreen mode Exit fullscreen mode

If either pair is present, the environment is compromised: rotate every credential that environment could see — and that list is long, because the stealer read other processes' environments too, not just its own. Version 1.26.0 is clean, and that is the version PyPI serves now.

The uncomfortable lesson is not "don't trust PyPI." It is that the trust signals we actually rely on — the package name, the publisher identity, the lockfile — were all intact here. The attack went through the signing and release path, the one place where "trusted publisher" stops being a defense and becomes the vulnerability. A .pth file is a 30-year-old feature doing exactly what it was designed to do. The only thing that would have caught this in the window was noticing that a wheel appeared 33 minutes after the previous one, with no corresponding commit. Nobody watches for that. Now somebody should.

Sources: OSV, PYSEC-2026-4388 (published Nov 17, 2026); Wiz, "Malicious version of Microsoft's agent-framework published to PyPI"; AI Brief, "fifty-five minutes on PyPI" (Nov 19, 2026 — upload times 20:35/21:08 UTC, ~55-minute window, 50 webhook requests, 8 repos unreadable, Microsoft's statement to The Register). PyPI JSON API and GitHub API checked locally Nov 19, 2026; .pth demo run locally in a fresh Python 3.12 venv Nov 19, 2026. The webhook.site URL is defanged in the advisory; I did not fetch it.

Top comments (0)