diff --git a/core/lib/Drupal/Core/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php index 0ca30ea..1a4e0a0 100644 --- a/core/lib/Drupal/Core/DrupalKernel.php +++ b/core/lib/Drupal/Core/DrupalKernel.php @@ -29,6 +29,7 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; use Symfony\Component\HttpKernel\TerminableInterface; use Composer\Autoload\ClassLoader; @@ -293,12 +294,28 @@ public function __construct($environment, $class_loader, $allow_dumping = TRUE) * @return string * The path of the matching directory. * + * @throws BadRequestHttpException + * * @see \Drupal\Core\DrupalKernelInterface::getSitePath() * @see \Drupal\Core\DrupalKernelInterface::setSitePath() * @see default.settings.php * @see example.sites.php */ public static function findSitePath(Request $request, $require_settings = TRUE) { + // Validate the hostname. $request->getHost can also throw a + // UnexpectedValueException if it detects a bad hostname, but it does not + // validate the length. + // @todo Adjust per resolution to https://github.com/symfony/symfony/issues/12349 + try { + $http_host = $request->getHost(); + if (self::validateHostnameLength($http_host) == FALSE) { + throw new \UnexpectedValueException('Bad hostname'); + } + } + catch (\UnexpectedValueException $e) { + throw new BadRequestHttpException('Bad hostname'); + } + // Check for a simpletest override. if ($test_prefix = drupal_valid_test_ua()) { return 'sites/simpletest/' . substr($test_prefix, 10); @@ -315,9 +332,6 @@ public static function findSitePath(Request $request, $require_settings = TRUE) $script_name = $request->server->get('SCRIPT_FILENAME'); } $http_host = $request->getHost(); - if (self::validateHostnameLength($http_host) == FALSE) { - throw new \UnexpectedValueException('Bad hostname'); - } $sites = array(); include DRUPAL_ROOT . '/sites/sites.php'; diff --git a/index.php b/index.php index 406d3dc..3de0a31 100644 --- a/index.php +++ b/index.php @@ -10,7 +10,9 @@ use Drupal\Core\DrupalKernel; use Drupal\Core\Site\Settings; +use Symfony\Component\HttpKernel\Exception\HttpException; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; $autoloader = require_once __DIR__ . '/core/vendor/autoload.php'; @@ -24,6 +26,11 @@ ->prepare($request)->send(); $kernel->terminate($request, $response); } +catch (HttpException $e) { + $code = $e->getStatusCode(); + http_response_code($code); + print Response::$statusTexts[$code]; +} catch (Exception $e) { $message = 'If you have just changed code (for example deployed a new module or moved an existing one) read http://drupal.org/documentation/rebuild'; if (Settings::get('rebuild_access', FALSE)) {