Skip to content

fix(windows): resolve helper executables outside the project directory - #5006

Merged
Daniel Meppiel (danielmeppiel) merged 16 commits into
mainfrom
windows-trusted-executables
Nov 23, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 16 commits into
mainfrom
windows-trusted-executables

Conversation

@danielmeppiel

@danielmeppiel Daniel Meppiel (danielmeppiel) commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

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 with shutil.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) in src/apm_cli/utils/git_env.py returns the absolute path of an installed helper, or None. It reuses the existing _resolve_trusted_executable, which searches only PATH directories outside the project and never the working directory.
  • Call sites now launch the resolved path: the lock-evidence and audit git probes, the az bearer token lookup, the external scanner lookup, the codex native client, the self-update installer shell, and the runtime manager (npm, PowerShell and runtime binaries). Presence checks use the owner too. The unused is_tool_available and get_available_package_managers helpers are removed.
  • On Windows the CLI sets NoDefaultCurrentDirectoryInExePath=1 at start, so child processes also skip the implicit current-directory search.
  • A new architecture rule, transport-platform-external-executable-owner, rejects a literal helper name as the first argument of a subprocess launch and any shutil.which call 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

  • Bug fix
  • New feature
  • Documentation
  • Maintenance / refactor

Testing

  • Tested locally
  • All existing tests pass
  • Added tests for new functionality (if applicable)

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 (plus apm audit --ci on 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

  • One fragment per section, 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]. See changelog.d/README.md and .github/instructions/changelog.instructions.md.
  • N/A -- internal-only change (CI, tests, refactor).

Spec conformance (OpenAPM v0.1)

  • Spec edit
  • Manifest edit
  • Test edit
  • CONFORMANCE.{md,json} regenerated
  • N/A -- this PR does not change OpenAPM-observable behaviour.

apm-spec-waiver: helper programs are located on PATH outside the project; no manifest, lockfile or resolver contract changes

Follow-up: #5052

…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]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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 --ci subprocess 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]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread src/apm_cli/runtime/manager.py Resolved
Comment thread src/apm_cli/runtime/utils.py Resolved
Comment thread src/apm_cli/utils/helpers.py Resolved
Comment thread src/apm_cli/runtime/codex_runtime.py Resolved
Comment thread src/apm_cli/runtime/llm_runtime.py Resolved
Comment thread tests/unit/test_copilot_runtime.py Resolved
…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]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread src/apm_cli/core/script_runner.py Resolved
Comment thread src/apm_cli/runtime/manager.py Resolved
Comment thread tests/unit/test_copilot_runtime.py Resolved
Co-authored-by: Copilot App <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Co-authored-by: Copilot App <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Co-authored-by: Copilot App <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

… 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]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Co-authored-by: Copilot App <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 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]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants