From fd2f63382a6aec83731b8ef6c024939d999bb970 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 21 Aug 2013 12:06:02 +0200 Subject: [PATCH] Include untrusted host in the exception message --- src/Symfony/Component/HttpFoundation/Request.php | 4 ++-- src/Symfony/Component/HttpFoundation/Tests/RequestTest.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/HttpFoundation/Request.php b/src/Symfony/Component/HttpFoundation/Request.php index ef0551c266..87a1b4cfef 100644 --- a/src/Symfony/Component/HttpFoundation/Request.php +++ b/src/Symfony/Component/HttpFoundation/Request.php @@ -1101,7 +1101,7 @@ class Request // as the host can come from the user (HTTP_HOST and depending on the configuration, SERVER_NAME too can come from the user) // check that it does not contain forbidden characters (see RFC 952 and RFC 2181) if ($host && !preg_match('/^\[?(?:[a-zA-Z0-9-:\]_]+\.?)+$/', $host)) { - throw new \UnexpectedValueException('Invalid Host'); + throw new \UnexpectedValueException('Invalid Host "'.$host.'"'); } if (count(self::$trustedHostPatterns) > 0) { @@ -1119,7 +1119,7 @@ class Request } } - throw new \UnexpectedValueException('Untrusted Host'); + throw new \UnexpectedValueException('Untrusted Host "'.$host.'"'); } return $host; diff --git a/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php b/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php index c41028d81c..ba95c4aea9 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php @@ -1520,7 +1520,7 @@ class RequestTest extends \PHPUnit_Framework_TestCase $request->getHost(); $this->fail('Request::getHost() should throw an exception when host is not trusted.'); } catch (\UnexpectedValueException $e) { - $this->assertEquals('Untrusted Host', $e->getMessage()); + $this->assertEquals('Untrusted Host "evil.com"', $e->getMessage()); } // trusted hosts