UpdateValidator: Check Actor owns Object or updates itself

This commit is contained in:
Phantasm 2026-04-30 00:18:54 +02:00
commit af6d12c0a5
No known key found for this signature in database
GPG key ID: 2669E588BCC634C8

View file

@ -75,15 +75,36 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.UpdateValidator do
end end
end end
# For remote Updates, verify the host is the same. # For remote Updates, verify the Actor is the same
def validate_updating_rights_remote(cng) do def validate_updating_rights_remote(cng) do
with actor = get_field(cng, :actor), with actor = get_field(cng, :actor),
object = get_field(cng, :object), object = get_field(cng, :object),
{:ok, object_id} <- ObjectValidators.ObjectID.cast(object), {:ok, object_id} <- ObjectValidators.ObjectID.cast(object),
actor_uri <- URI.parse(actor), entity <-
object_uri <- URI.parse(object_id), Object.normalize(object_id, fetch: false) || User.get_cached_by_ap_id(object_id) do
true <- actor_uri.host == object_uri.host do case entity do
cng # Actor must own Object to update it
%Object{} ->
if actor == entity.data["actor"] do
cng
else
cng
|> add_error(:object, "Can't be updated by this actor")
end
# Actor must only be allowed to update itself
%User{} ->
if actor == entity.ap_id do
cng
else
cng
|> add_error(:object, "Can't be updated by this actor")
end
true ->
cng
|> add_error(:object, "Update is neither for Object or Actor")
end
else else
_e -> _e ->
cng cng