Skip to content

[Process] Update PHPDoc to use proper placeholder syntax #45197

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

Merged
merged 1 commit into from
Jan 27, 2022

Conversation

ristomcgehee
Copy link

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:

$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.

@carsonbot
Copy link

Hey!

I see that this is your first PR. That is great! Welcome!

Symfony has a contribution guide which I suggest you to read.

In short:

  • Always add tests
  • Keep backward compatibility (see https://symfony.com/bc).
  • Bug fixes must be submitted against the lowest maintained branch where they apply (see https://symfony.com/releases)
  • Features and deprecations must be submitted against the 6.1 branch.

Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change.

When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor!
If this PR is merged in a lower version branch, it will be merged up to all maintained branches within a few days.

I am going to sit back now and wait for the reviews.

Cheers!

Carsonbot

@@ -180,6 +180,9 @@ public function __construct($command, string $cwd = null, array $env = null, $in
* $process = Process::fromShellCommandline('my_command "$MY_VAR"');
* $process->run(null, ['MY_VAR' => $theValue]);
*
* It is also recommended to use double quotes around placeholders. This will help ensure the value
Copy link
Member

Choose a reason for hiding this comment

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

this is already strongly recommended just above. Feel free to improve the above sentence if you want, but recommending twice looks duplicate to me.

but note that the comment is wrong: since #34848, ppl should use "${:MY_VAR}" and not "$MY_VAR".

Copy link
Author

Choose a reason for hiding this comment

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

Ok, using "${:MY_VAR}" should address my concern. If the developer leaves off the double quotes, the substitution won't work, so they'll be less likely to create an argument injection vulnerability. I've updated the PR to use the "${:MY_VAR}" syntax in the phpdoc here.

@ristomcgehee ristomcgehee changed the title [Process] Recommend double quotes with placeholders [Process] Update PHPDoc to use proper placeholder syntax Jan 27, 2022
@nicolas-grekas
Copy link
Member

Thank you @chrismcgehee.

@nicolas-grekas nicolas-grekas merged commit aba5490 into symfony:4.4 Jan 27, 2022
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.

3 participants