Commit 1c9b6e81 authored by Heikki Linnakangas's avatar Heikki Linnakangas

Verify that the server constructed the SCRAM nonce correctly.

The nonce consists of client and server nonces concatenated together. The
client checks the nonce contained the client nonce, but it would get fooled
if the server sent a truncated or even empty nonce.

Reported by Steven Fackler to security@postgresql.org. Neither me or Steven
are sure what harm a malicious server could do with this, but let's fix it.
parent d951db2e
...@@ -430,7 +430,8 @@ read_server_first_message(fe_scram_state *state, char *input, ...@@ -430,7 +430,8 @@ read_server_first_message(fe_scram_state *state, char *input,
} }
/* Verify immediately that the server used our part of the nonce */ /* Verify immediately that the server used our part of the nonce */
if (strncmp(nonce, state->client_nonce, strlen(state->client_nonce)) != 0) if (strlen(nonce) < strlen(state->client_nonce) ||
memcmp(nonce, state->client_nonce, strlen(state->client_nonce)) != 0)
{ {
printfPQExpBuffer(errormessage, printfPQExpBuffer(errormessage,
libpq_gettext("invalid SCRAM response (nonce mismatch)\n")); libpq_gettext("invalid SCRAM response (nonce mismatch)\n"));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment