Harden ExecuteTask with per-arg escapeshellarg and allow-list#485
Merged
dereuromark merged 1 commit intomasterfrom May 2, 2026
Merged
Harden ExecuteTask with per-arg escapeshellarg and allow-list#485dereuromark merged 1 commit intomasterfrom
dereuromark merged 1 commit intomasterfrom
Conversation
The ExecuteTask previously concatenated `command` and each `params` entry
through `escapeshellcmd()`, which only neutralizes shell metacharacters
(`; & | $`, etc.) and does NOT defend against argument injection. A
payload like `params => ['-r --some-flag /etc/passwd']` would still split
across additional shell tokens once `exec()` re-tokenized the line.
Switch the escape primitive to per-token `escapeshellarg()` so each
argument is wrapped as a single shell token (`ExecuteTask.php:97-110`).
This is a behavior change for callers that previously embedded multiple
tokens inside a single `params` entry: they must now split such entries
across the `params` array.
Add a `Queue.executeAllowedCommands` allow-list that is enforced
whenever `debug` is disabled (`ExecuteTask.php:93-100`). With debug off
and no allow-list configured, every Execute job is rejected before
`exec()` is reached. This protects environments where an attacker
gains DB write access to `queued_jobs`, or where upstream code
unexpectedly pipes user input into `createJob('Queue.Execute', ...)`.
Update the existing tests to use the supported separated
command/params shape, and add four regression tests covering the
arg-injection token quoting and the allow-list deny/empty/allow paths
(`ExecuteTaskTest.php`). Refresh the docs section to describe the new
escaping primitive and the production allow-list requirement.
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #485 +/- ##
============================================
+ Coverage 77.38% 77.54% +0.16%
- Complexity 963 966 +3
============================================
Files 45 45
Lines 3232 3238 +6
============================================
+ Hits 2501 2511 +10
+ Misses 731 727 -4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two-part hardening of
Queue.Execute:escapeshellcmd()to per-tokenescapeshellarg()for the command and eachparamsentry. The previous primitive only neutralizes shell metacharacters and cannot defend against argument injection (e.g. aparamsentry like-r --some-flag /etc/passwdwould still split into multiple shell tokens onceexec()re-tokenized the line). Withescapeshellarg()each entry is wrapped as one quoted token.Queue.executeAllowedCommandsallow-list that is enforced wheneverdebugis disabled. With debug off and no allow-list configured, every Execute job is rejected beforeexec()is reached. This protects environments where an attacker gains DB write access toqueued_jobs, or where upstream code unexpectedly pipes user input intocreateJob('Queue.Execute', ...).Notes
paramsentry: they must now split such entries across theparamsarray. The two existing tests that depended on the old behavior were updated to the supported shape.docs/sections/tasks/execute.mdupdated to describe the new escaping primitive and the production allow-list requirement.Verification
vendor/bin/phpunit— 176 passingvendor/bin/phpstan analyze— no errorsvendor/bin/phpcs src/— clean