diff --git a/core/modules/filter/filter.module b/core/modules/filter/filter.module
index 57ff8c2..ab62219 100644
--- a/core/modules/filter/filter.module
+++ b/core/modules/filter/filter.module
@@ -1741,7 +1741,8 @@ function _filter_html_image_secure_process($text) {
     $src = $image->getAttribute('src');
     // Remove absolute URLs pointing to the local domain to prevent mixed
     // content errors.
-    $image->setAttribute('src', preg_replace('|^https?://' . $_SERVER['HTTP_HOST'] . '|', '', $src));
+    $host = Drupal::request()->server->get('HTTP_HOST');
+    $image->setAttribute('src', preg_replace('|^https?://' . $host . '|', '', $src));
 
     // Verify that $src starts with $base_path.
     // This also ensures that external images cannot be referenced.
