rich media: suppress link previews if post is marked as sensitive
authorWilliam Pitcock <nenolod@dereferenced.org>
Fri, 17 May 2019 18:49:43 +0000 (18:49 +0000)
committerWilliam Pitcock <nenolod@dereferenced.org>
Fri, 17 May 2019 18:49:43 +0000 (18:49 +0000)
lib/pleroma/web/rich_media/helpers.ex
test/web/rich_media/helpers_test.exs

index 0162a5be9d99c9093ce0f9e108b8b4961bbd6da5..9bc8f2559b5d5d6c78174283bee33f156ffd7d4c 100644 (file)
@@ -24,6 +24,7 @@ defmodule Pleroma.Web.RichMedia.Helpers do
   def fetch_data_for_activity(%Activity{data: %{"type" => "Create"}} = activity) do
     with true <- Pleroma.Config.get([:rich_media, :enabled]),
          %Object{} = object <- Object.normalize(activity),
+         false <- object.data["sensitive"] || false,
          {:ok, page_url} <- HTML.extract_first_external_url(object, object.data["content"]),
          :ok <- validate_page_url(page_url),
          {:ok, rich_media} <- Parser.parse(page_url) do
index 60d93768f20f5b1fd5cd968b12a279d64d770e34..6e23392caba2e3644e0dbabdd3ab80dc7511043c 100644 (file)
@@ -1,6 +1,7 @@
 defmodule Pleroma.Web.RichMedia.HelpersTest do
   use Pleroma.DataCase
 
+  alias Pleroma.Object
   alias Pleroma.Web.CommonAPI
 
   import Pleroma.Factory
@@ -59,4 +60,24 @@ defmodule Pleroma.Web.RichMedia.HelpersTest do
 
     Pleroma.Config.put([:rich_media, :enabled], false)
   end
+
+  test "refuses to crawl URLs from posts marked sensitive" do
+    user = insert(:user)
+
+    {:ok, activity} =
+      CommonAPI.post(user, %{
+        "status" => "http://example.com/ogp",
+        "spoiler_text" => "."
+      })
+
+    %Object{} = object = Object.normalize(activity)
+
+    assert object.data["sensitive"]
+
+    Pleroma.Config.put([:rich_media, :enabled], true)
+
+    assert %{} = Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)
+
+    Pleroma.Config.put([:rich_media, :enabled], false)
+  end
 end