···11-using Iceshrimp.Backend.Core.Configuration;
11+using Iceshrimp.Shared.Configuration;
22using J = System.Text.Json.Serialization.JsonPropertyNameAttribute;
3344namespace Iceshrimp.Backend.Controllers.Pleroma.Schemas.Entities;
···34343535public class FieldsLimits
3636{
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;
3737+ [J("max_fields")] public int MaxFields => Limits.MaxProfileFields;
3838+ [J("max_remote_fields")] public int MaxRemoteFields => Limits.MaxProfileFields;
3939+ [J("name_length")] public int NameLength => Limits.MaxProfileFieldNameLength;
4040+ [J("value_length")] public int ValueLength => Limits.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;
7066}
+10-9
Iceshrimp.Backend/Core/Services/UserService.cs
···1717using Iceshrimp.Backend.Core.Queues;
1818using Iceshrimp.EntityFrameworkCore.Extensions;
1919using Iceshrimp.MfmSharp;
2020+using Iceshrimp.Shared.Configuration;
2021using Microsoft.EntityFrameworkCore;
2122using Microsoft.Extensions.Options;
2223···322323 })
323324 .Where(p => p is
324325 {
325325- Name.Length: <= Constants.MaxProfileFieldNameLength,
326326- Value.Length: <= Constants.MaxProfileFieldValueLength
326326+ Name.Length: <= Limits.MaxProfileFieldNameLength,
327327+ Value.Length: <= Limits.MaxProfileFieldValueLength
327328 })
328328- .Take(Constants.MaxProfileFields);
329329+ .Take(Limits.MaxProfileFields);
329330330331 var pronouns = actor.Pronouns?.Values.ToDictionary(p => p.Key, p => p.Value ?? "");
331332···376377 if (user.UserProfile == null) throw new Exception("user.UserProfile must not be null at this stage");
377378378379 // @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");
380380+ if (user.UserProfile.Fields.Length > Limits.MaxProfileFields)
381381+ throw GracefulException.BadRequest($"Profile must not contain more than {Limits.MaxProfileFields} fields");
382382+ if (user.UserProfile.Fields.Any(p => p.Name.Length > Limits.MaxProfileFieldNameLength))
383383+ throw GracefulException.BadRequest($"Profile must not contain any fields with a name exceeding {Limits.MaxProfileFieldNameLength} characters");
384384+ if (user.UserProfile.Fields.Any(p => p.Value.Length > Limits.MaxProfileFieldValueLength))
385385+ throw GracefulException.BadRequest($"Profile must not contain any fields with a value exceeding {Limits.MaxProfileFieldValueLength} characters");
385386 // @formatter:on
386387387388 user.DisplayName = user.DisplayName?.ReplaceLineEndings("\n").Trim();
···11+namespace Iceshrimp.Shared.Configuration;
22+33+public static class Limits
44+{
55+ public const int MaxProfileFields = 10;
66+ public const int MaxProfileFieldNameLength = 1000;
77+ public const int MaxProfileFieldValueLength = 1000;
88+}