From 4a1eb0c15889005d883006f14366d3858b46ff2e Mon Sep 17 00:00:00 2001 From: Shiva Kerdel <49479846+s-kerdel@users.noreply.github.com> Date: Tue, 13 Dec 2022 16:51:04 +0100 Subject: [PATCH] ISSUE-10615: Respect SS_BASE_URL scheme in CLI environment. Additionally set _SERVER variables for HTTPS and SSL to respect SS_BASE_URL scheme when executing builds and tasks through CLI. This should solve base tags not being provided with the correct HTTP scheme. This is important to resolve mixed content issues and insecure requests. --- src/Control/CLIRequestBuilder.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Control/CLIRequestBuilder.php b/src/Control/CLIRequestBuilder.php index 006dc7ab6..e122288d5 100644 --- a/src/Control/CLIRequestBuilder.php +++ b/src/Control/CLIRequestBuilder.php @@ -64,6 +64,13 @@ class CLIRequestBuilder extends HTTPRequestBuilder $variables['_GET']['url'] = $variables['_SERVER']['argv'][1]; $variables['_SERVER']['REQUEST_URI'] = $variables['_SERVER']['argv'][1]; } + + // Set 'HTTPS' and 'SSL' flag for CLI depending on SS_BASE_URL scheme value. + $scheme = parse_url(Environment::getEnv('SS_BASE_URL') ?? '', PHP_URL_SCHEME); + if ($scheme == 'https') { + $variables['_SERVER']['HTTPS'] = 'on'; + $variables['_SERVER']['SSL'] = true; + } // Parse rest of variables as standard return parent::cleanEnvironment($variables);