{"record":{"id":"6918433c001ae06d","repo":"jstedfast/MailKit","slug":"invalid-type-0-message","errorCode":null,"errorMessage":"Invalid Type{0} message.","messagePattern":"Invalid Type(.+?) message\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"MailKit/Security/Ntlm/NtlmMessageBase.cs","lineNumber":90,"sourceCode":"\t\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\treturn BitConverterLE.ToUInt32 (message, startIndex + 8) == Type;\n\t\t}\n\n\t\tprotected void ValidateArguments (byte[] message, int startIndex, int length)\n\t\t{\n\t\t\tif (message == null)\n\t\t\t\tthrow new ArgumentNullException (nameof (message));\n\n\t\t\tif (startIndex < 0 || startIndex > message.Length)\n\t\t\t\tthrow new ArgumentOutOfRangeException (nameof (startIndex));\n\n\t\t\tif (length < 12 || length > (message.Length - startIndex))\n\t\t\t\tthrow new ArgumentOutOfRangeException (nameof (length));\n\n\t\t\tif (!CheckSignature (message, startIndex))\n\t\t\t\tthrow new ArgumentException (string.Format (CultureInfo.InvariantCulture, \"Invalid Type{0} message.\", Type), nameof (message));\n\n\t\t\tvar messageType = BitConverterLE.ToUInt32 (message, 8);\n\t\t\tif (messageType != Type)\n\t\t\t\tthrow new ArgumentException (string.Format (CultureInfo.InvariantCulture, \"Invalid Type{0} message.\", Type), nameof (message));\n\t\t}\n\n\t\tpublic abstract byte[] Encode ();\n\t}\n}\n","sourceCodeStart":72,"sourceCodeEnd":100,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/Security/Ntlm/NtlmMessageBase.cs#L72-L100","documentation":"ValidateArguments throws ArgumentException \"Invalid Type{0} message.\" when CheckSignature fails: the buffer at startIndex does not start with the required 'NTLMSSP\\0' signature. The library requires all NTLM messages to begin with this 8-byte magic marker before parsing. A buffer without it is not an NTLMSSP message at all.","triggerScenarios":"Calling a decode API with a byte[] whose first bytes at startIndex are not the ASCII signature 'NTLMSSP\\0' (wrong protocol data, truncated message, or misaligned startIndex).","commonSituations":"Feeding a raw SASL/GSSAPI wrapped token instead of the unwrapped NTLM payload; startIndex pointing into the middle of the message past the signature; a peer sending a malformed or non-NTLM blob.","solutions":["Ensure the byte array begins with the 'NTLMSSP\\0' signature at startIndex","Unwrap any SASL/GSSAPI framing before passing the NTLM message","Dump the first 8 bytes at startIndex to confirm alignment"],"exampleFix":"// before\nchallenge.Decode(wrappedToken, 0, wrappedToken.Length); // SASL-framed\n// after\nvar ntlm = UnwrapSasl(wrappedToken); // starts with NTLMSSP\\0\nchallenge.Decode(ntlm, 0, ntlm.Length);","handlingStrategy":"validation","validationCode":"static bool HasNtlmSignature(byte[] buf, int start) =>\n    buf != null && start + 8 <= buf.Length &&\n    buf[start] == 'N' && buf[start+1] == 'T' && buf[start+2] == 'L' && buf[start+3] == 'M' &&\n    buf[start+4] == 'S' && buf[start+5] == 'S' && buf[start+6] == 'P' && buf[start+7] == 0;","typeGuard":"bool IsNtlmMessage(byte[] buf) => HasNtlmSignature(buf, 0);","tryCatchPattern":"try { msg.Decode(buffer, 0, buffer.Length); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"Invalid Type\")) { /* not an NTLMSSP message — inspect peer data */ }","preventionTips":["Unwrap SASL/GSSAPI layers before handing tokens to the NTLM parser","Log the first bytes of any token that fails signature checks","Never assume an opaque auth token is a raw NTLM message"],"tags":["ntlm","signature","mailkit"],"backgroundTag":"invalid-argument-format","analyzedSha":"9d3859a7855e3e17582c07fd01972b8e262bf176","analyzedAt":"2026-09-15T15:46:11.592Z","contentChangedAt":"2026-09-15T15:46:11.592Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}