Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,18 @@ public function process_parameters( $stackPtr, $group_name, $matched_content, $p
$search_start = $param_start;
// phpcs:ignore Generic.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition -- Valid usage.
while ( ( $has_text_string = $this->phpcsFile->findNext( Tokens::$stringTokens, $search_start, $search_end ) ) !== false ) {
if ( strpos( $this->tokens[ $has_text_string ]['content'], '://' ) !== false ) {
$string_content = $this->tokens[ $has_text_string ]['content'];
if ( strpos( $string_content, '://' ) !== false ) {
/*
* The `php://` stream wrappers (php://input, php://stdin, php://memory,
* php://temp, etc.) are local, in-process streams rather than remote
* requests, so should not be flagged. The scheme is case-insensitive.
*/
if ( preg_match( '`^["\']?php://`i', $string_content ) === 1 ) {
$search_start = ( $has_text_string + 1 );
continue;
}

$isRemoteFile = true;
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,13 @@ $result = file_get_contents(( is_ssl() ? 'http' : 'https' ) . '://example.com');

// Bug: don't presume if the parameter contains a text string token, that will be the only token.
\file_get_contents( $url . '/filename.css' ); // Warning FileGetContentsUnknown.

// Bug #506: the `php://` stream wrappers are local, in-process streams, not remote requests, so should not be flagged.
$webhook_body = file_get_contents( 'php://input' ); // OK.
$std_input = \file_get_contents( 'php://stdin' ); // OK.
$in_memory = file_get_contents( "php://memory" ); // OK.
$temp_stream = file_get_contents( 'php://temp/maxmemory:1048576' ); // OK.
$case_insensitive = file_get_contents( 'PHP://input' ); // OK. The scheme is case-insensitive.

// Bug #506: a `php://` substring which is not the URL scheme must still be flagged as remote.
$masked_remote = file_get_contents( 'https://example.com/?redirect=php://input' ); // Warning FileGetContentsRemoteFile.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public function getWarningList() {
79 => 1,
85 => 1,
88 => 1,
98 => 1,
];
}
}