{"record":{"id":"b503817a09f4dedc","repo":"TechnitiumSoftware/DnsServer","slug":"display-name-length-cannot-exceed-255-characters","errorCode":null,"errorMessage":"Display name length cannot exceed 255 characters.","messagePattern":"Display name length cannot exceed 255 characters\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"DnsServerCore/Auth/User.cs","lineNumber":448,"sourceCode":"\n        public int CompareTo(User other)\n        {\n            return _username.CompareTo(other._username);\n        }\n\n        #endregion\n\n        #region properties\n\n        public string DisplayName\n        {\n            get { return _displayName; }\n            set\n            {\n                if (string.IsNullOrWhiteSpace(value))\n                    _displayName = _username;\n                else if (value.Length > 255)\n                    throw new ArgumentException(\"Display name length cannot exceed 255 characters.\", nameof(DisplayName));\n                else\n                    _displayName = value;\n            }\n        }\n\n        public string Username\n        { get { return _username; } }\n\n        public bool IsSsoUser\n        { get { return _isSsoUser; } }\n\n        public string SsoIdentifier\n        { get { return _ssoIdentifier; } }\n\n        public UserPasswordHashType PasswordHashType\n        { get { return _passwordHashType; } }\n\n        public string PasswordHash","sourceCodeStart":430,"sourceCodeEnd":466,"githubUrl":"https://github.com/TechnitiumSoftware/DnsServer/blob/d0484b6c1e7439cdc53d67d81e9c876cda2ad756/DnsServerCore/Auth/User.cs#L430-L466","documentation":"Thrown by the User.DisplayName setter when the supplied value exceeds 255 characters. The limit is enforced because the display name is persisted via WriteShortString, which encodes length in a bounded prefix; a longer string would corrupt the saved user record. ArgumentException is used (not InvalidOperationException) because the argument itself is invalid. A null/whitespace value is allowed and falls back to the username.","triggerScenarios":"Assigning user.DisplayName = someLongString where someLongString.Length > 255, typically from an admin profile-edit form or an LDAP/SSO attribute mapping that pulls an unbounded display name.","commonSituations":"SSO/LDAP 'displayName' or 'CN' attribute mapped without truncation; copy-paste of a long descriptive string; a sync job that writes raw directory data into DisplayName.","solutions":["Truncate the input to 255 characters before assigning, or reject it at the form/API layer.","Sanitize mapped SSO/LDAP attributes (substring 0..255) during provisioning.","Add client-side maxlength=255 on the display-name input."],"exampleFix":"// before\nuser.DisplayName = displayName;\n\n// after\nuser.DisplayName = displayName?.Length > 255 ? displayName.Substring(0, 255) : displayName;","handlingStrategy":"validation","validationCode":"const int MAX = 255;\nif (!string.IsNullOrWhiteSpace(value) && value.Length > MAX)\n    value = value.Substring(0, MAX);\nuser.DisplayName = value;","typeGuard":"static bool IsValidDisplayName(string value) => string.IsNullOrWhiteSpace(value) || value.Length <= 255;","tryCatchPattern":null,"preventionTips":["Enforce maxlength=255 on the display-name input client-side.","Truncate mapped SSO/LDAP attributes during provisioning.","Validate length in the API handler and return 400 early."],"tags":["auth","validation","length-limit","serialization","technitium-dns-server"],"backgroundTag":null,"analyzedSha":"d0484b6c1e7439cdc53d67d81e9c876cda2ad756","analyzedAt":"2026-08-13T22:57:35.508Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}