Plugs.HTTPSecurityPlug: Add webpacker to connect-src
authorHaelwenn (lanodan) Monnier <contact@hacktivis.me>
Sat, 2 Feb 2019 18:06:26 +0000 (19:06 +0100)
committerHaelwenn (lanodan) Monnier <contact@hacktivis.me>
Tue, 12 Feb 2019 21:12:12 +0000 (22:12 +0100)
lib/pleroma/plugs/http_security_plug.ex

index 05e935f2c5b434ad8ebd12c02f69b89155993567..057553e2414757eaed4fd40f96774dc7af2babb9 100644 (file)
@@ -34,6 +34,21 @@ defmodule Pleroma.Plugs.HTTPSecurityPlug do
 
   defp csp_string do
     scheme = Config.get([Pleroma.Web.Endpoint, :url])[:scheme]
+    websocket_url = String.replace(Pleroma.Web.Endpoint.static_url(), "http", "ws")
+
+    connect_src =
+      if Mix.env() == :dev do
+        "connect-src 'self' http://localhost:3035/ " <> websocket_url
+      else
+        "connect-src 'self' " <> websocket_url
+      end
+
+    script_src =
+      if Mix.env() == :dev do
+        "script-src 'self' 'unsafe-eval'"
+      else
+        "script-src 'self'"
+      end
 
     [
       "default-src 'none'",
@@ -43,11 +58,9 @@ defmodule Pleroma.Plugs.HTTPSecurityPlug do
       "media-src 'self' https:",
       "style-src 'self' 'unsafe-inline'",
       "font-src 'self'",
-      "connect-src 'self' " <> String.replace(Pleroma.Web.Endpoint.static_url(), "http", "ws"),
       "manifest-src 'self'",
-      if Mix.env() == :dev do
-        "script-src 'self' 'unsafe-eval'"
-      end,
+      connect_src,
+      script_src,
       if scheme == "https" do
         "upgrade-insecure-requests"
       end