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

ValidatedSanitizedInput: Add support for picking up on variables in heredocs #890

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion WordPress/Sniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -1515,7 +1515,7 @@ protected function get_use_type( $stackPtr ) {
*
* @since 0.9.0
*
* @param string $string A T_DOUBLE_QUOTED_STRING token.
* @param string $string A T_DOUBLE_QUOTED_STRING or T_HEREDOC token.
*
* @return array Variable names (without '$' sigil).
*/
Expand Down
5 changes: 4 additions & 1 deletion WordPress/Sniffs/VIP/ValidatedSanitizedInputSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public function register() {
return array(
T_VARIABLE,
T_DOUBLE_QUOTED_STRING,
T_HEREDOC,
);
}

Expand All @@ -85,7 +86,9 @@ public function process_token( $stackPtr ) {
$superglobals = $this->input_superglobals;

// Handling string interpolation.
if ( T_DOUBLE_QUOTED_STRING === $this->tokens[ $stackPtr ]['code'] ) {
if ( T_DOUBLE_QUOTED_STRING === $this->tokens[ $stackPtr ]['code']
|| T_HEREDOC === $this->tokens[ $stackPtr ]['code']
) {
$interpolated_variables = array_map(
create_function( '$symbol', 'return "$" . $symbol;' ), // Replace with closure when 5.3 is minimum requirement for PHPCS.
$this->get_interpolated_variables( $this->tokens[ $stackPtr ]['content'] )
Expand Down
11 changes: 11 additions & 0 deletions WordPress/Tests/VIP/ValidatedSanitizedInputUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,14 @@ function test_this() {

$abc = sanitize_twitter_handle( $_POST['abc_field'] ); // Bad x2, sanitize + unslash.
}

// Variables in heredocs.
output( <<<EOD
some string \$_POST[some_var]
EOD
); // Ok.

output( <<<EOD
some string {$_POST[some_var]} {$_GET['evil']}
EOD
); // Bad x2.
1 change: 1 addition & 0 deletions WordPress/Tests/VIP/ValidatedSanitizedInputUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public function getErrorList() {
137 => 1,
138 => 1,
150 => 2,
160 => 2,
);

}
Expand Down