akkoma/lib/pleroma/web/plugs/csp_nonce_plug.ex
FloatingGhost e2320f870e
Some checks are pending
ci/woodpecker/push/woodpecker Pipeline is pending
Add prometheus metrics to router
2022-12-15 02:02:07 +00:00

21 lines
353 B
Elixir

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