Repository navigation
fix(windows): resolve helper executables outside the project directory - #5006
Conversation
…cuted Cells for the lock evidence and audit git probes, the az lookup, the external scanner lookup, the helper owner, and the CLI start setting. Each places a stand-in helper in the project and asserts the real tool answers and the stand-in never runs. Co-authored-by: Copilot App <[email protected]> Co-authored-by: copilot-swe-agent[bot] <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
The production executable-discovery hardening is missing, leaving the new import broken and vulnerable call sites unchanged, while test flaws can conceal unintended execution or premature CLI failures.
3 open issues
What changed in this PR
This PR adds regression tests intended to prevent APM from running project-local programs instead of installed helpers. The reviewed changes contain test additions, not the production hardening described in the PR.
Changes:
- Add project-local stand-ins for git, Azure CLI and SkillSpector discovery checks.
- Exercise trusted PATH filtering and the
apm audit --cisubprocess path. - Check that Windows CLI startup disables implicit current-directory executable lookup.
| File | Description |
|---|---|
tests/integration/test_trusted_executable_discovery.py |
Adds helper-discovery regression cases, stand-in fixtures and a Windows startup-setting check. |
Review effort: Balanced
Every helper program APM launches or probes (git, az, npm, codex, PowerShell, external scanners) now resolves through utils/git_env.trusted_executable, which reuses _resolve_trusted_executable and searches only PATH directories outside the project. Launches use the resolved path. On Windows the CLI sets NoDefaultCurrentDirectoryInExePath at start. The new architecture rule transport-platform-external-executable-owner rejects shutil.which outside the owner and literal program names in subprocess launches. The unused is_tool_available and get_available_package_managers helpers are removed. apm-spec-waiver: helper programs are located on PATH outside the project; no manifest, lockfile or resolver contract changes Co-authored-by: Copilot App <[email protected]> Co-authored-by: copilot-swe-agent[bot] <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved runtime-resolution bypasses can execute untrusted project-local binaries, while obsolete helper imports block unit-test collection and missing resolver stubs cause test failures.
10 open issues
Reject escaping symlinks when probing managed runtimes · New Fail closed when only a project-local runtime is found · New Remove obsolete helper imports and tests · New Add the production executable-discovery hardening Inspect positional and keyword subprocess commands · New Update Codex tests to stub the required runtime resolver · New Stub LLM runtime resolution in integration tests · New Stub Copilot discovery in all affected tests · New Assert the CLI succeeds before checking the stand-in marker Embed the absolute marker path in the POSIX stand-in
Review effort: Balanced
…eep the user's search setting The transport-platform-external-executable-owner rule now also rejects a literal program name held in a local argv, launches through aliased subprocess imports, os.exec*/spawn*/posix_spawnp and asyncio.create_subprocess_exec, and a literal executable= argument. NoDefaultCurrentDirectoryInExePath stays set for APM's own helper launches, while user-authored scripts (apm run, lifecycle and command scripts) receive the value the user started with. Co-authored-by: Copilot App <[email protected]> Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: Copilot App <[email protected]> Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: Copilot App <[email protected]> Co-authored-by: copilot-swe-agent[bot] <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
Executable-trust protections still allow project-local helpers to run, while stale imports and resolver mocks cause test collection and runtime-test failures.
14 open issues
Preserve hardened runtime environments and fail closed on lookup · New Prevent installer scripts from resolving helpers through project PATH · New Mock Copilot binary lookup in all execution tests · New Remove obsolete helper imports and tests Fail closed when only a project-local runtime is found Reject escaping symlinks when probing managed runtimes Add the production executable-discovery hardening Resolve shutil.which calls through imported aliases · New Stub Copilot discovery in all affected tests Stub LLM runtime resolution in integration tests Update Codex tests to stub the required runtime resolver Inspect positional and keyword subprocess commands Assert the CLI succeeds before checking the stand-in marker Embed the absolute marker path in the POSIX stand-in
Review effort: Balanced
Co-authored-by: Copilot App <[email protected]> Co-authored-by: copilot-swe-agent[bot] <[email protected]>
There was a problem hiding this comment.
🔵 Needs a closer look
The lookup check matches only the literal shutil.which spelling, allowing aliased or directly imported calls to bypass the owner guard.
13 open issues
Prevent installer scripts from resolving helpers through project PATH Preserve hardened runtime environments and fail closed on lookup Remove obsolete helper imports and tests Fail closed when only a project-local runtime is found Reject escaping symlinks when probing managed runtimes Add the production executable-discovery hardening Resolve shutil.which calls through imported aliases Stub Copilot discovery in all affected tests Stub LLM runtime resolution in integration tests Update Codex tests to stub the required runtime resolver Inspect positional and keyword subprocess commands Assert the CLI succeeds before checking the stand-in marker Embed the absolute marker path in the POSIX stand-in
1 resolved since last review
Review effort: Balanced
Co-authored-by: Copilot App <[email protected]> Co-authored-by: copilot-swe-agent[bot] <[email protected]>
There was a problem hiding this comment.
🔵 Needs a closer look
Runtime execution still bypasses trusted-path validation, allowing project-controlled executables to run through version probes and ScriptRunner’s bare-name fallback.
13 open issues
Prevent installer scripts from resolving helpers through project PATH Preserve hardened runtime environments and fail closed on lookup Remove obsolete helper imports and tests Fail closed when only a project-local runtime is found Reject escaping symlinks when probing managed runtimes Add the production executable-discovery hardening Resolve shutil.which calls through imported aliases Stub Copilot discovery in all affected tests Stub LLM runtime resolution in integration tests Update Codex tests to stub the required runtime resolver Inspect positional and keyword subprocess commands Assert the CLI succeeds before checking the stand-in marker Embed the absolute marker path in the POSIX stand-in
Review effort: Balanced
Co-authored-by: Copilot App <[email protected]> Co-authored-by: copilot-swe-agent[bot] <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
The runtime version probe can execute a project-controlled binary through an escaping managed-directory symlink because it checks only existence rather than containment.
15 open issues
Prevent installer scripts from resolving helpers through project PATH Preserve hardened runtime environments and fail closed on lookup Remove obsolete helper imports and tests Fail closed when only a project-local runtime is found Reject escaping symlinks when probing managed runtimes Add the production executable-discovery hardening Check keyword-form subprocess commands · New Resolve shutil.which calls through imported aliases Stub Copilot discovery in all affected tests Stub LLM runtime resolution in integration tests Update Codex tests to stub the required runtime resolver Inspect positional and keyword subprocess commands Assert the CLI succeeds before checking the stand-in marker Embed the absolute marker path in the POSIX stand-in Document PATH impact on all platforms and migration · New
Review effort: Balanced
… launched Co-authored-by: Copilot App <[email protected]> Co-authored-by: copilot-swe-agent[bot] <[email protected]>
…e directory Co-authored-by: Copilot App <[email protected]> Co-authored-by: copilot-swe-agent[bot] <[email protected]>
… their directory apm run no longer launches a runtime by bare name when no installed copy outside the project resolves; it stops with an install hint. Runtime listing and availability accept a managed runtime only while it stays inside the runtime directory. The helper guard also reads the args= keyword, annotated argv and shutil import aliases. Co-authored-by: Copilot App <[email protected]> Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: Copilot App <[email protected]> Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: Copilot App <[email protected]> Co-authored-by: copilot-swe-agent[bot] <[email protected]>
There was a problem hiding this comment.
🔵 Needs a closer look
Human assessment is needed to evaluate gaps in executable-launch guard coverage and inconsistencies between runtime availability checks and execution.
No open issues 🎉
15 resolved since last review
Prevent installer scripts from resolving helpers through project PATH Preserve hardened runtime environments and fail closed on lookup Remove obsolete helper imports and tests Fail closed when only a project-local runtime is found Reject escaping symlinks when probing managed runtimes Add the production executable-discovery hardening Check keyword-form subprocess commands Resolve shutil.which calls through imported aliases Stub Copilot discovery in all affected tests Stub LLM runtime resolution in integration tests Update Codex tests to stub the required runtime resolver Inspect positional and keyword subprocess commands Assert the CLI succeeds before checking the stand-in marker Embed the absolute marker path in the POSIX stand-in Document PATH impact on all platforms and migration
Review effort: Balanced
Co-authored-by: Copilot App <[email protected]> Co-authored-by: copilot-swe-agent[bot] <[email protected]>
There was a problem hiding this comment.
🔵 Needs a closer look
Human assessment is needed to evaluate scalar-binding gaps in the architecture guard and conflicting runtime-resolution rules that can make availability checks disagree with execution.
No open issues 🎉
Review effort: Balanced
Co-authored-by: Copilot App <[email protected]> Co-authored-by: copilot-swe-agent[bot] <[email protected]>
There was a problem hiding this comment.
🔵 Needs a closer look
Human assessment is needed because executable discovery can hide valid installations based on the working directory, with additional inconsistencies in managed-runtime and command-specific PATH handling.
No open issues 🎉
Review effort: Balanced



Description
APM launches and probes helper programs such as git, az, npm, codex, PowerShell and external scanners. Several of these call sites passed a bare program name to
subprocess, or located it withshutil.which. On Windows, both search the current directory before PATH. A program of the same name inside the project directory could then run in place of the installed tool.This PR routes every helper lookup and launch through one owner and adds a guard so new code cannot bypass it:
trusted_executable(name)insrc/apm_cli/utils/git_env.pyreturns the absolute path of an installed helper, orNone. It reuses the existing_resolve_trusted_executable, which searches only PATH directories outside the project and never the working directory.is_tool_availableandget_available_package_managershelpers are removed.NoDefaultCurrentDirectoryInExePath=1at start, so child processes also skip the implicit current-directory search.transport-platform-external-executable-owner, rejects a literal helper name as the first argument of asubprocesslaunch and anyshutil.whichcall outside the owner. It comes with mutation cases.Issue and approved scope
Issue: (maintainer-assigned hardening item; no public issue)
Human scope-approval comment: assigned by the maintainer through the program desk.
Does this PR complete the issue, or what remains? It completes the assigned scope.
Type of change
Testing
Red first: the first commit adds cells to
tests/integration/test_trusted_executable_discovery.py(windows_compat, so the Windows gate selects them). Each places a stand-in helper in the project directory and asserts the real tool answers and the stand-in never runs. They cover the lock-evidence git probe, the audit tracked-files git probe (plusapm audit --cion POSIX), the az lookup, the external scanner lookup, the owner skipping., an empty entry and the project path on PATH, and the Windows CLI-start setting. They fail before the fix and pass after it.Changelog
changelog.d/<pr>.<section>.md, holding one line: user-visible effect first, 25 words or fewer, ending with(#PR); breaking changes only under upgrade notes; no Highlights; no new lines under## [Unreleased]. Seechangelog.d/README.mdand.github/instructions/changelog.instructions.md.Spec conformance (OpenAPM v0.1)
CONFORMANCE.{md,json}regeneratedapm-spec-waiver: helper programs are located on PATH outside the project; no manifest, lockfile or resolver contract changes
Follow-up: #5052