Fix checking origin from a tombstone

When comparing an activity with their origin, only compare the ID
directly, as Tombstones don't have actors anymore

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2021-08-10 20:32:50 +02:00
parent cb148e29d7
commit 6f9db37ca3
No known key found for this signature in database
GPG Key ID: A061B9DDE0CA0773
3 changed files with 13 additions and 1 deletions

View File

@ -142,7 +142,7 @@ defmodule Mobilizon.Federation.ActivityPub.Fetcher do
true true
else else
Sentry.capture_message("Object origin check failed", extra: %{url: url, data: data}) Sentry.capture_message("Object origin check failed", extra: %{url: url, data: data})
Logger.debug("Object origin check failed") Logger.debug("Object origin check failed between #{inspect(url)} and #{inspect(data)}")
false false
end end
end end

View File

@ -239,6 +239,8 @@ defmodule Mobilizon.Federation.ActivityPub.Utils do
Takes the actor or attributedTo attributes (considers only the first elem if they're an array) Takes the actor or attributedTo attributes (considers only the first elem if they're an array)
""" """
def origin_check?(id, %{"type" => "Tombstone", "id" => tombstone_id}), do: id == tombstone_id
def origin_check?(id, %{"actor" => actor, "attributedTo" => _attributed_to} = params) def origin_check?(id, %{"actor" => actor, "attributedTo" => _attributed_to} = params)
when not is_nil(actor) and actor != "" do when not is_nil(actor) and actor != "" do
params = Map.delete(params, "attributedTo") params = Map.delete(params, "attributedTo")

View File

@ -5,6 +5,7 @@ defmodule Mobilizon.Federation.ActivityPub.UtilsTest do
import Mobilizon.Factory import Mobilizon.Factory
alias Mobilizon.Federation.ActivityPub.Utils
alias Mobilizon.Federation.ActivityStream.Converter alias Mobilizon.Federation.ActivityStream.Converter
alias Mobilizon.Web.Endpoint alias Mobilizon.Web.Endpoint
@ -51,4 +52,13 @@ defmodule Mobilizon.Federation.ActivityPub.UtilsTest do
assert comment_data["inReplyTo"] == comment.url assert comment_data["inReplyTo"] == comment.url
end end
end end
describe "origin_check?" do
test "origin_check? with a tombstone" do
assert Utils.origin_check?("http://an_uri", %{
"type" => "Tombstone",
"id" => "http://an_uri"
})
end
end
end end