mirror of
https://git.pleroma.social/sjw/pleroma.git
synced 2024-11-10 23:09:08 +01:00
Merge branch 'bad_inbox_request' into 'develop'
Return a 400 from a bad delivery attempt to the inbox Closes #2884 See merge request pleroma/pleroma!4009
This commit is contained in:
commit
5f1d707367
1
changelog.d/bad_inbox_request.change
Normal file
1
changelog.d/bad_inbox_request.change
Normal file
@ -0,0 +1 @@
|
|||||||
|
Invalid activities delivered to the inbox will be rejected with a 400 Bad Request
|
@ -273,12 +273,17 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubController do
|
|||||||
end
|
end
|
||||||
|
|
||||||
def inbox(%{assigns: %{valid_signature: true}} = conn, %{"nickname" => nickname} = params) do
|
def inbox(%{assigns: %{valid_signature: true}} = conn, %{"nickname" => nickname} = params) do
|
||||||
with %User{} = recipient <- User.get_cached_by_nickname(nickname),
|
with %User{is_active: true} = recipient <- User.get_cached_by_nickname(nickname),
|
||||||
{:ok, %User{} = actor} <- User.get_or_fetch_by_ap_id(params["actor"]),
|
{:ok, %User{is_active: true} = actor} <- User.get_or_fetch_by_ap_id(params["actor"]),
|
||||||
true <- Utils.recipient_in_message(recipient, actor, params),
|
true <- Utils.recipient_in_message(recipient, actor, params),
|
||||||
params <- Utils.maybe_splice_recipient(recipient.ap_id, params) do
|
params <- Utils.maybe_splice_recipient(recipient.ap_id, params) do
|
||||||
Federator.incoming_ap_doc(params)
|
Federator.incoming_ap_doc(params)
|
||||||
json(conn, "ok")
|
json(conn, "ok")
|
||||||
|
else
|
||||||
|
_ ->
|
||||||
|
conn
|
||||||
|
|> put_status(:bad_request)
|
||||||
|
|> json("Invalid request.")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -895,6 +895,23 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||||||
assert Activity.get_by_ap_id(data["id"])
|
assert Activity.get_by_ap_id(data["id"])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "it rejects an invalid incoming activity", %{conn: conn, data: data} do
|
||||||
|
user = insert(:user, is_active: false)
|
||||||
|
|
||||||
|
data =
|
||||||
|
data
|
||||||
|
|> Map.put("bcc", [user.ap_id])
|
||||||
|
|> Kernel.put_in(["object", "bcc"], [user.ap_id])
|
||||||
|
|
||||||
|
conn =
|
||||||
|
conn
|
||||||
|
|> assign(:valid_signature, true)
|
||||||
|
|> put_req_header("content-type", "application/activity+json")
|
||||||
|
|> post("/users/#{user.nickname}/inbox", data)
|
||||||
|
|
||||||
|
assert "Invalid request." == json_response(conn, 400)
|
||||||
|
end
|
||||||
|
|
||||||
test "it accepts messages with to as string instead of array", %{conn: conn, data: data} do
|
test "it accepts messages with to as string instead of array", %{conn: conn, data: data} do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user