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 9ee5ff7

Browse filesBrowse files
minor #30561 [HttpClient] strengthen bearer validation (nicolas-grekas)
This PR was merged into the 4.3-dev branch. Discussion ---------- [HttpClient] strengthen bearer validation | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Better be sure CR/LF/etc cannot be passed inside raw header values, opening potential security risks. Commits ------- e6e1620 [HttpClient] strengthen bearer validation
2 parents 59e6380 + e6e1620 commit 9ee5ff7
Copy full SHA for 9ee5ff7

File tree

Expand file treeCollapse file tree

2 files changed

+12
-3
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+12
-3
lines changed

‎src/Symfony/Component/HttpClient/HttpClientTrait.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpClient/HttpClientTrait.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ private static function prepareRequest(?string $method, ?string $url, array $opt
8484
throw new InvalidArgumentException(sprintf('Option "auth_basic" must be string or an array, %s given.', \gettype($options['auth_basic'])));
8585
}
8686

87-
if (!\is_string($options['auth_bearer'] ?? '')) {
88-
throw new InvalidArgumentException(sprintf('Option "auth_bearer" must be string, %s given.', \gettype($options['auth_bearer'])));
87+
if (isset($options['auth_bearer']) && (!\is_string($options['auth_bearer']) || !preg_match('{^[-._~+/0-9a-zA-Z]++=*+$}', $options['auth_bearer']))) {
88+
throw new InvalidArgumentException(sprintf('Option "auth_bearer" must be a string containing only characters from the base 64 alphabet, %s given.', \is_string($options['auth_bearer']) ? 'invalid string' : \gettype($options['auth_bearer'])));
8989
}
9090

9191
if (isset($options['auth_basic'], $options['auth_bearer'])) {

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpClient/Tests/HttpClientTraitTest.php
+10-1Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,22 @@ public function testAuthBearerOption()
174174

175175
/**
176176
* @expectedException \Symfony\Component\HttpClient\Exception\InvalidArgumentException
177-
* @expectedExceptionMessage Option "auth_bearer" must be string, object given.
177+
* @expectedExceptionMessage Option "auth_bearer" must be a string containing only characters from the base 64 alphabet, object given.
178178
*/
179179
public function testInvalidAuthBearerOption()
180180
{
181181
self::prepareRequest('POST', 'http://example.com', ['auth_bearer' => new \stdClass()], HttpClientInterface::OPTIONS_DEFAULTS);
182182
}
183183

184+
/**
185+
* @expectedException \Symfony\Component\HttpClient\Exception\InvalidArgumentException
186+
* @expectedExceptionMessage Option "auth_bearer" must be a string containing only characters from the base 64 alphabet, invalid string given.
187+
*/
188+
public function testInvalidAuthBearerValue()
189+
{
190+
self::prepareRequest('POST', 'http://example.com', ['auth_bearer' => "a\nb"], HttpClientInterface::OPTIONS_DEFAULTS);
191+
}
192+
184193
/**
185194
* @expectedException \Symfony\Component\HttpClient\Exception\InvalidArgumentException
186195
* @expectedExceptionMessage Define either the "auth_basic" or the "auth_bearer" option, setting both is not supported.

0 commit comments

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