projects
/
akkoma
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
make 2fa UI less awful
[akkoma]
/
lib
/
pleroma
/
web
/
preload.ex
diff --git
a/lib/pleroma/web/preload.ex
b/lib/pleroma/web/preload.ex
index f13932b890a0fa025954f8ba1341ce8cd935bbf5..e554965a26a12f42498ca952103f1835db85fabf 100644
(file)
--- a/
lib/pleroma/web/preload.ex
+++ b/
lib/pleroma/web/preload.ex
@@
-1,32
+1,36
@@
# Pleroma: A lightweight social networking server
# Pleroma: A lightweight social networking server
-# Copyright © 2017-202
0
Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-202
1
Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Preload do
alias Phoenix.HTML
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Preload do
alias Phoenix.HTML
- require Logger
- def build_tags(
_
conn, params) do
+ def build_tags(
%{assigns: %{csp_nonce: nonce}} =
conn, params) do
preload_data =
Enum.reduce(Pleroma.Config.get([__MODULE__, :providers], []), %{}, fn parser, acc ->
preload_data =
Enum.reduce(Pleroma.Config.get([__MODULE__, :providers], []), %{}, fn parser, acc ->
- Map.merge(acc, parser.generate_terms(params))
+ terms =
+ params
+ |> parser.generate_terms()
+ |> Enum.map(fn {k, v} -> {k, Base.encode64(Jason.encode!(v))} end)
+ |> Enum.into(%{})
+
+ Map.merge(acc, terms)
end)
rendered_html =
preload_data
|> Jason.encode!()
end)
rendered_html =
preload_data
|> Jason.encode!()
- |> build_script_tag()
+ |> build_script_tag(
nonce
)
|> HTML.safe_to_string()
rendered_html
end
|> HTML.safe_to_string()
rendered_html
end
- def build_script_tag(content) do
- content = Base.encode64(content)
-
+ def build_script_tag(content, nonce) do
HTML.Tag.content_tag(:script, HTML.raw(content),
id: "initial-results",
HTML.Tag.content_tag(:script, HTML.raw(content),
id: "initial-results",
- type: "application/json"
+ type: "application/json",
+ nonce: nonce
)
end
end
)
end
end