AP C2S: Restrict creation to `Note`s for now.
authorlain <lain@soykaf.club>
Tue, 5 May 2020 08:12:37 +0000 (10:12 +0200)
committerlain <lain@soykaf.club>
Tue, 5 May 2020 08:12:37 +0000 (10:12 +0200)
lib/pleroma/web/activity_pub/activity_pub_controller.ex
test/web/activity_pub/activity_pub_controller_test.exs

index f607931ab247bc2b6435cbbbba5a74d07bca6466..504eed4f40f7f9a23d43fc925e6d569f90dd218b 100644 (file)
@@ -396,7 +396,10 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubController do
     |> json(err)
   end
 
-  defp handle_user_activity(%User{} = user, %{"type" => "Create"} = params) do
+  defp handle_user_activity(
+         %User{} = user,
+         %{"type" => "Create", "object" => %{"type" => "Note"}} = params
+       ) do
     object =
       params["object"]
       |> Map.merge(Map.take(params, ["to", "cc"]))
index a8f1f0e263e092d95aad2633386be3ba4039656c..9a085ffc54565e9eb2a0787cb6cccd1e69e8ea0e 100644 (file)
@@ -815,6 +815,21 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
       assert object["content"] == activity["object"]["content"]
     end
 
+    test "it rejects anything beyond 'Note' creations", %{conn: conn, activity: activity} do
+      user = insert(:user)
+
+      activity =
+        activity
+        |> put_in(["object", "type"], "Benis")
+
+      _result =
+        conn
+        |> assign(:user, user)
+        |> put_req_header("content-type", "application/activity+json")
+        |> post("/users/#{user.nickname}/outbox", activity)
+        |> json_response(400)
+    end
+
     test "it inserts an incoming sensitive activity into the database", %{
       conn: conn,
       activity: activity