Skip to content

Commit 367aa1d

Browse files
committed
minor #37431 [HttpKernel] hide "_password" in request data collector raw content (EfeloPHP)
This PR was merged into the 5.2-dev branch. Discussion ---------- [HttpKernel] hide "_password" in request data collector raw content The password was already hidden in POST parameters, but still remained visible in raw content. | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | Deprecations? | no | License | MIT This is my first contribution, so I hope I did everything right :) Commits ------- 715c793 [HttpKernel] added password hiding in request data collector raw content
2 parents 488e2c9 + 715c793 commit 367aa1d

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

src/Symfony/Component/HttpKernel/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ CHANGELOG
88
* made the public `http_cache` service handle requests when available
99
* allowed enabling trusted hosts and proxies using new `kernel.trusted_hosts`,
1010
`kernel.trusted_proxies` and `kernel.trusted_headers` parameters
11+
* content of request parameter `_password` is now also hidden
12+
in the request profiler raw content section
1113

1214
5.1.0
1315
-----

src/Symfony/Component/HttpKernel/DataCollector/RequestDataCollector.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ public function collect(Request $request, Response $response, \Throwable $except
9595
$this->data = [
9696
'method' => $request->getMethod(),
9797
'format' => $request->getRequestFormat(),
98-
'content' => $content,
9998
'content_type' => $response->headers->get('Content-Type', 'text/html'),
10099
'status_text' => isset(Response::$statusTexts[$statusCode]) ? Response::$statusTexts[$statusCode] : '',
101100
'status_code' => $statusCode,
@@ -129,9 +128,13 @@ public function collect(Request $request, Response $response, \Throwable $except
129128
}
130129

131130
if (isset($this->data['request_request']['_password'])) {
131+
$encodedPassword = rawurlencode($this->data['request_request']['_password']);
132+
$content = str_replace('_password='.$encodedPassword, '_password=******', $content);
132133
$this->data['request_request']['_password'] = '******';
133134
}
134135

136+
$this->data['content'] = $content;
137+
135138
foreach ($this->data as $key => $value) {
136139
if (!\is_array($value)) {
137140
continue;

src/Symfony/Component/HttpKernel/Tests/DataCollector/RequestDataCollectorTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,27 @@ public function testStatelessCheck()
310310
$this->assertTrue($collector->getStatelessCheck());
311311
}
312312

313+
public function testItHidesPassword()
314+
{
315+
$c = new RequestDataCollector();
316+
317+
$request = Request::create(
318+
'http://test.com/login',
319+
'POST',
320+
['_password' => ' _password@123'],
321+
[],
322+
[],
323+
[],
324+
'_password=%20_password%40123'
325+
);
326+
327+
$c->collect($request, $this->createResponse());
328+
$c->lateCollect();
329+
330+
$this->assertEquals('******', $c->getRequestRequest()->get('_password'));
331+
$this->assertEquals('_password=******', $c->getContent());
332+
}
333+
313334
protected function createRequest($routeParams = ['name' => 'foo'])
314335
{
315336
$request = Request::create('http://test.com/foo?bar=baz');

0 commit comments

Comments
 (0)