Most of us treat pytest as the safe command. You clone a repo, skim the README, and before running the app you run the tests, because tests don't touch production, don't need secrets and can't break anything.

That habit is exactly what one malware campaign is now leaning on.

On November 24, SafeDep published an analysis of PolinRider's new Python loader. It found the same 58-line loader in 375 public GitHub repositories under 260 accounts. Most copies hide in a small utils package with harmless-sounding files (session.py, transport.py, http_session.py) plus five import lines added to a start file such as a Django asgi.py or a FastAPI main.py. Twelve copies are a root-level conftest.py. Those twelve need no import line at all, because pytest imports every conftest.py it finds while collecting tests.

I wanted to know exactly which everyday commands run a planted conftest.py, so I tested it. The answer is a good argument for changing how you open repos you didn't write.

What the loader does (briefly)

Per SafeDep's write-up, the loader reads the newest transaction an Ethereum wallet sent to itself, decodes that transaction's input data as JavaScript, writes it to a temp file and runs it with Node.js. That JavaScript reads a second wallet to find the command-and-control server, then feeds the next stage into a detached node -i process, so the code never appears on the process command line. SafeDep did not connect to the C2, so this chain's final payload isn't confirmed; in the earlier PolinRider chain it followed to the end, later stages installed a stealer for environment secrets, browser passwords, cookies and wallet data.

A few details matter for developers:

  • No package on PyPI or npm carries it. It lives in source repositories. Your dependency scanner, lockfile audit or Dependabot will never see it.
  • Commit history lies. SafeDep found the loader inside commits with forged dates (one dated September 2025, more than a year before the wallet existed) and inside commits titled as malware removals.
  • Cleaning the repo isn't enough. Two repos had removed an earlier PolinRider infection and were reinfected, because the machines that push to them were still compromised.

Which commands run a planted conftest.py? I checked

I built a throwaway repo with a root conftest.py that only appends a line to /tmp/canary.log, an app/utils/session.py that does the same, and an app/main.py that does import utils.session, mirroring the layout SafeDep describes. Then I ran the commands I'd normally run on a fresh clone. This was pytest 9.2.0 on Python 3.13.5:

Command conftest.py imported?
pytest -q yes
pytest --collect-only -q yes
pytest --co -k nothing_matches (zero tests selected) yes
pytest --help yes
pytest --version no
pytest --noconftest -q no

The surprises for me were the middle rows. "Just list the tests" (--collect-only) runs it. Selecting zero tests runs it. Even pytest --help runs it, because pytest loads conftest files to discover plugin options before printing help. If your editor's test explorer runs test discovery when you open a folder, that discovery is a collection run too.

The import-line variant behaves differently, and SafeDep's own testing found the same thing:

Command (from repo root) app/utils/session.py imported?
python app/main.py yes (the script's folder goes on sys.path, so utils resolves)
cd app && python -m main yes
python -m app.main no, ModuleNotFoundError: No module named 'utils'
python -c "import app.main" no, same error

That last row is the nasty part. SafeDep notes that in three example apps it checked, the documented start command failed with No module named 'utils' before the loader ran. The natural next step for a developer is to "fix" the import path, and fixing it is what runs the loader. An import error in a repo you just cloned is worth a second look before you reach for sys.path.

--noconftest is not a sandbox

pytest --noconftest does skip conftest files; my canary stayed silent. But it doesn't stop other code from running at collection time:

  • A pyproject.toml with addopts = "-p helpers.plug" loads that module as a plugin. In my test, pytest --noconftest -q still imported it. Adding -c /dev/null (ignore the repo's config file) stopped it.
  • Test modules are imported to collect them. A tests/test_y.py that starts with import helpers.plug ran that module under python -m pytest --noconftest -c /dev/null --co, because python -m puts the current directory on sys.path.

So flags can narrow what runs, but once you invoke the test runner on untrusted code, you have chosen to run untrusted code. The real fix is where you run it, not which flags you pass.

It's not just Python

The same "the build runs before you've read anything" pattern hit .NET developers this week. Socket reported 13 malicious NuGet packages used in a fake take-home job assessment. Most posed as WinUI 3 and WPF button controls. According to Socket's analysis, one package ships an MSBuild targets file that runs a bundled DLL after every build; it downloads a file and stages a DLL-sideloading pair next to a copy of Windows' on-screen keyboard. All 13 packages have since been removed from NuGet. In npm land, the equivalent is a postinstall hook, and the GitHub Advisory Database flagged yet another credential-harvesting npm package using one on Nov 26.

Every ecosystem has a file that executes on a routine command: conftest.py on pytest, .targets and Directory.Build.props on dotnet build, lifecycle scripts on npm install, setup.py on a legacy pip install .. Attackers don't need you to run the app. They need you to run the tooling.

A pre-run check for any repo you didn't write

Here's the order I'd follow before running anything in a clone from outside your team: a candidate's take-home, a client's legacy repo, an open-source project I'm evaluating, or a PR from a fork.

1. Read the files that execute on routine commands. I wrote a small, read-only triage script for this. It never imports anything from the repo; it parses files with ast and lists conftest files, top-level packages, .pth/setup.py, npm lifecycle hooks and MSBuild files, flagging any Python file that imports subprocess, urllib, socket, tempfile, base64 or ctypes at module level:

"""Flag files in a clone that run code on pytest / import / install. Reads files only; never imports anything from the repo.""" import ast, json, sys from pathlib import Path RISKY = {"subprocess", "urllib", "socket", "requests", "httpx", "tempfile", "base64", "ctypes"} SKIP = {".git", "node_modules", ".venv", "venv"} def import_time_risk(path): """Risky imports at module level (what runs the moment it's imported).""" try: tree = ast.parse(path.read_text(errors="replace")) except SyntaxError: return {"<does not parse>"} hits = set() for node in tree.body: # top-level statements only for sub in ast.walk(node): if isinstance(sub, (ast.FunctionDef, ast.AsyncFunctionDef)): break if isinstance(sub, ast.Import): hits |= {a.name for a in sub.names if a.name.split(".")[0] in RISKY} elif isinstance(sub, ast.ImportFrom) and sub.module: if sub.module.split(".")[0] in RISKY: hits.add(sub.module) return hits def audit(root): root = Path(root).resolve() for p in sorted(root.rglob("*")): if not p.is_file() or SKIP & set(p.parts): continue rel = p.relative_to(root) if p.name == "conftest.py": yield rel, "pytest imports this on collection", import_time_risk(p) elif p.name == "__init__.py" and len(rel.parts) == 2: risk = set().union(*(import_time_risk(m) for m in p.parent.rglob("*.py"))) yield rel.parent, "top-level package, importable from repo root", risk elif p.suffix == ".pth" or p.name in {"setup.py", "sitecustomize.py"}: yield rel, "runs on install or interpreter start", import_time_risk(p) if p.suffix == ".py" else set() elif p.name == "package.json": scripts = json.loads(p.read_text() or "{}").get("scripts", {}) hooks = {k: v for k, v in scripts.items() if k in {"preinstall", "install", "postinstall", "prepare"}} if hooks: yield rel, f"npm lifecycle hooks {hooks}", set() elif p.suffix in {".targets", ".props"}: yield rel, "MSBuild file, can run tasks on every build", set() if __name__ == "__main__": bad = False for rel, why, risk in audit(sys.argv[1] if len(sys.argv) > 1 else "."): bad |= bool(risk) print(f"{'!!' if risk else ' '} {rel}: {why}") if risk: print(f" imports at module level: {', '.join(sorted(risk))}") sys.exit(1 if bad else 0) 

On a defanged copy of the PolinRider layout (same imports, wrapped in try: like the real loader, no network code) it prints:

!! conftest.py: pytest imports this on collection imports at module level: subprocess, tempfile, urllib.request package.json: npm lifecycle hooks {'postinstall': 'node api.js'} !! utils: top-level package, importable from repo root imports at module level: subprocess, tempfile, urllib.request 

Be clear about what this is: a triage list, not a malware detector. A legitimate conftest.py may import subprocess to start a test server, and a determined attacker can hide imports behind __import__ or importlib. It also only checks top-level packages, while SafeDep found most planted utils folders nested inside the app folder. The point is to put the files that run first in front of human eyes.

2. Search for the known indicators. For this specific campaign, SafeDep publishes exact grep commands for the wallet address, the loader's API calls, the five-import pattern and NamedTemporaryFile in conftest.py, plus a git log --all -S <wallet> check for history. Use theirs rather than a paraphrase; it includes the full indicator list.

3. Run untrusted code somewhere disposable. A container or VM with no SSH keys, no cloud credentials, no browser profile and no ~/.npmrc or ~/.pypirc mounted. A devcontainer or Codespace counts if it isn't carrying your real tokens. If the take-home needs network access to install dependencies, that's fine; it shouldn't need your GITHUB_TOKEN.

4. Treat a "fix the import path" moment as a stop sign. If a fresh clone fails with No module named 'utils' and the README says it should just work, look at what utils contains before you change anything.

5. If you already ran it, assume compromise. SafeDep's guidance: if you ran pytest (or the start script) in an affected repo on a machine with Node.js, rotate the secrets in that shell environment and the passwords and session cookies saved in its browsers, move funds out of any wallet on that machine, and look for node -i or node -e processes with no terminal. If you own an infected repo, remove the loader, then clean every machine that pushes to it and replace their GitHub tokens and SSH keys, or it comes back.

What I actually tested, and what I didn't

We build Django and Python backends, so pytest in a fresh clone is muscle memory for our team, which is why I wanted the behaviour pinned down rather than assumed. Everything in the two tables above comes from a throwaway repo whose "payload" only writes a line to a log file. I did not run the real loader, query the wallets or contact the C2 server; every fact about the campaign itself (375 repos, 260 accounts, the wallet behaviour, the forged commit dates) is from SafeDep's analysis. The triage script was run against a defanged copy of the layout, not live samples.

That's also the honest limit of advice like this: I can tell you which commands execute what, but only the indicator checks in step 2 can tell you whether a repo on your disk is one of the 375.

The uncomfortable takeaway

"Run the tests first" is good engineering advice for code you trust. For code you don't, it's the same as "run the code first", because pytest executes Python before a single test is selected. The PolinRider repos were mostly small personal projects with 189 stars between them, which is exactly the kind of repo people clone to learn from, fork for a class, or get sent as an assessment.

So here's my question: when you clone a repo from someone you don't know, do you actually open it in a container or VM first, or is pytest on your own laptop still the first thing you run?