From d2d07bfe4b9f1567c205a736e6e81e02d13598c1 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Wed, 7 Aug 2024 14:04:20 -0400 Subject: [PATCH 1/6] Add test for Follow objects with a cc --- .../object_validators/follow_validation_test.exs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/pleroma/web/activity_pub/object_validators/follow_validation_test.exs b/test/pleroma/web/activity_pub/object_validators/follow_validation_test.exs index 371368e0e..e684042a1 100644 --- a/test/pleroma/web/activity_pub/object_validators/follow_validation_test.exs +++ b/test/pleroma/web/activity_pub/object_validators/follow_validation_test.exs @@ -22,5 +22,15 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.FollowValidationTest do test "validates a basic follow object", %{valid_follow: valid_follow} do assert {:ok, _follow, []} = ObjectValidator.validate(valid_follow, []) end + + test "supports a nil cc", %{valid_follow: valid_follow} do + valid_follow_with_nil_cc = Map.put(valid_follow, "cc", nil) + assert {:ok, _follow, []} = ObjectValidator.validate(valid_follow_with_nil_cc, []) + end + + test "supports an empty cc", %{valid_follow: valid_follow} do + valid_follow_with_nil_cc = Map.put(valid_follow, "cc", []) + assert {:ok, _follow, []} = ObjectValidator.validate(valid_follow_with_nil_cc, []) + end end end From 8f15000c0f4c81b27b3a7077092f1ba1b37da205 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Wed, 7 Aug 2024 14:38:29 -0400 Subject: [PATCH 2/6] Do not require a cc field when validating an incoming Follow activity The cc field is not required and the code was keeping the cc if it existed on an activity or replacing it with the default of an empty list when casting. If any Follow activity was received with a cc field, it would attempt to keep it. This was noticed in !4208 where we would craft Follow requests with a cc value of nil. --- .../web/activity_pub/object_validators/follow_validator.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pleroma/web/activity_pub/object_validators/follow_validator.ex b/lib/pleroma/web/activity_pub/object_validators/follow_validator.ex index b3ca5b691..e4e97bf72 100644 --- a/lib/pleroma/web/activity_pub/object_validators/follow_validator.ex +++ b/lib/pleroma/web/activity_pub/object_validators/follow_validator.ex @@ -29,7 +29,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.FollowValidator do defp validate_data(cng) do cng - |> validate_required([:id, :type, :actor, :to, :cc, :object]) + |> validate_required([:id, :type, :actor, :to, :object]) |> validate_inclusion(:type, ["Follow"]) |> validate_inclusion(:state, ~w{pending reject accept}) |> validate_actor_presence() From b25f67372b0f425ae428a1b6b18156553c995dc2 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Wed, 7 Aug 2024 14:42:44 -0400 Subject: [PATCH 3/6] Improve the FollowValidator --- changelog.d/follow-validator.fix | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/follow-validator.fix diff --git a/changelog.d/follow-validator.fix b/changelog.d/follow-validator.fix new file mode 100644 index 000000000..d49932b7b --- /dev/null +++ b/changelog.d/follow-validator.fix @@ -0,0 +1 @@ +Improve the FollowValidator to successfully incoming activities with an errant cc field. From fcda1b5e2aeb166dfd84ff17d1840fcfbd6f1490 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Wed, 7 Aug 2024 14:46:39 -0400 Subject: [PATCH 4/6] Improve variable name --- .../activity_pub/object_validators/follow_validation_test.exs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/pleroma/web/activity_pub/object_validators/follow_validation_test.exs b/test/pleroma/web/activity_pub/object_validators/follow_validation_test.exs index e684042a1..acf6e8d8f 100644 --- a/test/pleroma/web/activity_pub/object_validators/follow_validation_test.exs +++ b/test/pleroma/web/activity_pub/object_validators/follow_validation_test.exs @@ -29,8 +29,8 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.FollowValidationTest do end test "supports an empty cc", %{valid_follow: valid_follow} do - valid_follow_with_nil_cc = Map.put(valid_follow, "cc", []) - assert {:ok, _follow, []} = ObjectValidator.validate(valid_follow_with_nil_cc, []) + valid_follow_with_empty_cc = Map.put(valid_follow, "cc", []) + assert {:ok, _follow, []} = ObjectValidator.validate(valid_follow_with_empty_cc, []) end end end From 526a57ff9fe2be729c6e4d95f3eb5991047c41a2 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Wed, 7 Aug 2024 21:51:22 -0400 Subject: [PATCH 5/6] Remove validation for cc fields on Follow Accept/Reject --- .../activity_pub/object_validators/accept_reject_validator.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pleroma/web/activity_pub/object_validators/accept_reject_validator.ex b/lib/pleroma/web/activity_pub/object_validators/accept_reject_validator.ex index d611da051..03ab83347 100644 --- a/lib/pleroma/web/activity_pub/object_validators/accept_reject_validator.ex +++ b/lib/pleroma/web/activity_pub/object_validators/accept_reject_validator.ex @@ -29,7 +29,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.AcceptRejectValidator do defp validate_data(cng) do cng - |> validate_required([:id, :type, :actor, :to, :cc, :object]) + |> validate_required([:id, :type, :actor, :to, :object]) |> validate_inclusion(:type, ["Accept", "Reject"]) |> validate_actor_presence() |> validate_object_presence(allowed_types: ["Follow"]) From ca934b744f9c6095315421990975c1e9a7b9cd85 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Wed, 7 Aug 2024 21:51:43 -0400 Subject: [PATCH 6/6] Remove validation for cc fields on Blocks --- .../web/activity_pub/object_validators/block_validator.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pleroma/web/activity_pub/object_validators/block_validator.ex b/lib/pleroma/web/activity_pub/object_validators/block_validator.ex index 0de87a27e..98340545c 100644 --- a/lib/pleroma/web/activity_pub/object_validators/block_validator.ex +++ b/lib/pleroma/web/activity_pub/object_validators/block_validator.ex @@ -29,7 +29,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.BlockValidator do defp validate_data(cng) do cng - |> validate_required([:id, :type, :actor, :to, :cc, :object]) + |> validate_required([:id, :type, :actor, :to, :object]) |> validate_inclusion(:type, ["Block"]) |> CommonValidations.validate_actor_presence() |> CommonValidations.validate_actor_presence(field_name: :object)