A Malicious PyPI Release Got Upgrade PRs in 6 Minutes. Add a Cooldown
On November 17, someone published two malicious versions of Microsoft's agent-framework package to PyPI. The bad releases, 1.26.1 and 1.26.2, were live for well under an hour. According to JFrog's analysis, that was stil
On November 17, someone published two malicious versions of Microsoft's agent-framework package to PyPI. The bad releases, 1.26.1 and 1.26.2, were live for well under an hour. According to JFrog's analysis, that was still long enough for dependency bots such as Renovate to start opening upgrade pull requests in downstream repositories, within six minutes of the first upload.
That six-minute figure is the part that changed my mind. For years I treated "stay on the latest version" as a security virtue. After reading the write-ups for this incident, I think that for most application teams installing a release minutes after it appears is now a supply-chain risk, and a few days of deliberate delay is cheap insurance.
This post covers what happened (only what the advisory and research teams have published), why the payload ran even if your code never imported the package, and two concrete changes you can make today: a release cooldown in pip, uv, Dependabot and Renovate, and a CI check for .pth startup hooks. I ran every command below on a throwaway virtualenv with pip 26.3, uv 0.13.8 and Python 3.13.
TL;DR
-
agent-framework1.26.1 and 1.26.2 (published Nov 17, 2026) carried a credential stealer. 1.26.0 is the last clean release. If either bad version touched a laptop, CI runner or image, rotate every credential that environment could reach. - The payload used a
.pthfile, so it ran on every Python start in that environment, includingpipandpytest, without anyone importingagent_framework. - The malicious versions were removed within roughly an hour. A cooldown of even one day would have skipped them entirely.
- pip (
--uploaded-prior-to P7D), uv (exclude-newer = "7 days"), Dependabot (cooldown) and Renovate (minimumReleaseAge) all support cooldowns now. Keep security fixes on a separate, faster path.
What happened, briefly
The GitHub Advisory Database entry, GHSA-764m-3ppc-5m73, is the best single summary. The key facts:
- 1.26.1 was published at 20:35 UTC on November 17 as a wheel only. 1.26.2 followed at 21:08 UTC. Both have since been removed from PyPI.
- Each wheel added an executable
.pthstartup hook. The rest of the wheel matched the clean 1.26.0, and the dependency pin onagent-framework-core[all]==1.26.0was unchanged, so applications kept working normally. - The stealer collected environment variables with names containing strings like
TOKEN,SECRET,KEY,AZURE,AWS,GITHUBandOPENAI, read other processes' environments from/proc/*/environ, grabbed credential files (~/.azure,.npmrc,.netrc,.git-credentials,.docker/config.json,.envfiles) and requested Azure managed-identity and Azure DevOps OIDC tokens. Version 1.26.2 added GitHub Actions OIDC tokens. - Everything went out in one HTTPS POST to a
webhook.siteURL.
Wiz Research reported that the attacker appears to have compromised a client certificate and key for Microsoft's internal release pipeline (ESRP). They also found the attacker had used webhook.site's free tier, which stores at most 100 requests. Of the 50 requests it captured, Wiz counted only three unique successful exfiltrations of victim data. That is good news for this incident, and it was luck. The attacker's next payload may not have a 100-request cap.
One detail from JFrog's write-up is worth repeating. PyPI quarantined 1.26.1 about 31 minutes after upload, and the attacker shipped 1.26.2 two minutes later. Removing a version does not revoke the credential that published it. Pinning to "whatever isn't quarantined yet" isn't a defense.
Why nobody had to import anything
Most of us assume a malicious package needs to be imported, or at least needs an install script, to do damage. Wheels don't run install scripts. This attack got around that with a .pth file.
When CPython starts, site.py scans each site-packages directory for .pth files. Most lines in those files are just extra paths to add to sys.path. But any line that starts with import is passed to exec(). That happens before your script, before sitecustomize, and before pip or pytest load their own code.
You can see it in ten seconds. Drop a harmless hook into a scratch virtualenv:
uv venv --python 3.13 /tmp/pthdemo && cd /tmp/pthdemo
cat > lib/python3.13/site-packages/zz_demo.pth <<'PTH'
import os, sys; os.environ.get("_DEMO_PTH") or (os.environ.__setitem__("_DEMO_PTH", "1"), sys.stderr.write("[zz_demo.pth] ran before your code: %r\n" % sys.argv[:2]))
PTH
Then run anything:
$ bin/python -c "print('hello from my code')"
[zz_demo.pth] ran before your code: ['-c']
hello from my code
$ bin/python -m pip --version
[zz_demo.pth] ran before your code: ['-m', '--version']
pip 26.3 from /tmp/pthdemo/lib/python3.13/site-packages/pip (python 3.13)
The environment-variable guard in my demo mirrors what the real stealer did. According to Wiz, it set _AF_TEL=1 so it wouldn't run again in child processes.
Two things surprised me while testing:
-
python -I(isolated mode) does not stop it. Isolated mode ignoresPYTHON*environment variables and the user site directory, but it still processes.pthfiles in the environment's ownsite-packages. My hook ran under-I. -
python -Sdoes stop it, because it skips thesitemodule entirely. It also skips addingsite-packagestosys.path, so it's not something you can run an application with.
The practical point is that "we install the package but only import it in one service" offers no protection. Running pip list in a poisoned environment is enough.
Change 1: make new releases wait
A cooldown means your resolver ignores any file uploaded in the last N days. It doesn't help against a backdoor that goes unnoticed for months, and it isn't meant to. It targets the pattern in this incident: a hijacked release that gets spotted and pulled within hours.
Here's how each tool handles it, tested where I could run it locally.
pip 26+
pip install --uploaded-prior-to P7D -r requirements.txt
P7D is an ISO 8601 duration ("at least 7 days ago"). It only works against indexes that publish upload times, which PyPI does. I compared a dry run with and without it on November 21:
$ pip install --dry-run --report - boto3 -> boto3 1.44.9
$ pip install --dry-run --report - --uploaded-prior-to P7D boto3 -> boto3 1.44.3
uv
On the command line:
uv pip compile requirements.in --exclude-newer "7 days"
Or keep it in pyproject.toml so every developer and every CI job gets the same rule:
[tool.uv]
exclude-newer = "7 days"
After uv lock, the lockfile records the span (exclude-newer-span = "P7D"), so reviewers can see the policy in the diff. In my test, boto3 resolved to 1.44.3 instead of 1.44.9 and openai to 3.51.0 instead of 3.57.0.
uv also has --exclude-newer-package, which lets you set a different cutoff for a single package. That's your escape hatch when one dependency ships a fix you need today.
Dependabot
Dependabot's options reference now says it applies a default cooldown of 3 days to version updates, even if you never configure one. Security updates are not delayed. To make the window longer:
# .github/dependabot.yml
version: 2
updates:
- package-ecosystem: "pip"
directory: "/"
schedule:
interval: "weekly"
cooldown:
default-days: 7
semver-major-days: 14
Renovate
Renovate calls this minimumReleaseAge. On its own it adds a "pending" status check to the branch. The docs recommend pairing it with internalChecksFilter: "strict" so no PR is created until the age requirement is met:
{
"minimumReleaseAge": "7 days",
"internalChecksFilter": "strict"
}
The trade-off, stated honestly
A cooldown delays good releases too, including fixes. That's why I keep two lanes:
- Routine version bumps: a 7-day cooldown, batched weekly.
- Security fixes: no cooldown. A human reads the advisory, then bumps the one package on purpose (uv's per-package override, or a manual pin). Dependabot already treats security updates this way.
The second lane relies on a person checking that a "security fix" really comes from the project. Given that the attacker here published from what looked like Microsoft's own pipeline, I'm comfortable with a human in that loop.
Change 2: fail CI on unexpected startup hooks
A cooldown reduces exposure. This check catches the specific trick. The script lists every .pth file the interpreter will process, shows which installed distribution owns it (from dist-info/RECORD), and flags the lines Python will exec():
# pth_audit.py: list .pth files that execute code at interpreter start
import site, sys
from importlib import metadata
from pathlib import Path
def owners():
m = {}
for dist in metadata.distributions():
for f in dist.files or []:
m[str(Path(dist.locate_file(f)).resolve())] = f"{dist.metadata['Name']}=={dist.version}"
return m
def main(allowed: set[str]) -> int:
dirs = list(dict.fromkeys(site.getsitepackages() + [site.getusersitepackages()]))
own, bad = owners(), 0
for d in dirs:
for pth in sorted(Path(d).glob("*.pth")):
lines = pth.read_text("utf-8-sig", "replace").splitlines()
execs = [l.strip() for l in lines if l.startswith(("import ", "import\t"))]
if not execs:
continue
owner = own.get(str(pth.resolve()), "NOT IN ANY RECORD")
ok = pth.name in allowed
bad += not ok
print(f"{'ok ' if ok else 'NEW'} {pth.name:32} {owner}")
for l in execs:
print(f" runs: {l[:90]}")
return 1 if bad else 0
if __name__ == "__main__":
sys.exit(main(set(sys.argv[1:])))
In a test environment with setuptools, coverage, an editable install and my demo hook, the output looked like this (exec lines trimmed):
$ python pth_audit.py distutils-precedence.pth a1_coverage.pth
[zz_demo.pth] ran before your code: ['pth_audit.py', 'distutils-precedence.pth']
ok a1_coverage.pth coverage==7.17.4
runs: import sys; exec('import os\n\nif os.getenv("COVERAGE_PROCESS_START") ...
ok distutils-precedence.pth setuptools==84.2.1
runs: import os; var = 'SETUPTOOLS_USE_DISTUTILS'; enabled = ...
NEW zz_demo.pth NOT IN ANY RECORD
runs: import os, sys; os.environ.get("_DEMO_PTH") or ...
$ echo $?
1
Three things I learned from running it:
-
Legitimate executable
.pthfiles are common.setuptoolsandcoverageboth ship one. Editable installs add.pthfiles too, but those contain plain paths, so the script skips them. You can't ban.pthoutright. You need an allowlist. -
Ownership alone wouldn't have caught this attack. The malicious hook was a real file inside a real wheel, so it would show up as owned by
agent-framework==1.26.2. What gives it away is that a new executable hook appeared in a package that never had one. That's why the script compares against an allowlist instead of checking ownership. -
Run it after the install, not before. It is a Python script, so in a poisoned environment the hook runs first. You can see that in the first line of the output above. Run it in CI right after
pip install, in a job that has no deploy credentials, and fail before any job that does.
For CI, I'd put it in the test job before anything else uses secrets:
- run: pip install --uploaded-prior-to P7D -r requirements.txt
- run: python pth_audit.py distutils-precedence.pth a1_coverage.pth
If you installed 1.26.1 or 1.26.2
Follow the advisory and the vendors' guidance, not a blog post. In short:
- Find exposure in lockfiles, CI logs, virtualenvs and images (
pip show agent-framework, and grep lockfiles for1.26.1and1.26.2). - Look for
agent_framework_meta.pth,agent_framework_meta/_telemetry.py,af_runtime_diag.pthoraf_runtime_diag.pyinsite-packages. - Rebuild the environment from a clean base, pinned to 1.26.0.
- Rotate everything that environment could reach: CI secrets, cloud CLI sessions, registry tokens, git credentials and AI provider keys. For GitHub Actions workflows with
id-token: writethat installed 1.26.2, review the Entra ID federated credentials that trust them.
What this changes for me
I used to measure dependency hygiene by how quickly we picked up new versions. After this incident I care more about how deliberately we pick them up: a few days of delay for routine bumps, a fast lane that a human reads for security fixes, and a CI check that notices when a package starts running code at interpreter startup.
None of this would have stopped a patient attacker who hides a backdoor for months. It would have kept this one out of a project with a 7-day cooldown, since both bad versions were gone from PyPI within about an hour.
So, the question I'd like your take on: do you pull dependency updates as soon as they're released to get fixes early, or do you make every release wait a few days and accept that some fixes arrive late? If you use a cooldown, how many days did you choose and why?
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.