blog.rust.gay

Microsoft's agent framework was a supply-chain attack on CI

Microsoft's official agent-framework package on PyPI was compromised in versions 1.26.1 and 1.26.2. The package has nearly 200,000 downloads a month and is used to build and deploy AI agents. According to OX Security and OpenSourceMalware, the malicious versions run when a Python interpreter starts with the package installed, without any import statement. They pull the genuine 1.26.0 release to keep the application working, collect credentials for Azure, Git, Docker, Hugging Face, and other developer services, request fresh tokens from GitHub Actions, Azure DevOps, and Azure, and send the results to a hard-coded webhook.site address as base64-encoded JSON.

The first reaction to a story like this is to tell people to pin their dependencies. That advice is correct, but it is not the interesting part. The interesting part is that the attack targeted CI credentials, not application secrets. A package that runs at interpreter startup is a package that runs in the build runner, the test job, the deployment script, and the developer laptop. The stolen tokens are short-lived, but they are valid immediately. In a CI system, immediate is enough.

The import that never happened

Python's import system is not the only way to execute code. A package can install files that the interpreter loads during startup, before the application's first import. The exact mechanism is in the malicious wheel; the important operational lesson is that "we only import trusted modules" is not a defense. If the package is installed in the environment, it may already be running.

That changes the threat model for dependency scanning. A scanner that looks for known malicious imports will miss a startup hook. A scanner that only checks the package name against an allowlist will miss a compromised release from the official publisher. A scanner that runs the application in a clean environment without monitoring outbound traffic will miss the exfiltration. The attack is designed to look like a normal install until the interpreter starts.

The package also kept up appearances. It pulled the genuine 1.26.0 version so the application would continue to work. That made the compromise harder to notice in functional tests. A test suite that checks agent behavior would pass. The malicious code was not trying to break the agent. It was trying to steal the credentials around it.

What the malware took

The reported targets are the credentials that make modern development work: environment variables, credential files, and service tokens for Azure, Git, Docker, and Hugging Face. The malware did not just read what was already there. It asked GitHub Actions, Azure DevOps, and Azure for fresh identity tokens. That is a more aggressive design than a simple file scraper. It means the attacker did not need a long-lived secret. A short-lived token issued to the build job was enough.

Short-lived tokens are a security improvement in theory. They reduce the blast radius of a leaked long-lived key. In practice, they are only safer if the token cannot be exfiltrated during its lifetime. A CI runner that can request a token and send it to an arbitrary webhook has turned a short-lived credential into an immediate one. The lifetime matters less than the speed of exfiltration.

The use of webhook.site is a reminder that attackers do not need sophisticated infrastructure for the first stage. A public webhook service is enough to receive a payload. That makes network egress monitoring more useful than domain blocklists. If a build runner can reach any host on the internet, it can reach an attacker-controlled endpoint. If it can only reach the package registry and the cloud APIs it needs, the exfiltration path is narrower.

How the publisher account was abused

The reported sequence is ugly. Version 1.26.1 was reverted to a safe version, and then the attacker uploaded 1.26.2 through Microsoft's official PyPI publisher account. Researchers suspect a compromised GitHub organization administrator account. Microsoft has not published a root-cause statement, and the agent-framework GitHub repository was offline at the time of the report.

That last detail is a warning about attribution. Microsoft's ONNX Runtime repository was also offline, but no one has linked that outage to the malware campaign. Two repositories being offline at the same time is suspicious, but suspicion is not evidence. The confirmed fact is that a malicious release came through the official publisher path. The root cause could be a compromised account, a compromised CI workflow, a stolen token, or a weakness in the publisher configuration. Until Microsoft explains it, defenders should assume the publisher path is not trustworthy for this package.

The official publisher path is exactly what makes this worse than a typosquat. A typosquat relies on a developer making a spelling mistake. This attack used the correct name, the correct project, and the correct account. The only signal was the version number and the behavior after installation. Most teams do not inspect the wheel contents of an official Microsoft package. They should not have to, but that is the current state of the ecosystem.

Why CI is the target

CI runners are high-value because they combine three things: credentials, network access, and automation. A runner can deploy to production, read from artifact stores, push container images, and comment on pull requests. It often has a broader set of permissions than a developer laptop, because it needs to do those things without a human in the loop. That makes it a better target than the application server.

The stolen tokens also have a short useful life, which changes the attacker's playbook. They do not need to establish persistence in the runner. They need to use the token before it expires. That could mean pushing a malicious image, opening a pull request, reading private repositories, or modifying a deployment. The malware itself is not persistent; it runs only while the malicious package remains in site-packages. But the stolen token can outlive the package.

This is why "remove the package and rotate the credentials" is the right first response, but not a complete one. Removing the package stops the execution. Rotating the credentials invalidates the stolen tokens. Neither step tells you what the attacker did with the access while it was valid. You need to audit the CI logs, the cloud audit trail, the package registry, and the source-control history for the window between the malicious release and the rotation.

The token is the payload

Modern CI systems increasingly use short-lived identity tokens instead of long-lived secrets. GitHub Actions can issue an OIDC token that a cloud provider exchanges for temporary credentials. Azure DevOps and Azure have similar flows. The design is good: the token is scoped to a workflow, expires quickly, and does not need to be stored in a repository. But the design assumes the workload that requests the token is trustworthy. If a malicious package is running inside that workload, it can request the same token and send it somewhere else.

The damage depends on the token's audience and scope. A token that can only read one artifact bucket is less dangerous than a token that can push container images or modify deployments. A token issued to a pull-request job from a fork should have no production access at all. A token issued to a release job may have broad access by design. The attacker does not need to escalate if the build job already has the permissions needed to deploy.

That is why the first question in incident response is not "what did the package do?" It is "what could the build job do?" Map the runner's identity to its cloud roles, registry permissions, source-control scopes, and deployment targets. Then review the audit logs for that identity during the exposure window. A token that was valid for ten minutes can still create a repository, push an image, or change a secret. The short lifetime limits the window; it does not limit the impact.

The second question is whether the token was bound to a specific audience. If a CI token can be exchanged for credentials in any cloud account that trusts the issuer, the blast radius is larger than it should be. Restrict the trust policy to the specific repository, branch, and workflow. Require human approval for production deployments. Treat every build job as a potential attacker, because in this case one was.

What to check

The first check is the installed version:

python -m pip show agent-framework
python -m pip index versions agent-framework

If you see 1.26.1 or 1.26.2, treat the environment as compromised. Do not just uninstall the package and move on. The malware had access to the environment variables and credential files of that process. Rotate every credential that was available to it, including cloud keys, Git tokens, Docker registry credentials, Hugging Face tokens, and CI secrets. If the environment could request GitHub Actions or Azure DevOps tokens, revoke the active sessions and review the audit logs.

The second check is the build configuration. Look for pip install commands that do not pin a version or verify a hash. A lockfile with hashes would not have prevented a malicious release from being published, but it would have prevented an unpinned install from picking it up. If your lockfile pins 1.26.0, you were not affected by this release, but you should still verify that the lockfile was actually used in the job that ran.

The third check is network egress. Search for connections to webhook.site and for unusual outbound requests from CI runners. A build job that only needs the package registry and a cloud API should not be able to reach arbitrary webhooks. If it can, restrict egress at the network layer. This is not a complete defense against a determined attacker, but it raises the cost of the simplest exfiltration path.

The fourth check is the publisher account. Enable strong authentication for package registry accounts, require approval for new releases, and monitor for changes to maintainers, tokens, and trusted publishers. The attack succeeded because the official account was enough. The defense has to make the official account harder to abuse.

The broader lesson

The software supply chain is usually drawn as a graph of dependencies. This incident shows that the graph has a second dimension: the execution context. A package is not just code that your application imports. It is code that runs in every environment where it is installed, including the environments that hold the credentials to deploy the application. That is why a Python package compromise can become a cloud infrastructure incident.

The fix is not to stop using dependencies. It is to treat the build environment as production. Pin versions, verify hashes, isolate runners, restrict egress, rotate credentials, and audit what the runner can do. The package registry is part of the perimeter now. A compromised publisher account is a compromised build pipeline, even if the application code never changes.

That also means package provenance needs to be more than a green checkmark. A signed release proves that a particular account published a particular artifact. It does not prove that the account was not compromised, that the build was reproducible, or that the artifact contains only the code in the repository. Provenance is useful for tracing an incident, but it is not a substitute for runtime controls. A signed malicious package is still malicious.

The practical combination is provenance plus isolation plus least privilege. Use the registry's attestations to verify where a package came from. Run builds in short-lived, isolated environments. Give each job only the credentials it needs for that job. Restrict egress to the registries and APIs the job actually uses. Log token issuance and usage, and alert on anomalies. None of these controls is sufficient alone, but together they turn a single compromised package into a contained incident instead of a pipeline-wide breach.

Microsoft will eventually publish a root-cause analysis. Until then, the safe assumption is that the official publisher path was compromised and that any credential available to an affected build job should be considered exposed. The package versions are known. The blast radius is not.

Sources


← back to posts