Repository navigation
Agent-mode scan patches the activated VIRTUAL_ENV even when PIPENV_IGNORE_VIRTUALENVS or PIPENV_ACTIVE tells Pipenv to ignore it, leaving the Pipenv venv unpatched with exit 0 #384
Description
Activity
- addedbugSomething isn't workingSomething isn't workingbughuntFound by a scheduled package-manager bug-hunt agentFound by a scheduled package-manager bug-hunt agentpm:pipenvPipenvPipenv
on Sep 30, 2026 - added a commit that references this issue
on Sep 30, 2026 mikolalysenko commented
on Sep 30, 2026 CollaboratorAuthorMore actions[agent] Triaged:
priority:p1(Pipenv / PyPI family). Not a duplicate, and no open or merged PR fixes it (theVIRTUAL_ENVprobe infind_local_venv_site_packageson main still ignoresPIPENV_IGNORE_VIRTUALENVSandPIPENV_ACTIVE).Shares root cause with #334: for a Pipenv project,
find_local_venv_site_packages(crawlers/python_crawler.rs) runs a generic probe order (VIRTUAL_ENV,./.venv,./venv, and only then the$WORKON_HOMEvenv) instead of resolving the venv the way Pipenv does. Will be fixed together. One Pipenv-specific resolver that follows Pipenv's own order covers both issues: honourVIRTUAL_ENVonly withoutPIPENV_ACTIVE/PIPENV_IGNORE_VIRTUALENVS, honourPIPENV_VENV_IN_PROJECTand[pipenv] venv_in_project, and never usevenv/.
Generated by Claude Code
mikolalysenko commented
on Sep 30, 2026 CollaboratorAuthorMore actions[agent] Claiming this issue (with #334; shared root cause: Pipenv venv discovery uses a generic probe order instead of Pipenv's own resolution). Branch: agent/fix-pipenv-venv-resolution. Claim-ID: 2026-09-30T22:21:16Z-1947b5
Generated by Claude Code
mikolalysenko commented
on Sep 30, 2026 CollaboratorAuthorMore actions- added a commit that references this issue
on Sep 30, 2026 mikolalysenko commented
on Oct 1, 2026 CollaboratorAuthorMore actions[agent] On main
2463257(#277, v5) the same discovery bug also causes a false VEX attestation in hosted mode.With
VIRTUAL_ENVpointing at an unrelated venv (one without six) andPIPENV_IGNORE_VIRTUALENVS=1, Pipenv uses itsWORKON_HOMEvenv. socket-patch looks only atVIRTUAL_ENV, so:scan --mode hostedgivesredirected: 1and noredirect_pypi_stale_install, although Pipenv's venv still holds upstream six. Pipenv won't reinstall a warm venv.socket-patch vex --product pkg:pypi/x@1emitsnot_affected/inline_mitigations_already_exist("Patched via Socket patch … (redirected)"), whilepipenv run python -c "import six; print(hasattr(six,'SOCKET_PATCHED'))"printsFalse.- Control (same project,
VIRTUAL_ENVunset): the stale warning fires, andvexomits the patch asnot_applied.
Pipenv (Linux, py3.12) control VIRTUAL_ENV=other +PIPENV_IGNORE_VIRTUALENVS=12023.12.1 ✅ ❌ no warning, not_affected2026.8.0 ✅ ❌ no warning, not_affectedI ran each twice. The repro script is the same as the one I just posted on #334 (same root cause,
crawlers/python_crawler.rsvenv selection).
Generated by Claude Code
- added a commit that references this issue
on Oct 1, 2026
[agent] Found by the scheduled Pipenv bug-hunt routine (ledger #313).
Summary
find_local_venv_site_packages(crates/socket-patch-core/src/crawlers/python_crawler.rs:276-284) takesVIRTUAL_ENVfirst and returns as soon as it has a site-packages. Pipenv only usesVIRTUAL_ENVwhen neitherPIPENV_IGNORE_VIRTUALENVSnorPIPENV_ACTIVEis set (pipenv/environments.py:if "PIPENV_ACTIVE" not in os.environ and not self.PIPENV_IGNORE_VIRTUALENVS: self.PIPENV_VIRTUALENV = os.environ.get("VIRTUAL_ENV"), the same on 2018.11.26, 2023.12.1 and 2026.8.0). The crawler ignores both variables:PIPENV_IGNORE_VIRTUALENVS=1with some other venv activated. This is Pipenv's documented switch for keeping an activated venv from hijacking the project. Pipenv uses$WORKON_HOME/<name>-<hash>, but socket-patch patches the activated venv.PIPENV_ACTIVE=1: you ranpipenv shellin project A, thencdinto project B and ran socket-patch there.VIRTUAL_ENVstill points at A's venv, and Pipenv in B deliberately ignores it. socket-patch patches project A's venv from project B.Both cases report
added/applied,status: successand exit 0. The venv thatpipenv run/pipenv syncuse in the project stays unpatched, and an unrelated venv gets modified. In hosted and vendored mode, the stale-install warning (vendor/pypi.rs:611,pipenv_stale_install_warning, which calls the same function) is judged against the wrong venv.(socket-patch itself sets
PIPENV_IGNORE_VIRTUALENVS=1when it runspipenvinutils/pipenv.rs:80, so the codebase already relies on this variable meaning "don't use VIRTUAL_ENV".)This is related to #334 (stray
venv/or.venvshadowing Pipenv's venv), but it's a different trigger and needs a different fix. Pipenv does honourVIRTUAL_ENVby default, so moving Pipenv's placement ahead of./.venv/./venvfor #334 won't fix it. TheVIRTUAL_ENVprobe itself has to respect the two Pipenv opt-outs when the project is a Pipenv project.Impact
Agent mode reports success while the project's real venv keeps the vulnerable bytes, and it writes patched files into a venv the user didn't target (another project's venv, or a tool venv). CI that gates on the exit code passes.
PIPENV_IGNORE_VIRTUALENVS=1is common in shells and CI images that keep a tool venv activated. Thepipenv shell→cdflow is everyday developer use.Repro (Linux; mock patch API or a local manifest)
The same thing happens with
socket-patch apply --offlineagainst a local.socket/manifest.json(reproduced twice locally on Linux 2023.12.1 and 2026.8.0, and once more per cell in the probe).Expected vs actual
scan/rollbacksees the project's venv; before, it fell through to the global interpreter and reported success while the venv stayed unpatched". The project's venv is the onepipenv --venvreports. CLI_CONTRACT.md:status: success/ exit 0 means the requested patches are in place.VIRTUAL_ENVnames, even when Pipenv has been told to ignore it. It exits 0.Control: with
VIRTUAL_ENVset and neither opt-out set, Pipenv 2023.12.1 / 2026.8.0 also use the activated venv, so socket-patch is correct there (pass).OS × version
pipenv --venvnames VIRTUAL_ENV, butpipenv runimports from the WORKON_HOME venv)First bad version
Not bisected. This isn't a regression: the unconditional
VIRTUAL_ENVearly return predates Pipenv venv discovery (added in 4.0.0), and neitherPIPENV_IGNORE_VIRTUALENVSnorPIPENV_ACTIVEis read anywhere in the crawler.Suspect code
crates/socket-patch-core/src/crawlers/python_crawler.rs:276-284: the unconditionalVIRTUAL_ENVearly return.crates/socket-patch-core/src/vendor/pypi.rs:611: the stale-install warning goes through the same discovery.Probe run: https://github.com/SocketDev/socket-patch/actions/runs/36779636041 (6 jobs: ubuntu / macos / windows × 2023.12.1 / 2026.8.0,
scan --mode agentagainst a mock patch API). 2018.11.26 was checked locally on Linux.