Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F115437
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/changelog.d/bugfix-truncate-remote-user-fields.fix b/changelog.d/bugfix-truncate-remote-user-fields.fix
new file mode 100644
index 000000000..239a3c224
--- /dev/null
+++ b/changelog.d/bugfix-truncate-remote-user-fields.fix
@@ -0,0 +1 @@
+Truncate remote user fields, avoids them getting rejected
diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex
index e28d76a7c..4f6cdc03e 100644
--- a/lib/pleroma/user.ex
+++ b/lib/pleroma/user.ex
@@ -463,6 +463,7 @@ defmodule Pleroma.User do
def remote_user_changeset(struct \\ %User{local: false}, params) do
bio_limit = Config.get([:instance, :user_bio_length], 5000)
name_limit = Config.get([:instance, :user_name_length], 100)
+ fields_limit = Config.get([:instance, :max_remote_account_fields], 0)
name =
case params[:name] do
@@ -476,6 +477,7 @@ defmodule Pleroma.User do
|> Map.put_new(:last_refreshed_at, NaiveDateTime.utc_now())
|> truncate_if_exists(:name, name_limit)
|> truncate_if_exists(:bio, bio_limit)
+ |> Map.update(:fields, [], &Enum.take(&1, fields_limit))
|> truncate_fields_param()
|> fix_follower_address()
diff --git a/test/pleroma/user_test.exs b/test/pleroma/user_test.exs
index 036ae78fb..06afc0709 100644
--- a/test/pleroma/user_test.exs
+++ b/test/pleroma/user_test.exs
@@ -1075,6 +1075,21 @@ defmodule Pleroma.UserTest do
refute cs.valid?
end
+
+ test "it truncates fields" do
+ clear_config([:instance, :max_remote_account_fields], 2)
+
+ fields = [
+ %{"name" => "One", "value" => "Uno"},
+ %{"name" => "Two", "value" => "Dos"},
+ %{"name" => "Three", "value" => "Tres"}
+ ]
+
+ cs = User.remote_user_changeset(@valid_remote |> Map.put(:fields, fields))
+
+ assert [%{"name" => "One", "value" => "Uno"}, %{"name" => "Two", "value" => "Dos"}] ==
+ Ecto.Changeset.get_field(cs, :fields)
+ end
end
describe "followers and friends" do
diff --git a/test/pleroma/web/activity_pub/transmogrifier/user_update_handling_test.exs b/test/pleroma/web/activity_pub/transmogrifier/user_update_handling_test.exs
index da46f063a..851c60850 100644
--- a/test/pleroma/web/activity_pub/transmogrifier/user_update_handling_test.exs
+++ b/test/pleroma/web/activity_pub/transmogrifier/user_update_handling_test.exs
@@ -119,8 +119,8 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.UserUpdateHandlingTest do
user = User.get_cached_by_ap_id(user.ap_id)
assert user.fields == [
- %{"name" => "foo", "value" => "updated"},
- %{"name" => "foo1", "value" => "updated"}
+ %{"name" => "foo", "value" => "bar"},
+ %{"name" => "foo11", "value" => "bar11"}
]
update_data =
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Thu, Nov 28, 5:09 AM (1 d, 18 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
40842
Default Alt Text
(2 KB)
Attached To
Mode
rPUBE pleroma-upstream
Attached
Detach File
Event Timeline
Log In to Comment