Authentication identity smuggling via NUL-byte injection in SASL PLAIN payload
Description
Impact
The Go Driver does not reject \x00 characters in a PLAIN username or password. The SASL PLAIN message separates its fields with \x00, so an embedded \x00 changes where the fields split, and consequently the server can authenticate a different user, or check different a password, than the application intended.
Applications are affected if they use PLAIN authentication and build the username or password from untrusted input. The attacker still needs valid database credentials for the user the server authenticates: this only bypasses the application's authorization policy, such as a tenant suffix or a deny-list, not database authentication.
Workarounds
Users can reject \x00 characters before connecting:
opts := options.Client().ApplyURI(uri)
if cred := opts.Auth; cred != nil &&
(strings.ContainsRune(cred.Username, 0) || strings.ContainsRune(cred.Password, 0)) {
return errors.New("username and password cannot contain NUL characters")
}Proof of Concept
Before 2.10.1, an application that builds username = user_input + "@tenant1.example" and receives a user_input of admin\x00secret\x00 would produce this payload:
"\x00" + "admin\x00secret\x00@tenant1.example" + "\x00" + "<password>"which splits into five NUL-separated fields:
"" \x00 "admin" \x00 "secret" \x00 "@tenant1.example" \x00 "<password>"So mongod's built-in PLAIN mechanism reads the username as admin and the password as secret, and anything after the third \x00 is ignored, bypassing the application's intended tenant restriction.