mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2024-11-30 01:01:12 +00:00
22 lines
353 B
Elixir
22 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
|