Repository navigation
fix(python): place Windows venv in configured temp directory - #696
Conversation
Reviewer's GuideImplementationPlace the managed venv under the Windows OS temp directory and derive its executable paths from that complete directory, while retaining the fixed POSIX location.
TestsUpdate the controller test harness and platform-specific assertions to verify Windows temp-directory placement and POSIX path preservation.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 3 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/providers/python_controller.js" line_range="112" />
<code_context>
+ // drive-aware even when the Windows branch runs on another host (tests).
+ const venvPath = isWindows ? path.win32 : path.posix
+ this.pythonEnvDir = isWindows
+ ? venvPath.join(os.tmpdir(), "trustify_da_env_js")
+ : venvPath.join("/", "tmp", "trustify_da_env_js")
try {
</code_context>
<issue_to_address>
**Temp paths execute shell commands**
When the configured Windows temp path contains an attacker-controlled shell metacharacter such as `&` but no spaces, `invokeCommand` passes `pythonEnvDir` through `shell: true`, and `handleSpacesInPath` leaves the path unquoted, so `cmd.exe` treats `&` as a command separator and runs the injected command; venv creation or the pip upgrade fails and the analysis process runs attacker-controlled commands.
Quote or escape Windows paths containing shell metacharacters before passing them to the shell, or avoid invoking commands through a shell.
</issue_to_address>
### Comment 2
<location path="src/providers/python_controller.js" line_range="112" />
<code_context>
+ // drive-aware even when the Windows branch runs on another host (tests).
+ const venvPath = isWindows ? path.win32 : path.posix
+ this.pythonEnvDir = isWindows
+ ? venvPath.join(os.tmpdir(), "trustify_da_env_js")
+ : venvPath.join("/", "tmp", "trustify_da_env_js")
try {
</code_context>
<issue_to_address>
**Shared temp venv can be preseeded**
When a Windows process uses a temp directory writable by an untrusted local user, who pre-creates the venv path with a malicious startup module, `pythonEnvDir` is a predictable child of the shared temp root, and `prepareEnvironment()` runs `python -m venv` there before executing the venv interpreter for the pip upgrade. Python reuses existing venv contents, so a planted `sitecustomize.py` can execute with the analysis process's privileges.
Create the venv in a securely created private directory and verify that it is owned by the process and is not a reparse point before invoking Python.
</issue_to_address>
### Comment 3
<location path="src/providers/python_controller.js" line_range="112" />
<code_context>
+ // drive-aware even when the Windows branch runs on another host (tests).
+ const venvPath = isWindows ? path.win32 : path.posix
+ this.pythonEnvDir = isWindows
+ ? venvPath.join(os.tmpdir(), "trustify_da_env_js")
+ : venvPath.join("/", "tmp", "trustify_da_env_js")
try {
</code_context>
<issue_to_address>
**Overlapping scans corrupt shared environments**
When two Windows analyses using the same configured temp directory overlap, both controllers run `python -m venv` and install dependencies into the same `pythonEnvDir`; one setup can disrupt the other's environment, and `getDependencies()` can read the other scan's packages after yielding, so setup fails or the scan returns an incorrect SBOM.
Give each analysis its own isolated virtual-environment directory, or coordinate access so concurrent scans cannot modify or read the same environment.
</issue_to_address>Sourcery assessment
Approval pending. 3 findings to address first.
Blocking findings: src/providers/python_controller.js:112, src/providers/python_controller.js:112, src/providers/python_controller.js:112
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #696 +/- ##
=======================================
Coverage 91.60% 91.60%
=======================================
Files 44 44
Lines 11638 11641 +3
Branches 2347 2349 +2
=======================================
+ Hits 10661 10664 +3
Misses 977 977
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
|
[sdlc-workflow/verify-pr] Re: @sourcery-ai[bot] review — all three items in review 5879037787 are classified as code change requests; their validity and scope are assessed separately from the language classification.
Individual inline threads contain the corresponding reasoning. These dispositions do not assert that the broader lifecycle risks are fixed. |
Verification Report for TC-7494 (commit b6d2f58)Reviewed HEAD:
Overall: FAILRequired fix
This is a valid-path portability failure and a command-injection exposure when the configured path is attacker-influenced. The unsafe helper predates the PR, but exposing configurable TEMP content to it is new. No injected command was executed; native Windows/cmd.exe execution remains unverified. No remote exploitability or privilege escalation is claimed. See Node's shell-input warning. TC-7561 tracks a narrow command-boundary fix on this existing PR, preserving supported batch-wrapper behavior and the fixed venv lifecycle. It is a standalone Task, as authorized, because TC-7494 is already a Sub-task and Jira does not nest sub-tasks. Inline Other review dispositions
Verification detail and limitations
Root causeThe supportable preventive gap is an implement-task analysis method: trace newly sourced input through unchanged downstream helpers and verify literal data remains literal at parsing/execution boundaries. The task's helper-mocked placement tests verify path values, not the actual subprocess boundary. No parent Feature or Feature-to-task omission was evidenced, so no define-feature/plan-feature attribution is asserted; historical skill invocation/responsibility is unproven. Existing TC-5951 already covers this downstream re-parsing method, including shell and format-active input verification. It was reused, linked Related to TC-7494, and received supporting root-cause analysis. No duplicate preventive Task was created or branch retargeted. Node/Windows API facts stay out of general-purpose skill rules. TC-7504 remains separate relational-oracle work. Evidence retained locally in Code unchanged; no merge or Jira status transition performed. TC-7494 remains in Review. Test Quality, Test Change Classification, and Root-Cause Investigation are informational and excluded from the Overall calculation. This comment was AI-generated by sdlc-workflow/verify-pr v0.13.10. |
Strum355
left a comment
There was a problem hiding this comment.
This PR should probably be split into two: this PR containing only b6d2f58, and another PR containing only 0724cb7. These two happened to end up in the same PR due to an unfortunate aspect of /verify-pr (sourcery-ai raised a comment that is completely unrelated to the PR, and /verify-pr forces the fix to end up in this PR).
When you move 0724cb7 into a separate PR, theres a few things that should be done:
- drop the "exposing configurable TEMP content to it is new" premise, and widen the scope statement to the Gradle/Maven call sites it also fixes.
- possibly add a
windows-latestjob to test.yml so that this stuff can potentially be caught in CI as well - replace most of what was added in 0724cb7 with the
cross-spawnlibrary, which should handle everything that was hand-rolled in that commit with a tried & tested library (make sure to use 7.0.6, previous versions had a CVE) - revisit the tests added in test/tools.test.js, Claude & our sdlc-workflow tooling has a tendency to add a load of unnecessary tests, which in this case would most likely be covered just by running the tests on windows in the first place.
- be absolutely sure that the changes introduced in 0724cb7 don't cause a regression, this was a sticky codepiece before (hence why I left a comment with two links for further reading)
Strum355
left a comment
There was a problem hiding this comment.
Not sure why CI is failing, but I think this looks fine otherwise
prepareEnvironment() built the managed venv at path.join(path.sep, "tmp", "trustify_da_env_js"), which becomes a root-relative \tmp path on Windows, then re-anchored the interpreter and pip paths to the current drive root from process.cwd(). Use os.tmpdir() on Windows so the venv lives in the OS-configured temp directory, and join Scripts\python.exe and Scripts\pip.exe from that complete venv directory. The venv creation and pip upgrade now share one directory even when TEMP and the working directory are on different drives. POSIX keeps the fixed /tmp/trustify_da_env_js path with the existing reuse and pip uninstall behavior. Adds one failing-first Windows placement test backed by an explicit path.win32 seam; Linux path preservation is covered by the existing POSIX tests running with a non-default temp dir. Native Windows execution remains unverified on this POSIX host. Implements TC-7494 Signed-off-by: Adva Oren <aoren@redhat.com> Assisted-by: Claude Code
Replace blanket shell execution and pre-quoting with cross-spawn 7.0.6 for the shared Python, Maven, and Gradle invocation helper. Preserve synchronous stdout, thrown failures, environment handling, and the 10 MiB output buffer. Add real-process contract tests and focused Windows Node 22/24 CI. Keep the Python venv-placement change independent in PR guacsec#696. Implements TC-7561 Assisted-by: OpenCode (GPT-6.1 Sol) Signed-off-by: Adva Oren <aoren@redhat.com>
* fix(tools): use cross-spawn for Windows commands Replace blanket shell execution and pre-quoting with cross-spawn 7.0.6 for the shared Python, Maven, and Gradle invocation helper. Preserve synchronous stdout, thrown failures, environment handling, and the 10 MiB output buffer. Add real-process contract tests and focused Windows Node 22/24 CI. Keep the Python venv-placement change independent in PR #696. Implements TC-7561 Assisted-by: OpenCode (GPT-6.1 Sol) Signed-off-by: Adva Oren <aoren@redhat.com> * ci: remove native Windows invocation jobs Keep unit CI on Linux; the shared integration workflow already has Windows and macOS runners. Retain Windows-only contract tests for manual runs; they remain skipped on Linux, not counted as passing. The initial Windows jobs failed during checkout of existing OCI fixture filenames containing colons, before any invocation tests ran. Do not include the proposed sparse-checkout workaround. Fix-specific native Windows results remain unverified. Implements TC-7561 Assisted-by: OpenCode (GPT-6.1 Sol) Signed-off-by: Adva Oren <aoren@redhat.com> * fix(tools): avoid circular spawn errors Exclude the nested error reference when enriching spawn failures so JSON serialization preserves diagnostic fields without a cycle. Cover missing executables and timeouts with real-process assertions. Implements TC-7561 Signed-off-by: Adva Oren <aoren@redhat.com> * build(deps): allow compatible cross-spawn updates Use ^7.0.6 for consumers while retaining the locked 7.0.6 version for reproducible repository installs. No resolved dependency changes. Implements TC-7561 Signed-off-by: Adva Oren <aoren@redhat.com> --------- Signed-off-by: Adva Oren <aoren@redhat.com>
Summary
os.tmpdir()instead of a root-relative\tmppath.Scripts\python.exeandScripts\pip.exefrom that complete venv directory, including when TEMP and the working directory are on different drives./tmp/trustify_da_env_jspath and existing venv lifecycle.This PR is limited to unchanged commit
b6d2f58(TC-7494). The pre-existing shared Windows command-invocation issue has been moved to PR #698 (TC-7561); it affects Python and Maven/Gradle invocations, including batch wrappers, and is not a defect newly introduced by configurable TEMP content.Verification
The original Python-controller placement tests are unchanged. Their Windows path assertions use a simulated Windows path seam, not native Windows execution.
Implements TC-7494.
Summary by Sourcery
Use the OS-configured temporary directory for Windows Python virtual environments while retaining existing POSIX behavior.
Bug Fixes:
Enhancements:
/tmpvirtual-environment location and lifecycle.Tests: