fix(mastodon-api): restrict unauthenticated account statuses
This commit is contained in:
parent
b9ef1e2182
commit
2b32e3cf1f
4 changed files with 146 additions and 0 deletions
|
|
@ -1357,6 +1357,43 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
|||
|
||||
defp restrict_unauthenticated(query, _), do: query
|
||||
|
||||
defp restrict_unauthenticated_object(query, nil) do
|
||||
local = Config.restrict_unauthenticated_access?(:activities, :local)
|
||||
remote = Config.restrict_unauthenticated_access?(:activities, :remote)
|
||||
local_object_pattern = Pleroma.Web.Endpoint.url() <> "/%"
|
||||
|
||||
cond do
|
||||
local and remote ->
|
||||
from([object: object] in query, where: false)
|
||||
|
||||
local ->
|
||||
from([object: object] in query,
|
||||
where: not fragment("(?->>'id') LIKE ?", object.data, ^local_object_pattern)
|
||||
)
|
||||
|
||||
remote ->
|
||||
from([object: object] in query,
|
||||
where: fragment("(?->>'id') LIKE ?", object.data, ^local_object_pattern)
|
||||
)
|
||||
|
||||
true ->
|
||||
query
|
||||
end
|
||||
end
|
||||
|
||||
defp restrict_unauthenticated_object(query, _), do: query
|
||||
|
||||
defp maybe_restrict_unauthenticated(
|
||||
query,
|
||||
%{restrict_unauthenticated: true, user: user}
|
||||
) do
|
||||
query
|
||||
|> restrict_unauthenticated(user)
|
||||
|> restrict_unauthenticated_object(user)
|
||||
end
|
||||
|
||||
defp maybe_restrict_unauthenticated(query, _), do: query
|
||||
|
||||
defp restrict_quote_url(query, %{quote_url: quote_url}) do
|
||||
from([_activity, object] in query,
|
||||
where: fragment("(?)->'quoteUrl' = ?", object.data, ^quote_url)
|
||||
|
|
@ -1514,6 +1551,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
|||
|> maybe_preload_report_notes(opts)
|
||||
|> maybe_set_thread_muted_field(opts)
|
||||
|> maybe_order(opts)
|
||||
|> maybe_restrict_unauthenticated(opts)
|
||||
|> restrict_recipients_or_hashtags(recipients, opts[:user], opts[:followed_hashtags])
|
||||
|> restrict_replies(opts)
|
||||
|> restrict_since(opts)
|
||||
|
|
|
|||
|
|
@ -348,6 +348,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do
|
|||
params
|
||||
|> Map.delete(:tagged)
|
||||
|> Map.put(:tag, params[:tagged])
|
||||
|> Map.put(:restrict_unauthenticated, true)
|
||||
|
||||
activities = ActivityPub.fetch_user_activities(user, reading_user, params)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue