X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=lib%2Fpleroma%2Fweb%2Fplugs%2Fcsp_nonce_plug.ex;fp=lib%2Fpleroma%2Fweb%2Fplugs%2Fcsp_nonce_plug.ex;h=bc2c6fcd86fd36239506362e67be7d8227daeaba;hb=18bf82d7479b0bb767a657e1b7447529f9c2884f;hp=0000000000000000000000000000000000000000;hpb=07a48b9293e4046c50b5d424d60a1bf16c7cc198;p=akkoma diff --git a/lib/pleroma/web/plugs/csp_nonce_plug.ex b/lib/pleroma/web/plugs/csp_nonce_plug.ex new file mode 100644 index 000000000..bc2c6fcd8 --- /dev/null +++ b/lib/pleroma/web/plugs/csp_nonce_plug.ex @@ -0,0 +1,21 @@ +defmodule Pleroma.Web.Plugs.CSPNoncePlug do + import Plug.Conn + + def init(opts) do + opts + end + + def call(conn, _opts) do + assign_csp_nonce(conn) + end + + defp assign_csp_nonce(conn) do + nonce = + :crypto.strong_rand_bytes(128) + |> Base.url_encode64() + |> binary_part(0, 15) + + conn + |> assign(:csp_nonce, nonce) + end +end