Restrict reblogs of activities from blocked domains
authorAaron Tinio <aptinio@gmail.com>
Tue, 14 May 2019 23:59:24 +0000 (07:59 +0800)
committerAaron Tinio <aptinio@gmail.com>
Wed, 15 May 2019 21:53:51 +0000 (05:53 +0800)
lib/pleroma/web/activity_pub/activity_pub.ex
test/web/activity_pub/activity_pub_test.exs

index 233fee4fa7133b43adc87accabdc423baa608dc5..6087a1cdc9e5c2e52c6ae93f1553f31963d594e3 100644 (file)
@@ -752,6 +752,14 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
 
     from(
       activity in query,
+      inner_join: o in Object,
+      on:
+        fragment(
+          "(?->>'id') = COALESCE(?->'object'->>'id', ?->>'object')",
+          o.data,
+          activity.data,
+          activity.data
+        ),
       where: fragment("not (? = ANY(?))", activity.actor, ^blocks),
       where: fragment("not (? && ?)", activity.recipients, ^blocks),
       where:
@@ -761,7 +769,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
           activity.data,
           ^blocks
         ),
-      where: fragment("not (split_part(?, '/', 3) = ANY(?))", activity.actor, ^domain_blocks)
+      where: fragment("not (split_part(?, '/', 3) = ANY(?))", activity.actor, ^domain_blocks),
+      where: fragment("not (split_part(?->>'actor', '/', 3) = ANY(?))", o.data, ^domain_blocks)
     )
   end
 
index 442120ffda0aa97da20b0d98152e054d02a7fb85..dfee93f67af98932332562c9ca42913f62846cbf 100644 (file)
@@ -474,6 +474,15 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
       ActivityPub.fetch_activities([], %{"blocking_user" => user, "skip_preload" => true})
 
     refute activity in activities
+
+    followed_user = insert(:user)
+    ActivityPub.follow(user, followed_user)
+    {:ok, repeat_activity, _} = CommonAPI.repeat(activity.id, followed_user)
+
+    activities =
+      ActivityPub.fetch_activities([], %{"blocking_user" => user, "skip_preload" => true})
+
+    refute repeat_activity in activities
   end
 
   test "doesn't return muted activities" do