Skip to content

Harden shell execution: fail loudly on missing test directory - #4

Merged
mohaelmrabet merged 1 commit into
masterfrom
security/robust-test-dir-handling
Aug 30, 2026
Merged

mohaelmrabet merged 1 commit into
masterfrom
security/robust-test-dir-handling

Conversation

@mohaelmrabet

Copy link
Copy Markdown
Contributor

Summary

  • realpath() can return false if a dev/tests/* directory does not exist; the code then called chdir(false) without checking, silently running paratest in an unintended working directory instead of failing.
  • Now reports the missing directory and records it as a failure instead.
  • Documented why --arguments/-c is intentionally passed through unescaped to the shell command (mirrors Magento's native dev:tests:run; it must carry multiple shell tokens like --filter=Foo bar.php, and this is a local dev CLI invoked by the developer, not fed untrusted remote input) — reviewed as part of an open-source readiness pass, no injection vector found beyond what upstream Magento already accepts.

Test plan

  • Added testMissingTestDirectoryIsReportedAsFailure covering the new branch
  • CI green (PHPStan / PHP-CS-Fixer / PHPUnit)

Previously chdir(realpath(...)) would chdir(false) silently if the
target dev/tests directory did not exist, potentially running paratest
in whatever the previous loop iteration's (or the process's original)
working directory was instead of failing loudly. Also document why
$commandArguments is intentionally passed through unescaped (mirrors
Magento's own dev:tests:run, meant to carry multiple shell tokens; this
is a local dev CLI, not fed untrusted remote input).
@mohaelmrabet
mohaelmrabet merged commit d245cb1 into master Aug 30, 2026
3 checks passed
@mohaelmrabet mohaelmrabet mentioned this pull request Aug 30, 2026
1 task
@mohaelmrabet
mohaelmrabet deleted the security/robust-test-dir-handling branch August 30, 2026 10:03
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.

1 participant