From f2a5c177c105bc26f7b320591bfc02f81e4fec40 Mon Sep 17 00:00:00 2001 From: Nicolas Brassard Date: Thu, 23 Jun 2016 16:56:44 -0400 Subject: [PATCH] Allow to set the protocol for external images This changes makes url like /image/1/80/80/1/https://external.domain/image.jpg Mostly needed for sites that are https only or ones that upgrade insecure requests --- README.markdown | 4 ++++ extension.meta.xml | 1 + lib/class.jit.php | 9 ++++++++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/README.markdown b/README.markdown index ef2df89..f4a9532 100644 --- a/README.markdown +++ b/README.markdown @@ -155,6 +155,10 @@ The URL then requires a sixth parameter, external, (where the fourth and fifth p ^ External parameter +You can also include the protocol in the full path of the image. This can eliminate a redirection when requesting images from a domain that upgrade insecure requests. + + + ### Recipes Recipes are named rules in JIT settings which help improve security and convenience. They can be edited at the preferences page in the JIT section and are saved in `/workspace/jit-image-manipulation/recipes.php`. An image using a recipe called `thumbnail` might look like: diff --git a/extension.meta.xml b/extension.meta.xml index e780516..3b27481 100644 --- a/extension.meta.xml +++ b/extension.meta.xml @@ -27,6 +27,7 @@ - Removed the Image::renderOutputHeaders() method - Removed support for the undocumented "Direct display" (mode 0) - Added support for forced download via the ?save query string + - Added support to pass protocol for external images - JIT image process is it's own Symphony renderer now diff --git a/lib/class.jit.php b/lib/class.jit.php index 3ea97c3..e4b0f37 100644 --- a/lib/class.jit.php +++ b/lib/class.jit.php @@ -265,7 +265,14 @@ public function fetchImagePath(array &$parameters) { // Fetch external images if ($parameters['settings']['external'] === true) { - $image_path = "http://{$parameters['image']}"; + if (preg_match('/^https?:\/\/?/i', $parameters['image'])) { + // User agent will reduce multiple slashes (//) after the protocol. + // This replacement will take this fact into account + $image_path = preg_replace('/^(https?:)\/([^\/])(.+)$/i', '$1//$2$3', $parameters['image']); + } + else { + $image_path = "http://{$parameters['image']}"; + } // Image is external, check to see that it is a trusted source $rules = @file(WORKSPACE . '/jit-image-manipulation/trusted-sites', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);