Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On Windows, don't rely on the OS to find executables #12180

Merged
merged 15 commits into from
Nov 6, 2024

Conversation

nicolas-grekas
Copy link
Contributor

Windows always looks up in the current directory when searching for a binary.
This is risky practice, so this PR tries to prevent this by using ExecutableFinder instead (which looks up using the PATH only).

While at it, I replaced all string command lines by array commands. This removed the need for explicit argument escaping.
Some remain, but most are removed.

@nicolas-grekas nicolas-grekas force-pushed the windows-executable-finder branch 7 times, most recently from da7e9af to 728106c Compare October 29, 2024 11:03
Copy link
Contributor Author

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

Grepping for ProcessExecutor::escape is the best way to see what remains of string command-lines after this PR:

  • ZipDownloader: could be turned into array commands
  • Util\Svn: this one is rooted for string command-lines (execute(string $command, ...))
  • EventDispatcher: this class runs scripts only if allowed to so its safe
  • Perforce: executeCommand is document as @param non-empty-string $command
  • SvnDownloader: because it uses Util\Svn

These classes are nonetheless hardened thanks to the added logic in ProcessExecutor.

src/Composer/Util/ProcessExecutor.php Show resolved Hide resolved
src/Composer/Downloader/GitDownloader.php Show resolved Hide resolved
src/Composer/Downloader/GitDownloader.php Show resolved Hide resolved
src/Composer/Downloader/GitDownloader.php Outdated Show resolved Hide resolved
@nicolas-grekas
Copy link
Contributor Author

Symfony "generic" PR at symfony/symfony#58710

@Seldaek Seldaek force-pushed the windows-executable-finder branch from cfa5be4 to 7578df9 Compare October 30, 2024 16:33
@Seldaek Seldaek force-pushed the windows-executable-finder branch from 944c76a to e641d60 Compare October 31, 2024 10:49
@nicolas-grekas nicolas-grekas changed the title On Windows, we don't rely on the OS to find executables On Windows, don't rely on the OS to find executables Oct 31, 2024
@Seldaek Seldaek force-pushed the windows-executable-finder branch from 69ceac3 to a7fee29 Compare November 1, 2024 23:01
@Seldaek Seldaek force-pushed the windows-executable-finder branch 2 times, most recently from 995b37b to 88c5f2d Compare November 1, 2024 23:48
nicolas-grekas added a commit to symfony/symfony that referenced this pull request Nov 4, 2024
…tables (nicolas-grekas)

This PR was merged into the 7.2 branch.

Discussion
----------

[Process] On Windows, don't rely on the OS to find executables

| Q             | A
| ------------- | ---
| Branch?       | 7.2
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Issues        | -
| License       | MIT

Porting part of composer/composer#12180 here:

On Windows, when searching for an executable, the OS always looks at the current directory before using the PATH variable. This makes it easier than desired to hijack executables. Unix-like OSes don't have this issue.

This PR proposes to rely on ExecutableFinder instead.

Commits
-------

b35a7d4 [Process] On Windows, don't rely on the OS to find executables
symfony-splitter pushed a commit to symfony/process that referenced this pull request Nov 4, 2024
…tables (nicolas-grekas)

This PR was merged into the 7.2 branch.

Discussion
----------

[Process] On Windows, don't rely on the OS to find executables

| Q             | A
| ------------- | ---
| Branch?       | 7.2
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Issues        | -
| License       | MIT

Porting part of composer/composer#12180 here:

On Windows, when searching for an executable, the OS always looks at the current directory before using the PATH variable. This makes it easier than desired to hijack executables. Unix-like OSes don't have this issue.

This PR proposes to rely on ExecutableFinder instead.

Commits
-------

b35a7d42931 [Process] On Windows, don't rely on the OS to find executables
@Seldaek Seldaek force-pushed the windows-executable-finder branch from 88c5f2d to 6058e49 Compare November 6, 2024 09:34
Copy link

private-packagist bot commented Nov 6, 2024

composer.lock

Package changes

Package Operation From To About
composer/ca-bundle upgrade 1.5.2 1.5.3 diff
symfony/console upgrade v5.4.45 v5.4.46 diff
symfony/process upgrade v5.4.45 ⚠️ v5.4.46 ✅ diff

Dev Package changes

Package Operation From To About
phpstan/phpstan-symfony upgrade 1.4.10 1.4.11 diff

Settings · Docs · Powered by Private Packagist

@Seldaek Seldaek added this to the 2.8 milestone Nov 6, 2024
@Seldaek Seldaek merged commit 3dc279c into composer:main Nov 6, 2024
20 checks passed
@Seldaek
Copy link
Member

Seldaek commented Nov 6, 2024

Thanks!

@nicolas-grekas nicolas-grekas deleted the windows-executable-finder branch November 6, 2024 12:50
@nicolas-grekas
Copy link
Contributor Author

Thanks too!

Copy link

The composer.lock diff comment has been updated to reflect new changes in this PR.

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

Successfully merging this pull request may close these issues.

2 participants