SimplePolicy: Fix problem with DM leaks.

This commit is contained in:
lain 2020-07-31 09:57:30 +02:00
parent e2e66e50d3
commit 1dd162a5f7
2 changed files with 7 additions and 3 deletions

View File

@ -109,6 +109,10 @@ defp check_ftl_removal(%{host: actor_host} = _actor_info, object) do
{:ok, object} {:ok, object}
end end
defp intersection(list1, list2) do
list1 -- list1 -- list2
end
defp check_followers_only(%{host: actor_host} = _actor_info, object) do defp check_followers_only(%{host: actor_host} = _actor_info, object) do
followers_only = followers_only =
Config.get([:mrf_simple, :followers_only]) Config.get([:mrf_simple, :followers_only])
@ -125,8 +129,8 @@ defp check_followers_only(%{host: actor_host} = _actor_info, object) do
cc = FollowingRelationship.followers_ap_ids(user, fixed_cc) cc = FollowingRelationship.followers_ap_ids(user, fixed_cc)
object object
|> Map.put("to", [user.follower_address] ++ to) |> Map.put("to", intersection([user.follower_address | to], fixed_to))
|> Map.put("cc", cc) |> Map.put("cc", intersection([user.follower_address | cc], fixed_cc))
else else
_ -> object _ -> object
end end

View File

@ -308,7 +308,7 @@ test "has a matching host" do
Config.put([:mrf_simple, :followers_only], [actor_domain]) Config.put([:mrf_simple, :followers_only], [actor_domain])
assert {:ok, new_activity} = SimplePolicy.filter(activity) assert {:ok, new_activity} = SimplePolicy.filter(activity)
assert actor.follower_address in new_activity["to"] assert actor.follower_address in new_activity["cc"]
assert following_user.ap_id in new_activity["to"] assert following_user.ap_id in new_activity["to"]
refute "https://www.w3.org/ns/activitystreams#Public" in new_activity["to"] refute "https://www.w3.org/ns/activitystreams#Public" in new_activity["to"]
refute "https://www.w3.org/ns/activitystreams#Public" in new_activity["cc"] refute "https://www.w3.org/ns/activitystreams#Public" in new_activity["cc"]