Skip to content

Commit af9c949

Browse files
authored
Merge pull request #15488 from danog/request-input-sources
Treat what filter_input(), getallheaders() and other request functions return as user input
2 parents 96a45a1 + 8f4f3be commit af9c949

12 files changed

Lines changed: 1310 additions & 20 deletions

File tree

‎dictionaries/InternalTaintSourceMap.php‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414
* @var array<lowercase-string, non-empty-list<non-empty-string>>
1515
*/
1616
return [
17+
// the request (filter_input() and filter_input_array() are in FilterInputTaints)
18+
'apache_request_headers' => ['return'],
19+
'getallheaders' => ['return'],
20+
'request_parse_body' => ['return'],
21+
// the terminal, as with STDIN
22+
'readline' => ['return'],
1723
// sockets
1824
'socket_read' => ['return'],
1925
'socket_recv' => ['data'],

‎docs/security_analysis/index.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -778,12 +778,13 @@ Psalm treats the following built-in inputs as taint sources:
778778
| Category | Built-in sources |
779779
|---|---|
780780
| **Request superglobals** | `$_GET`, `$_POST`, `$_COOKIE`, `$_REQUEST` |
781+
| **Request functions** | `filter_input()` and `filter_input_array()`, except for what the filter removes (`FILTER_VALIDATE_INT`, ...); `getallheaders()`, `apache_request_headers()` and `request_parse_body()` |
781782
| **Environment** | `getenv()` and `$_ENV` (chosen by whoever starts the process) |
782783
| **Client-controlled `$_SERVER` entries** | Request headers (`HTTP_*`), URI fields (`REQUEST_URI`, `QUERY_STRING`, `PATH_INFO`, `PHP_SELF`, `argv`, ...), `REQUEST_METHOD`, `CONTENT_TYPE`, HTTP auth credentials, redirected equivalents (`REDIRECT_*`), and any read using a non-literal key (`$_SERVER[$key]`) |
783784
| **Uploaded files** | Each file's `name`, `type`, and `full_path` in `$_FILES` |
784785
| **PSR-7 HTTP messages** | Return values of `Psr\Http\Message\ServerRequestInterface`, `ResponseInterface`, `UriInterface`, `StreamInterface`, `UploadedFileInterface`, and implementations (covering framework requests and HTTP client responses such as Guzzle) |
785786
| **Symfony HTTP client responses** | `getContent()`, `toArray()`, `getHeaders()` and `getInfo()` of `Symfony\Contracts\HttpClient\ResponseInterface`, and the content of the chunks `HttpClientInterface::stream()` yields |
786-
| **Input streams** | `STDIN`; `fopen()`, `file_get_contents()`, and `file()` on literal `php://input` or `php://stdin`; and stream readers (`fgets()`, `fread()`, `stream_get_contents()`, ...) reading those handles |
787+
| **Input streams** | `STDIN`; `readline()`; `fopen()`, `file_get_contents()`, and `file()` on literal `php://input` or `php://stdin`; and stream readers (`fgets()`, `fread()`, `stream_get_contents()`, ...) reading those handles |
787788
| **Server responses** | `fopen()`, `file_get_contents()`, and `file()` on a URL starting with a literal `http://`, `https://`, `ftp://` or `ftps://` (as `file_get_contents('https://api.example.com/items/' . $id)`), and stream readers reading those handles |
788789
| **Databases** | What the program stored in a database, where it reads it back (see [Databases](taint_flow.md#databases)) |
789790
| **Network I/O** | `socket_read()`, `stream_socket_recvfrom()`, `curl_exec()`, `curl_multi_getcontent()`; by-reference data from `socket_recv()`, `socket_recvfrom()`, `socket_recvmsg()`; and streams opened with `fsockopen()`, `pfsockopen()`, `stream_socket_client()`, `stream_socket_accept()`, `socket_export_stream()` |

0 commit comments

Comments
 (0)