Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit aba5490

Browse files
minor #45197 [Process] Update PHPDoc to use proper placeholder syntax (chrismcgehee)
This PR was squashed before being merged into the 4.4 branch. Discussion ---------- [Process] Update PHPDoc to use proper placeholder syntax | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | no | License | MIT | Doc PR | no I'd like to add this PHPDoc comment to help make sure `Process::fromShellCommandline` is used securely. The other day, one of the developers at my company wrote some code that was roughly like: ```php $process = Process::fromShellCommandline('find $FILENAME'); $process->run(null, ['FILENAME' => $fileName]); ``` Since `$fileName` is user input, he thought he was doing the secure thing by using placeholders. The issue is that a malicious user could have utilized the `-exec` option of `find` to gain arbitrary code execution, for example `$fileName = '. -exec echo Foo! ;'`. This can be fixed by simply surrounding `$FILENAME` with double quotes because this passes the input as a single argument to `find` instead of passing it as multiple arguments. I believe there are enough programs out there that can be manipulated if an attacker is able to control multiple arguments that it's worth putting a warning here to help prevent the mistake of not surrounding placeholders with quotes. Commits ------- a2ecf08 [Process] Update PHPDoc to use proper placeholder syntax
2 parents fa6a03a + a2ecf08 commit aba5490

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/Symfony/Component/Process/Process.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public function __construct($command, string $cwd = null, array $env = null, $in
177177
* In order to inject dynamic values into command-lines, we strongly recommend using placeholders.
178178
* This will save escaping values, which is not portable nor secure anyway:
179179
*
180-
* $process = Process::fromShellCommandline('my_command "$MY_VAR"');
180+
* $process = Process::fromShellCommandline('my_command "${:MY_VAR}"');
181181
* $process->run(null, ['MY_VAR' => $theValue]);
182182
*
183183
* @param string $command The command line to pass to the shell of the OS

0 commit comments

Comments
 (0)