Plugs.HTTPSecurityPlug: Activate upgrade-insecure-requests only when there is https
authorHaelwenn (lanodan) Monnier <contact@hacktivis.me>
Mon, 26 Nov 2018 20:40:29 +0000 (21:40 +0100)
committerHaelwenn (lanodan) Monnier <contact@hacktivis.me>
Mon, 26 Nov 2018 20:41:36 +0000 (21:41 +0100)
This fixes running mastofe with MIX_ENV=dev

lib/pleroma/plugs/http_security_plug.ex

index 84d6506e3abc6d662f2842e42e03757c41bae418..4c32653ea5733b5ef8f310994171d49808f663b5 100644 (file)
@@ -29,6 +29,8 @@ defmodule Pleroma.Plugs.HTTPSecurityPlug do
   end
 
   defp csp_string do
+    protocol = Config.get([Pleroma.Web.Endpoint, :protocol])
+
     [
       "default-src 'none'",
       "base-uri 'self'",
@@ -40,7 +42,9 @@ defmodule Pleroma.Plugs.HTTPSecurityPlug do
       "script-src 'self'",
       "connect-src 'self' " <> String.replace(Pleroma.Web.Endpoint.static_url(), "http", "ws"),
       "manifest-src 'self'",
-      "upgrade-insecure-requests"
+      if @protocol == "https" do
+        "upgrade-insecure-requests"
+      end
     ]
     |> Enum.join("; ")
   end