-
Type:
Bug
-
Resolution: Unresolved
-
Priority:
Minor - P4
-
None
-
Affects Version/s: None
-
Component/s: Authentication
-
None
-
None
-
Dotnet Drivers
-
None
-
None
-
None
-
None
-
None
-
None
Affects driver versions 2.12.0 through 3.12.0, and current main.
On Linux, the driver authenticates Kerberos (GSSAPI) through libgssapi. GssInputBuffer(string) (src/MongoDB.Driver/Authentication/Gssapi/Libgssapi/GssInputBuffer.cs) builds the GSSAPI buffer like this:
_length = (nuint)inputString.Length; // number of UTF-16 chars _value = Marshal.StringToHGlobalAnsi(inputString); // UTF-8 bytes on Linux
GSSAPI treats length as the number of bytes to read (RFC 2744, gss_buffer_desc). Any character outside ASCII takes more than one byte in UTF-8, so the declared length is too short and the end of the string is dropped. libgssapi reports success on the truncated value, so nothing fails until authentication does.
The same constructor is used for:
- the username: GssapiSecurityCredential.Acquire → gss_import_name
- the password: GssapiSecurityCredential.Acquire → gss_acquire_cred_with_password
- the service principal name: GssapiServicePrincipalName.Create
Windows isn't affected; it uses SSPI instead.
Observed: on Linux (Ubuntu, MIT krb5 1.20.1) against current main, calling the driver's internal libgssapi types, with a local MIT KDC for EXAMPLE.COM. The driver's byte[] constructor, which uses the byte count, returned every name intact, and so did MIT's kinit for the same principals and passwords.
Names (gss_import_name / gss_display_name):
| Input | UTF-8 bytes | Declared length | Name held by GSSAPI |
|---|---|---|---|
| alice@EXAMPLE.COM | 17 | 17 | alice@EXAMPLE.COM |
| jérôme@EXAMPLE.COM | 20 | 18 | jérôme@EXAMPLE.C |
| 田中@EXAMPLE.COM | 18 | 14 | 田中@EXAMPLE |
Service principal names (GssapiServicePrincipalName.Create):
| Expected | Name held by GSSAPI |
|---|---|
| mongodb@db.example.com | mongodb@db.example.com |
| mongodb@dé.example.com | mongodb@dé.example.co |
| mongodb@db.example.com@RÉALM.COM | mongodb@db.example.com@RÉALM.CO |
Credentials (GssapiSecurityCredential.Acquire(username, password), real AS exchange with the KDC):
| Principal (real password) | Password passed | Result |
|---|---|---|
| dave@EXAMPLE.COM (secret) | secret | success |
| alice@EXAMPLE.COM (pässwörd) | pässwörd | Preauthentication failed (kinit succeeds) |
| carol@EXAMPLE.COM (pässwö) | pässwörd (wrong) | success: only the first 8 bytes, pässwö, are sent |
| carol@EXAMPLE.COM (pässwö) | pässwö (correct) | Preauthentication failed: only pässw is sent |
| jérôme@EXAMPLE.COM (secret) | secret | Cannot find KDC for realm "EXAMPLE.C" (kinit succeeds) |
Expected: the GSSAPI buffer length equals the UTF-8 byte count, so non-ASCII principals and passwords reach libgssapi intact.
Impact: Kerberos authentication on Linux fails, or targets a truncated principal, whenever the username, password, host or realm contains non-ASCII characters. ASCII-only credentials are unaffected.
Suggested fix: encode once and use the byte count. For example: var bytes = Encoding.UTF8.GetBytes(inputString);, allocate and copy, then set _length = (nuint)bytes.Length. The byte[] constructor already handles length this way.
Testing notes: a unit test can check that the length the buffer declares equals the string's UTF-8 byte count; it needs no Kerberos setup. A full end-to-end check needs the GSSAPI test environment (GSSAPI_TESTS_ENABLED, AUTH_HOST, AUTH_GSSAPI) with a non-ASCII principal.