{"record":{"id":"b71738d01cbbac04","repo":"jstedfast/MailKit","slug":"user-name-too-long","errorCode":null,"errorMessage":"User name too long.","messagePattern":"User name too long\\.","errorType":"exception","errorClass":"AuthenticationException","httpStatus":null,"severity":"error","filePath":"MailKit/Net/Proxy/Socks5Client.cs","lineNumber":242,"sourceCode":"\t\t\t// |  1  |   1    |\n\t\t\t// +-----+--------+\n\t\t\tint nread, n = 0;\n\t\t\tdo {\n\t\t\t\tif ((nread = await ReceiveAsync (socket, buffer, 0 + n, 2 - n, cancellationToken).ConfigureAwait (false)) > 0)\n\t\t\t\t\tn += nread;\n\t\t\t} while (n < 2);\n\n\t\t\tVerifySocksVersion (buffer[0]);\n\n\t\t\treturn (Socks5AuthMethod) buffer[1];\n\t\t}\n\n\t\tbyte[] GetAuthenticateCommand ()\n\t\t{\n\t\t\tvar user = Encoding.UTF8.GetBytes (ProxyCredentials!.UserName);\n\n\t\t\tif (user.Length > 255)\n\t\t\t\tthrow new AuthenticationException (\"User name too long.\");\n\n\t\t\tvar passwd = Encoding.UTF8.GetBytes (ProxyCredentials.Password);\n\n\t\t\tif (passwd.Length > 255) {\n\t\t\t\tArray.Clear (passwd, 0, passwd.Length);\n\t\t\t\tthrow new AuthenticationException (\"Password too long.\");\n\t\t\t}\n\n\t\t\tvar buffer = new byte[user.Length + passwd.Length + 3];\n\t\t\tint n = 0;\n\n\t\t\tbuffer[n++] = 1;\n\t\t\tbuffer[n++] = (byte) user.Length;\n\t\t\tBuffer.BlockCopy (user, 0, buffer, n, user.Length);\n\t\t\tn += user.Length;\n\t\t\tbuffer[n++] = (byte) passwd.Length;\n\t\t\tBuffer.BlockCopy (passwd, 0, buffer, n, passwd.Length);\n","sourceCodeStart":224,"sourceCodeEnd":260,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/Net/Proxy/Socks5Client.cs#L224-L260","documentation":"The SOCKS5 username/password (RFC 1929) sub-negotiation limits each field to a single length byte, i.e. 255 bytes. GetAuthenticateCommand throws AuthenticationException when the UTF-8 encoded UserName exceeds 255 bytes, since it cannot be encoded on the wire.","triggerScenarios":"Socks5Client.Connect/ConnectAsync with ProxyCredentials whose UserName encodes to more than 255 UTF-8 bytes.","commonSituations":"Users pasting credentials containing a whole token/URL or a JWT as the username; enterprise credential strings with long domain prefixes; multi-byte characters (e.g. CJK) pushing a nominally short username over 255 bytes.","solutions":["Shorten the username to 255 UTF-8 bytes or less (trim domain prefix if the proxy allows bare username)","Use an authentication method without the 255-byte limit, or pre-authorize by IP so no username is needed","Count bytes, not characters, when validating credentials before configuring the client"],"exampleFix":"// before\nvar name = \"cn=svc,ou=proxy,dc=example,dc=com;\" + longToken; // >255 bytes\ncredentials.UserName = name;\n// after\nvar name = \"svc-proxy\"; // short, pre-registered on the proxy\ncredentials.UserName = name;","handlingStrategy":"validation","validationCode":"if (Encoding.UTF8.GetByteCount(user) > 255)\n    throw new ArgumentException(\"SOCKS5 username must be <= 255 UTF-8 bytes.\", nameof(user));","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate credential byte lengths at config load","Never paste tokens/JWTs into SOCKS5 username fields","Remember bytes vs characters for non-ASCII credentials"],"tags":["socks5","authentication","credentials"],"backgroundTag":"authentication-required","analyzedSha":"9d3859a7855e3e17582c07fd01972b8e262bf176","analyzedAt":"2026-09-15T15:46:11.592Z","contentChangedAt":"2026-09-15T15:46:11.592Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}