Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1d52937

Browse filesBrowse files
bug #50226 [HttpClient] Ensure HttplugClient ignores invalid HTTP headers (nicolas-grekas)
This PR was merged into the 5.4 branch. Discussion ---------- [HttpClient] Ensure HttplugClient ignores invalid HTTP headers | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Something we forgot in #47415 Commits ------- f702e66 [HttpClient] Ensure HttplugClient ignores invalid HTTP headers
2 parents 3683d73 + f702e66 commit 1d52937
Copy full SHA for 1d52937

File tree

Expand file treeCollapse file tree

3 files changed

+24
-1
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+24
-1
lines changed

‎composer.json

Copy file name to clipboardExpand all lines: composer.json
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@
165165
},
166166
"config": {
167167
"allow-plugins": {
168+
"php-http/discovery": false,
168169
"symfony/runtime": true
169170
}
170171
},

‎src/Symfony/Component/HttpClient/Internal/HttplugWaitLoop.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpClient/Internal/HttplugWaitLoop.php
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,11 @@ public function createPsr7Response(ResponseInterface $response, bool $buffer = f
120120

121121
foreach ($response->getHeaders(false) as $name => $values) {
122122
foreach ($values as $value) {
123-
$psrResponse = $psrResponse->withAddedHeader($name, $value);
123+
try {
124+
$psrResponse = $psrResponse->withAddedHeader($name, $value);
125+
} catch (\InvalidArgumentException $e) {
126+
// ignore invalid header
127+
}
124128
}
125129
}
126130

‎src/Symfony/Component/HttpClient/Tests/HttplugClientTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpClient/Tests/HttplugClientTest.php
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,4 +267,22 @@ function (\Exception $exception) use ($errorMessage, &$failureCallableCalled, $c
267267
$this->assertSame(200, $response->getStatusCode());
268268
$this->assertSame('OK', (string) $response->getBody());
269269
}
270+
271+
public function testInvalidHeaderResponse()
272+
{
273+
$responseHeaders = [
274+
// space in header name not allowed in RFC 7230
275+
' X-XSS-Protection' => '0',
276+
'Cache-Control' => 'no-cache',
277+
];
278+
$response = new MockResponse('body', ['response_headers' => $responseHeaders]);
279+
$this->assertArrayHasKey(' x-xss-protection', $response->getHeaders());
280+
281+
$client = new HttplugClient(new MockHttpClient($response));
282+
$request = $client->createRequest('POST', 'http://localhost:8057/post')
283+
->withBody($client->createStream('foo=0123456789'));
284+
285+
$resultResponse = $client->sendRequest($request);
286+
$this->assertCount(1, $resultResponse->getHeaders());
287+
}
270288
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.