Skip to content
Snippets Groups Projects
Commit 9fb76eaf authored by catch's avatar catch
Browse files

Issue #2609076 by alexpott, Darren Oh: Install failure with HTTPS reverse proxy on newer browsers

parent dc736e72
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
use Drupal\Core\Logger\LoggerChannelFactory; use Drupal\Core\Logger\LoggerChannelFactory;
use Drupal\Core\Site\Settings; use Drupal\Core\Site\Settings;
use Drupal\Core\StringTranslation\Translator\FileTranslation; use Drupal\Core\StringTranslation\Translator\FileTranslation;
use Drupal\Core\StackMiddleware\ReverseProxyMiddleware;
use Drupal\Core\Extension\ExtensionDiscovery; use Drupal\Core\Extension\ExtensionDiscovery;
use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\Url; use Drupal\Core\Url;
...@@ -403,6 +404,8 @@ function install_begin_request($class_loader, &$install_state) { ...@@ -403,6 +404,8 @@ function install_begin_request($class_loader, &$install_state) {
$kernel->setSitePath($site_path); $kernel->setSitePath($site_path);
$kernel->boot(); $kernel->boot();
$container = $kernel->getContainer(); $container = $kernel->getContainer();
// If Drupal is being installed behind a proxy, configure the request.
ReverseProxyMiddleware::setSettingsOnRequest($request, Settings::getInstance());
// Register the file translation service. // Register the file translation service.
if (isset($GLOBALS['config']['locale.settings']['translation']['path'])) { if (isset($GLOBALS['config']['locale.settings']['translation']['path'])) {
......
...@@ -47,28 +47,41 @@ public function __construct(HttpKernelInterface $http_kernel, Settings $settings ...@@ -47,28 +47,41 @@ public function __construct(HttpKernelInterface $http_kernel, Settings $settings
*/ */
public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = TRUE) { public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = TRUE) {
// Initialize proxy settings. // Initialize proxy settings.
if ($this->settings->get('reverse_proxy', FALSE)) { static::setSettingsOnRequest($request, $this->settings);
$ip_header = $this->settings->get('reverse_proxy_header', 'X_FORWARDED_FOR'); return $this->httpKernel->handle($request, $type, $catch);
}
/**
* Sets reverse proxy settings on Request object.
*
* @param \Symfony\Component\HttpFoundation\Request $request
* A Request instance.
* @param \Drupal\Core\Site\Settings $settings
* The site settings.
*/
public static function setSettingsOnRequest(Request $request, Settings $settings) {
// Initialize proxy settings.
if ($settings->get('reverse_proxy', FALSE)) {
$ip_header = $settings->get('reverse_proxy_header', 'X_FORWARDED_FOR');
$request::setTrustedHeaderName($request::HEADER_CLIENT_IP, $ip_header); $request::setTrustedHeaderName($request::HEADER_CLIENT_IP, $ip_header);
$proto_header = $this->settings->get('reverse_proxy_proto_header', 'X_FORWARDED_PROTO'); $proto_header = $settings->get('reverse_proxy_proto_header', 'X_FORWARDED_PROTO');
$request::setTrustedHeaderName($request::HEADER_CLIENT_PROTO, $proto_header); $request::setTrustedHeaderName($request::HEADER_CLIENT_PROTO, $proto_header);
$host_header = $this->settings->get('reverse_proxy_host_header', 'X_FORWARDED_HOST'); $host_header = $settings->get('reverse_proxy_host_header', 'X_FORWARDED_HOST');
$request::setTrustedHeaderName($request::HEADER_CLIENT_HOST, $host_header); $request::setTrustedHeaderName($request::HEADER_CLIENT_HOST, $host_header);
$port_header = $this->settings->get('reverse_proxy_port_header', 'X_FORWARDED_PORT'); $port_header = $settings->get('reverse_proxy_port_header', 'X_FORWARDED_PORT');
$request::setTrustedHeaderName($request::HEADER_CLIENT_PORT, $port_header); $request::setTrustedHeaderName($request::HEADER_CLIENT_PORT, $port_header);
$forwarded_header = $this->settings->get('reverse_proxy_forwarded_header', 'FORWARDED'); $forwarded_header = $settings->get('reverse_proxy_forwarded_header', 'FORWARDED');
$request::setTrustedHeaderName($request::HEADER_FORWARDED, $forwarded_header); $request::setTrustedHeaderName($request::HEADER_FORWARDED, $forwarded_header);
$proxies = $this->settings->get('reverse_proxy_addresses', array()); $proxies = $settings->get('reverse_proxy_addresses', array());
if (count($proxies) > 0) { if (count($proxies) > 0) {
$request::setTrustedProxies($proxies); $request::setTrustedProxies($proxies);
} }
} }
return $this->httpKernel->handle($request, $type, $catch);
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment