]> git.wh0rd.org - tt-rss.git/blobdiff - plugins/af_zz_imgproxy/init.php
af_zz_imgproxy: implement a whitelist of known sites that have optional SSL
[tt-rss.git] / plugins / af_zz_imgproxy / init.php
index e0ec2f1745c8919d38dc6aefc130f2afd250cc2d..43b3fe7f1715eeabe50400e35171272514e17d1a 100644 (file)
@@ -8,6 +8,8 @@ class Af_Zz_ImgProxy extends Plugin {
                        "fox");
        }
 
+       private $ssl_known_whitelist = "imgur.com i.reddituploads.com pbs.twimg.com i.redd.it i.sli.mg media.tumblr.com";
+
        function is_public_method($method) {
                return $method === "imgproxy";
        }
@@ -23,7 +25,7 @@ class Af_Zz_ImgProxy extends Plugin {
        }
 
        function hook_enclosure_entry($enc) {
-               if (preg_match("/image/", $enc["content_type"]) || preg_match("/\.(jpe?g|png|gif|bmp)$/i", $enc["filename"])) {
+               if (preg_match("/image/", $enc["content_type"])) {
                        $proxy_all = $this->host->get($this, "proxy_all");
 
                        $enc["content_url"] = $this->rewrite_url_if_needed($enc["content_url"], $proxy_all);
@@ -119,7 +121,17 @@ class Af_Zz_ImgProxy extends Plugin {
 
                if (($scheme != 'https' && $scheme != "") || $is_remote) {
                        if (strpos($url, "data:") !== 0) {
-                               $url = get_self_url_prefix() . "/public.php?op=pluginhandler&plugin=af_zz_imgproxy&pmethod=imgproxy&url=" .
+                               $parts = parse_url($url);
+
+                               foreach (explode(" " , $this->ssl_known_whitelist) as $host) {
+                                       if (strpos($parts['host'], $host) !== FALSE) {
+                                               $parts['scheme'] = 'https';
+
+                                               return build_url($parts);
+                                       }
+                               }
+
+                               return get_self_url_prefix() . "/public.php?op=pluginhandler&plugin=af_zz_imgproxy&pmethod=imgproxy&url=" .
                                        urlencode($url);
                        }
                }