···11+using Iceshrimp.Backend.Core.Configuration;
12using J = System.Text.Json.Serialization.JsonPropertyNameAttribute;
2334namespace Iceshrimp.Backend.Controllers.Pleroma.Schemas.Entities;
···3132 [J("fields_limits")] public FieldsLimits FieldsLimits => new();
3233}
33343434-// there doesn't seem to be any limits there, from briefly checking the code
3535public class FieldsLimits
3636{
3737- [J("max_fields")] public int MaxFields => int.MaxValue;
3838- [J("max_remote_fields")] public int MaxRemoteFields => int.MaxValue;
3939- [J("name_length")] public int NameLength => int.MaxValue;
4040- [J("value_length")] public int ValueLength => int.MaxValue;
3737+ [J("max_fields")] public int MaxFields => Constants.MaxProfileFields;
3838+ [J("max_remote_fields")] public int MaxRemoteFields => Constants.MaxProfileFields;
3939+ [J("name_length")] public int NameLength => Constants.MaxProfileFieldNameLength;
4040+ [J("value_length")] public int ValueLength => Constants.MaxProfileFieldValueLength;
4141}
+4
Iceshrimp.Backend/Core/Configuration/Constants.cs
···6363 "audio/flac",
6464 "audio/vnd.wave"
6565 ];
6666+6767+ public const int MaxProfileFields = 10;
6868+ public const int MaxProfileFieldNameLength = 1000;
6969+ public const int MaxProfileFieldValueLength = 1000;
6670}
+17-2
Iceshrimp.Backend/Core/Services/UserService.cs
···315315 Exception("User host must not be null at this stage"));
316316317317 var fields = actor.Attachments?.OfType<ASField>()
318318- .Where(p => p is { Name: not null, Value: not null })
318318+ .Where(p => p is { Name.Length: > 0, Value.Length: > 0 })
319319 .Select(p => new UserProfile.Field
320320 {
321321 Name = p.Name!, Value = MfmConverter.FromHtml(p.Value).Mfm
322322- });
322322+ })
323323+ .Where(p => p is
324324+ {
325325+ Name.Length: <= Constants.MaxProfileFieldNameLength,
326326+ Value.Length: <= Constants.MaxProfileFieldValueLength
327327+ })
328328+ .Take(Constants.MaxProfileFields);
323329324330 var pronouns = actor.Pronouns?.Values.ToDictionary(p => p.Key, p => p.Value ?? "");
325331···368374 {
369375 if (user.IsRemoteUser) throw new Exception("This method is only valid for local users");
370376 if (user.UserProfile == null) throw new Exception("user.UserProfile must not be null at this stage");
377377+378378+ // @formatter:off
379379+ if (user.UserProfile.Fields.Length > Constants.MaxProfileFields)
380380+ throw GracefulException.BadRequest($"Profile must not contain more than {Constants.MaxProfileFields} fields");
381381+ if (user.UserProfile.Fields.Any(p => p.Name.Length > Constants.MaxProfileFieldNameLength))
382382+ throw GracefulException.BadRequest($"Profile must not contain any fields with a name exceeding {Constants.MaxProfileFieldNameLength} characters");
383383+ if (user.UserProfile.Fields.Any(p => p.Value.Length > Constants.MaxProfileFieldValueLength))
384384+ throw GracefulException.BadRequest($"Profile must not contain any fields with a value exceeding {Constants.MaxProfileFieldValueLength} characters");
385385+ // @formatter:on
371386372387 user.DisplayName = user.DisplayName?.ReplaceLineEndings("\n").Trim();
373388 user.UserProfile.Description = user.UserProfile.Description?.ReplaceLineEndings("\n").Trim();