api/masto/account: filter embedded nodeinfo
The only kown user is akkoma-fe and it only ever accesses the software information. For *oma instances the full, unfiltered nodeinfo data can be quite large adding unneeded bloat to API responses. This would have become worse with the duplication of account data needed for Masto quote post interop. In case a client we’re not aware of actually uses more fields from nodeinfo, a new but temporary config setting is provided as a workaround. Fixes: #827
This commit is contained in:
parent
c4bcfb70df
commit
e557bbcd9d
4 changed files with 40 additions and 3 deletions
|
|
@ -249,6 +249,7 @@ config :pleroma, :instance,
|
|||
remote_post_retention_days: 90,
|
||||
skip_thread_containment: true,
|
||||
limit_to_local_content: :unauthenticated,
|
||||
filter_embedded_nodeinfo: true,
|
||||
user_bio_length: 5000,
|
||||
user_name_length: 100,
|
||||
max_account_fields: 10,
|
||||
|
|
|
|||
|
|
@ -43,6 +43,22 @@ defmodule Pleroma.Config.DeprecationWarnings do
|
|||
end
|
||||
end
|
||||
|
||||
def check_truncated_nodeinfo_in_accounts do
|
||||
if !Config.get!([:instance, :filter_embedded_nodeinfo]) do
|
||||
Logger.warning("""
|
||||
!!!BUG WORKAROUND DETECTED!!!
|
||||
Your config is explicitly disabling filtering of nodeinfo data embedded in other Masto API responses
|
||||
|
||||
config :pleroma, :instance, filter_embedded_nodeinfo: false
|
||||
|
||||
This setting will soon be removed. Any usage of it merely serves as a temporary workaround.
|
||||
Make sure to file a bug telling us which problems you encountered and circumvented by setting this!
|
||||
https://akkoma.dev/AkkomaGang/akkoma/issues
|
||||
We can’t fix bugs we don’t know about.
|
||||
""")
|
||||
end
|
||||
end
|
||||
|
||||
def check_exiftool_filter do
|
||||
filters = Config.get([Pleroma.Upload]) |> Keyword.get(:filters, [])
|
||||
|
||||
|
|
|
|||
|
|
@ -181,10 +181,19 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
|
|||
end
|
||||
|
||||
def render("instance.json", %{instance: %Pleroma.Instances.Instance{} = instance}) do
|
||||
nodeinfo =
|
||||
if Pleroma.Config.get!([:instance, :filter_embedded_nodeinfo]) and instance.nodeinfo do
|
||||
%{}
|
||||
|> maybe_put_nodeinfo(instance.nodeinfo, :version)
|
||||
|> maybe_put_nodeinfo(instance.nodeinfo, :software)
|
||||
else
|
||||
instance.nodeinfo
|
||||
end
|
||||
|
||||
%{
|
||||
name: instance.host,
|
||||
favicon: instance.favicon |> MediaProxy.url(),
|
||||
nodeinfo: instance.nodeinfo
|
||||
nodeinfo: nodeinfo
|
||||
}
|
||||
end
|
||||
|
||||
|
|
@ -442,6 +451,17 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
|
|||
|
||||
defp maybe_put_email_address(data, _, _), do: data
|
||||
|
||||
defp maybe_put_nodeinfo(map, nodeinfo, key) do
|
||||
# local nodeinfo uses atom keys, all remote instances string keys
|
||||
val = nodeinfo[key] || nodeinfo[to_string(key)]
|
||||
|
||||
if val do
|
||||
Map.put(map, key, val)
|
||||
else
|
||||
map
|
||||
end
|
||||
end
|
||||
|
||||
defp image_url(%{"url" => [%{"href" => href} | _]}), do: href
|
||||
defp image_url(_), do: nil
|
||||
end
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
instance: %{
|
||||
name: "example.com",
|
||||
nodeinfo: %{
|
||||
"version" => "2.1"
|
||||
version: "2.1"
|
||||
},
|
||||
favicon: nil
|
||||
},
|
||||
|
|
@ -135,7 +135,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
instance: %{
|
||||
name: "somewhere.example.com",
|
||||
nodeinfo: %{
|
||||
"version" => "2.0"
|
||||
version: "2.0"
|
||||
},
|
||||
favicon: "https://example.com/favicon.ico"
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue