Merge branch 'feature/mention-mrf' into 'develop'

Add MRF MentionPolicy for dropping posts which mention specific actors

See merge request pleroma/pleroma!1439
This commit is contained in:
kaniini 2019-07-17 15:28:41 +00:00
commit ce73d5f6a5
4 changed files with 121 additions and 0 deletions

View File

@ -24,6 +24,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Added
- MRF: Support for priming the mediaproxy cache (`Pleroma.Web.ActivityPub.MRF.MediaProxyWarmingPolicy`)
- MRF: Support for excluding specific domains from Transparency.
- MRF: Support for filtering posts based on who they mention (`Pleroma.Web.ActivityPub.MRF.MentionPolicy`)
- Configuration: `federation_incoming_replies_max_depth` option
- Mastodon API: Support for the [`tagged` filter](https://github.com/tootsuite/mastodon/pull/9755) in [`GET /api/v1/accounts/:id/statuses`](https://docs.joinmastodon.org/api/rest/accounts/#get-api-v1-accounts-id-statuses)
- Mastodon API, streaming: Add support for passing the token in the `Sec-WebSocket-Protocol` header

View File

@ -101,6 +101,7 @@ config :pleroma, Pleroma.Emails.Mailer,
* `Pleroma.Web.ActivityPub.MRF.EnsureRePrepended`: Rewrites posts to ensure that replies to posts with subjects do not have an identical subject and instead begin with re:.
* `Pleroma.Web.ActivityPub.MRF.AntiLinkSpamPolicy`: Rejects posts from likely spambots by rejecting posts from new users that contain links.
* `Pleroma.Web.ActivityPub.MRF.MediaProxyWarmingPolicy`: Crawls attachments using their MediaProxy URLs so that the MediaProxy cache is primed.
* `Pleroma.Web.ActivityPub.MRF.MentionPolicy`: Drops posts mentioning configurable users. (see `:mrf_mention` section)
* `public`: Makes the client API in authentificated mode-only except for user-profiles. Useful for disabling the Local Timeline and The Whole Known Network.
* `quarantined_instances`: List of ActivityPub instances where private(DMs, followers-only) activities will not be send.
* `managed_config`: Whenether the config for pleroma-fe is configured in this config or in ``static/config.json``
@ -271,6 +272,9 @@ config :pleroma, :mrf_subchain,
* `federated_timeline_removal`: A list of patterns which result in message being removed from federated timelines (a.k.a unlisted), each pattern can be a string or a [regular expression](https://hexdocs.pm/elixir/Regex.html)
* `replace`: A list of tuples containing `{pattern, replacement}`, `pattern` can be a string or a [regular expression](https://hexdocs.pm/elixir/Regex.html)
## :mrf_mention
* `actors`: A list of actors, for which to drop any posts mentioning.
## :media_proxy
* `enabled`: Enables proxying of remote media to the instances proxy
* `base_url`: The base URL to access a user-uploaded file. Useful when you want to proxy the media files via another host/CDN fronts.

View File

@ -0,0 +1,24 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.MRF.MentionPolicy do
@moduledoc "Block messages which mention a user"
@behaviour Pleroma.Web.ActivityPub.MRF
@impl true
def filter(%{"type" => "Create"} = message) do
reject_actors = Pleroma.Config.get([:mrf_mention, :actors], [])
recipients = (message["to"] || []) ++ (message["cc"] || [])
if Enum.any?(recipients, fn recipient -> Enum.member?(reject_actors, recipient) end) do
{:reject, nil}
else
{:ok, message}
end
end
@impl true
def filter(message), do: {:ok, message}
end

View File

@ -0,0 +1,92 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.MRF.MentionPolicyTest do
use Pleroma.DataCase
alias Pleroma.Web.ActivityPub.MRF.MentionPolicy
test "pass filter if allow list is empty" do
Pleroma.Config.delete([:mrf_mention])
message = %{
"type" => "Create",
"to" => ["https://example.com/ok"],
"cc" => ["https://example.com/blocked"]
}
assert MentionPolicy.filter(message) == {:ok, message}
end
describe "allow" do
test "empty" do
Pleroma.Config.put([:mrf_mention], %{actors: ["https://example.com/blocked"]})
message = %{
"type" => "Create"
}
assert MentionPolicy.filter(message) == {:ok, message}
end
test "to" do
Pleroma.Config.put([:mrf_mention], %{actors: ["https://example.com/blocked"]})
message = %{
"type" => "Create",
"to" => ["https://example.com/ok"]
}
assert MentionPolicy.filter(message) == {:ok, message}
end
test "cc" do
Pleroma.Config.put([:mrf_mention], %{actors: ["https://example.com/blocked"]})
message = %{
"type" => "Create",
"cc" => ["https://example.com/ok"]
}
assert MentionPolicy.filter(message) == {:ok, message}
end
test "both" do
Pleroma.Config.put([:mrf_mention], %{actors: ["https://example.com/blocked"]})
message = %{
"type" => "Create",
"to" => ["https://example.com/ok"],
"cc" => ["https://example.com/ok2"]
}
assert MentionPolicy.filter(message) == {:ok, message}
end
end
describe "deny" do
test "to" do
Pleroma.Config.put([:mrf_mention], %{actors: ["https://example.com/blocked"]})
message = %{
"type" => "Create",
"to" => ["https://example.com/blocked"]
}
assert MentionPolicy.filter(message) == {:reject, nil}
end
test "cc" do
Pleroma.Config.put([:mrf_mention], %{actors: ["https://example.com/blocked"]})
message = %{
"type" => "Create",
"to" => ["https://example.com/ok"],
"cc" => ["https://example.com/blocked"]
}
assert MentionPolicy.filter(message) == {:reject, nil}
end
end
end