Browse Source

AP C2S: Restrict creation to `Note`s for now.

2168-media-preview-proxy
lain 4 years ago
parent
commit
6400998820
2 changed files with 19 additions and 1 deletions
  1. +4
    -1
      lib/pleroma/web/activity_pub/activity_pub_controller.ex
  2. +15
    -0
      test/web/activity_pub/activity_pub_controller_test.exs

+ 4
- 1
lib/pleroma/web/activity_pub/activity_pub_controller.ex View 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"]))


+ 15
- 0
test/web/activity_pub/activity_pub_controller_test.exs View 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


Loading…
Cancel
Save