diff options
author | eugenijm <eugenijm@protonmail.com> | 2021-01-21 14:58:18 +0300 |
---|---|---|
committer | eugenijm <eugenijm@protonmail.com> | 2021-01-21 21:55:23 +0300 |
commit | 7fcaa188a0be4bc8e41790ddda9b6789cb318347 (patch) | |
tree | bf0701de8ac6c04bc131b04d0662c7604494888d /lib | |
parent | 133644dfa2e46dc48980ae6f835b7aa2758b4250 (diff) | |
download | pleroma-7fcaa188a0be4bc8e41790ddda9b6789cb318347.tar.gz pleroma-7fcaa188a0be4bc8e41790ddda9b6789cb318347.zip |
Allow to define custom HTTP headers per each frontend
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pleroma/web/plugs/http_security_plug.ex | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/lib/pleroma/web/plugs/http_security_plug.ex b/lib/pleroma/web/plugs/http_security_plug.ex index 6c959a870..0025b042a 100644 --- a/lib/pleroma/web/plugs/http_security_plug.ex +++ b/lib/pleroma/web/plugs/http_security_plug.ex @@ -20,10 +20,26 @@ defmodule Pleroma.Web.Plugs.HTTPSecurityPlug do end end - defp headers do + def primary_frontend do + with %{"name" => frontend} <- Config.get([:frontends, :primary]), + available <- Config.get([:frontends, :available]), + %{} = primary_frontend <- Map.get(available, frontend) do + {:ok, primary_frontend} + end + end + + def custom_http_frontend_headers do + with {:ok, %{"custom-http-headers" => custom_headers}} <- primary_frontend() do + custom_headers + else + _ -> [] + end + end + + def headers do referrer_policy = Config.get([:http_security, :referrer_policy]) report_uri = Config.get([:http_security, :report_uri]) - service_worker_allowed = Config.get([:http_security, :service_worker_allowed]) + custom_http_frontend_headers = custom_http_frontend_headers() headers = [ {"x-xss-protection", "1; mode=block"}, @@ -36,8 +52,8 @@ defmodule Pleroma.Web.Plugs.HTTPSecurityPlug do ] headers = - if service_worker_allowed do - [{"service-worker-allowed", service_worker_allowed} | headers] + if custom_http_frontend_headers do + custom_http_frontend_headers ++ headers else headers end |