Skip to content

Commit 197cb38

Browse files
committed
bug symfony#14497 [HttpFoundation] Allow curly braces in trusted host patterns (sgrodzicki)
This PR was merged into the 2.3 branch. Discussion ---------- [HttpFoundation] Allow curly braces in trusted host patterns | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Let's say I want to whilelist Amazon CloudFront hosts: ```php Request::setTrustedHosts(array('^d[a-z0-9]{13}\.cloudfront\.net$')); ``` See: symfony#14489 Commits ------- 6038b75 [HttpFoundation] Allow curly braces in trusted host patterns
2 parents 7f24883 + 6038b75 commit 197cb38

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/Symfony/Component/HttpFoundation/Request.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ public static function getTrustedProxies()
553553
public static function setTrustedHosts(array $hostPatterns)
554554
{
555555
self::$trustedHostPatterns = array_map(function ($hostPattern) {
556-
return sprintf('{%s}i', str_replace('}', '\\}', $hostPattern));
556+
return sprintf('#%s#i', $hostPattern);
557557
}, $hostPatterns);
558558
// we need to reset trusted hosts on trusted host patterns change
559559
self::$trustedHosts = array();

src/Symfony/Component/HttpFoundation/Tests/RequestTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1601,7 +1601,7 @@ public function testTrustedHosts()
16011601
$this->assertEquals('evil.com', $request->getHost());
16021602

16031603
// add a trusted domain and all its subdomains
1604-
Request::setTrustedHosts(array('.*\.?trusted.com$'));
1604+
Request::setTrustedHosts(array('^([a-z]{9}\.)?trusted\.com$'));
16051605

16061606
// untrusted host
16071607
$request->headers->set('host', 'evil.com');

0 commit comments

Comments
 (0)