Microsoft agent-framework PyPI 入侵對 CI 管線的影響
What the Microsoft agent-framework PyPI Breach Means for Your CI Pipeline
Microsoft 官方 Python 套件 agent-framework 的 1.26.1 和 1.26.2 於 2026 年 11 月 17 日遭未授權上傳至 PyPI,內含可在 Python 啟動時執行並竊取憑證的程式碼。
文章梳理 .pth 啟動機制、兩個惡意版本的差異與 CI 憑證風險,並整理不啟動可疑環境的排查及處置方法。
Image: www.python.org via Wikimedia Commons, public domain
Installing a Python package should not compromise your cloud tenant before you even type an import statement. On November 17, 2026, two unauthorized releases of agent-framework, the official Python package for Microsoft Agent Framework, proved that a 55-minute window on PyPI is plenty of time to harvest build secrets across developer laptops and continuous integration runners.
According to the GitHub Advisory Database entry GHSA-764m-3ppc-5m73 and the Python Packaging Authority advisory PYSEC-2026-4388, versions 1.26.1 and 1.26.2 were uploaded directly under Microsoft's legitimate agent-framework project on PyPI. This was not a typosquatting trick where an attacker registered a lookalike name. Anyone whose dependency resolver pulled the latest version without a strict pin or hash check during that window received repackaged wheels containing an active credential stealer.
With agent-framework pulling almost 200,000 downloads a month according to Wiz's incident write-up, AI engineering teams building on Azure and Python sat directly in the blast radius. Even teams that never deployed an agent to production could have been hit inside a single pull request check or container build.
Why .pth startup hooks bypass normal code review
Most developers expect malicious code in a dependency to trigger only when an application explicitly imports the library. The attacker behind agent-framework 1.26.1 and 1.26.2 avoided that delay by abusing Python's .pth path configuration mechanism inside site-packages.
Whenever a Python interpreter initializes, it automatically scans site-packages for .pth files and executes any line starting with import. Because pip itself runs on Python, installing the wheel or running a follow-up pip show command inside the same virtual environment is enough to fire the payload. Even an unrelated build script, pytest runner, or linter running in that container triggers the stealer.
In release 1.26.1, published at 20:35 UTC (15:35 EST) on November 17, the wheel dropped agent_framework_meta.pth and modified agent_framework_meta/__init__.py to launch agent_framework_meta/_telemetry.py. Thirty-three minutes later, at 21:08 UTC (16:08 EST), version 1.26.2 arrived after 1.26.1 was pulled. In 1.26.2, the attacker restored the clean __init__.py from 1.26.0 and moved the startup trigger to af_runtime_diag.pth and af_runtime_diag.py. Teams searching only for the 1.26.1 filenames miss 1.26.2 completely.
Expand
Microsoft Azure logo, the cloud whose identity endpoints the stealer targeted
Image: Microsoft Corporation via Wikimedia Commons, public domain
Both releases kept the rest of the 1.26.0 codebase intact and preserved the exact agent-framework-core[all]==1.26.0 dependency pin. Applications built on the framework continued to run normally, which masked the compromise during automated test suites. On Linux and macOS, the helper module detaches into a background process using os.fork and os.setsid, sets _AF_TEL=1 so it runs once per process tree, and swallows all exceptions so no stack trace appears in build logs. On Windows, where os.fork is unavailable, the payload runs in a background thread instead, dressed up with a _telemetry module name and an SDK-style HTTP User-Agent.
Comparing the 1.26.0, 1.26.1, and 1.26.2 releases
The differences between the clean 1.26.0 release and the two compromised wheels show how quickly the attacker adapted after PyPI quarantined the first upload.
| Release Version | Publish Time (Nov 17 UTC) | Startup Trigger Files | Target Scope and Exfiltration User-Agent |
|---|---|---|---|
| 1.26.0 | Before Nov 17 | None | Last clean release; not affected |
| 1.26.1 | 20:35 UTC |
agent_framework_meta.pth, _telemetry.py
|
Env vars, 60 files, Azure IMDS, ADO OIDC; af-runtime-diagnostics/1
|
| 1.26.2 | 21:08 UTC |
af_runtime_diag.pth, af_runtime_diag.py
|
Adds GitHub Actions OIDC, /home/runner paths, 80 files; runtime-diagnostics/1
|
This shift from 1.26.1 to 1.26.2 matters for incident responders because the second wheel specifically expanded coverage for GitHub-hosted runners and raised its file collection cap from 60 to 80 files.
What secrets the payload harvests and mints
Static credential scraping is only half of the damage. As detailed in Rescana's technical breakdown of GHSA-764m-3ppc-5m73, the payload actively requests fresh short-lived tokens from cloud and CI identity endpoints before compressing the bundle with zlib, encoding it in base64, and posting it to webhook[.]site/d381fd80-ec62-42ad-8f5c-d1b15103c9bb?t=telemetry.
On an affected host or runner, the stealer collects four categories of sensitive material:
-
Environment and process memory: Every environment variable whose name contains
TOKEN,SECRET,PASSWORD,KEY,AZURE,AWS,GITHUB,HF_,OPENAI,NPM,PIP, orCI_, plus/proc/[pid]/environvalues from up to 300 running Linux processes. -
Local credential files: Cached sessions and tokens from
~/.azure,pip.conf,.npmrc,.netrc,.git-credentials,.docker/config.json, Hugging Face token paths, Azure Pipelines agent.credentials, and.envfiles under/appand/workspace. -
Azure DevOps and managed identities: An OIDC token request to
SYSTEM_OIDCREQUESTURIauthenticated withSYSTEM_ACCESSTOKEN, alongside Azure Instance Metadata Service (169.254.169.254) and App ServiceIDENTITY_ENDPOINTrequests covering 12 Azure resource audiences including Azure Resource Manager, Key Vault, Microsoft Graph, Storage, and Container Registry. -
GitHub Actions runners (1.26.2 only): OIDC tokens for
api://AzureADTokenExchangeandmanagement.azure.comviaACTIONS_ID_TOKEN_REQUEST_URLandACTIONS_ID_TOKEN_REQUEST_TOKENin workflows withid-token: write, plusACTIONS_RUNTIME_TOKENand files under/home/runner.
Where an Entra ID federated credential trusts a GitHub Actions workflow or an Azure DevOps service connection, those minted OIDC tokens can be exchanged for live Azure access without any static secret stored on disk. Because ACTIONS_RUNTIME_TOKEN also grants write access to the GitHub Actions cache and artifact services, a compromised job in 1.26.2 could even poison caches consumed by subsequent clean runs.
Researchers could read the attacker's public webhook.site endpoint, and PexLens summarized three confirmed victims in the logged requests. That sounds small, but each request can carry working cloud, CI, and registry credentials, and a free webhook endpoint keeps only a limited log, so not being in that sample does not clear your environment.
How the attacker gained publishing access
Microsoft has not yet published a full root-cause postmortem or an MSRC security advisory detailing how the malicious wheels were signed and uploaded. A Microsoft spokesperson told The Hacker News that the company had made some repositories private while it investigated malicious content.
Independent assessments point to Microsoft's release infrastructure rather than a stray developer password. Wiz assessed that the attacker compromised a client certificate and private key belonging to Microsoft's Engineering System Release Pipeline (ESRP), the internal signing and publishing service used for official releases. According to Wiz, an initial publish attempt from AWS IP space failed due to ESRP IP filtering, whereas a second attempt originating from Microsoft-owned IP space succeeded. As StepSecurity pointed out, 1.26.2 was uploaded after 1.26.1 had already been quarantined, which shows the attacker still held publishing access at that point. BleepingComputer reported that Microsoft had not yet explained how the breach happened.
Why a 55-minute PyPI window creates long-tail exposure
Wiz reported that both malicious versions were removed from PyPI by 21:30 UTC (16:30 EST) on November 17, roughly 55 minutes after 1.26.1 went live. Security teams should not treat that quick takedown as proof that their pipelines escaped untouched.
Internal package proxies, Artifactory or Nexus mirrors, CI build caches, Docker layer caches, and lockfiles generated during that 55-minute window can keep serving 1.26.1 or 1.26.2 days or weeks later. Even if pip now resolves 1.26.0 on a fresh machine, any container image or virtual environment built on or after November 17 could still hold the .pth trigger or have already leaked its build-time secrets.
Expand
Microsoft logo, publisher of the Agent Framework package that was hijacked
Image: Microsoft via Wikimedia Commons, public domain
There is also a subtle trap in how agent-framework declares its dependencies. agent-framework acts as a thin meta-package that pins agent-framework-core[all]==1.26.0, while agent-framework-core uses open upper-bound ranges (typically below 2.0) for 29 sibling packages such as agent-framework-openai and agent-framework-foundry. Pinning only the top-level agent-framework==1.26.0 line in requirements.txt does not lock those sibling packages against future tampering.
How to hunt for exposure without triggering the payload
The first rule of triage is simple: do not run python, pip, or pytest inside a virtual environment or container that might contain 1.26.1 or 1.26.2. Starting the interpreter executes the .pth hook immediately.
Instead, inspect filesystems, container layers, and lockfiles using read-only OS and Docker tools:
- Search Linux and macOS filesystems for both sets of indicators using
find / \( -name agent_framework_meta.pth -o -name af_runtime_diag.pth -o -name af_runtime_diag.py -o -path '*/agent_framework_meta/_telemetry.py' -o -name 'agent_framework-1.26.[12].dist-info' \) 2>/dev/nullacross every virtual environment, conda environment, and self-hosted runner workspace. - Inspect container images built on or after November 17 without starting them by using
CID=$(docker create your-registry/your-image:tag) && docker export "$CID" | tar -t | grep -E 'agent_framework-1\.26\.[12]\.dist-info|agent_framework_meta\.pth|af_runtime_diag' ; docker rm "$CID". - Audit
requirements*.txt,uv.lock,poetry.lock,Pipfile.lock, andpdm.lockfor1.26.1,1.26.2, or the wheel SHA-256 digestsd27fa34414e6201d5e03e559ef634f020057554d7b3f4898dd5d7cd3e989e110(1.26.1) and3d20a8bc91351a9a16b6db243b848ceca0206b7a8623b02d2af553a9c9f7e0a9(1.26.2). - Check DNS, proxy, and firewall logs for outbound POST requests to
webhook.site/d381fd80-ec62-42ad-8f5c-d1b15103c9bbor theaf-runtime-diagnostics/1andruntime-diagnostics/1User-Agents.
Do not stop at checking your own repositories. If third-party vendors or consultancies build AI agents for your organization on Microsoft Agent Framework, ask them to confirm they audited their CI logs, lockfiles, and internal PyPI proxies from November 17 onward.
Remediation, secret rotation, and locking down PyPI
If any machine, container build, or CI runner installed 1.26.1 or 1.26.2, discard and rebuild the environment from a known clean base pinned to agent-framework==1.26.0. Trying to delete .pth files in place leaves behind the risk that another script or cached pip wheel reintroduces them.
Rotate every credential reachable from that environment in order of blast radius. Start with Azure service principals, Entra ID sessions (revoking cached ~/.azure sessions in Entra ID rather than just deleting local files), Azure DevOps personal access tokens and self-hosted agent registrations, and GitHub repository or organization secrets. Follow with PyPI, npm, NuGet, Docker, and Hugging Face tokens, plus any LLM API keys stored in .env files.
Because minted Azure managed identity and OIDC tokens are short-lived but usable until they expire, and you often cannot revoke them individually, review Entra ID sign-in logs, Azure activity logs, and GitHub audit logs from November 17 at 20:35 UTC through the point where the last affected Python process exited and its tokens had expired. Purge CI caches, local pip caches (~/.cache/pip), and internal PyPI proxy caches populated on or after November 17, and block 1.26.1 and 1.26.2 explicitly at your registry proxy.
Finally, adopt two supply-chain controls across Python AI projects: generate full lockfiles with SHA-256 hashes covering agent-framework, agent-framework-core, and all 29 sibling packages, and enforce pip install --require-hashes -r requirements.txt in CI. Adding a short quarantine delay of two to three days on internal PyPI proxies for newly published package versions would also have blocked both malicious wheels automatically while monitoring tools caught and removed them.
Originally published on Mango Developer.
來源:DEV Community · dev.to

