Skip to content

Commit 344a113

Browse files
committed
Don't use SCRAM-specific "e=invalid-proof" on invalid password.
Instead, send the same FATAL message as with other password-based authentication mechanisms. This gives a more user-friendly message: psql: FATAL: password authentication failed for user "test" instead of: psql: error received from server in SASL exchange: invalid-proof Even before this patch, the server sent that FATAL message, after the SCRAM-specific "e=invalid-proof" message. But libpq would stop at the SCRAM error message, and not process the ErrorResponse that would come after that. We could've taught libpq to check for an ErrorResponse after failed authentication, but it's simpler to modify the server to send only the ErrorResponse. The SCRAM specification allows for aborting the authentication at any point, using an application-defined error mechanism, like PostgreSQL's ErrorResponse. Using the e=invalid-proof message is optional. Reported by Jeff Janes. Discussion: https://www.postgresql.org/message-id/CAMkU%3D1w3jQ53M1OeNfN8Cxd9O%2BA_9VONJivTbYoYRRdRsLT6vA@mail.gmail.com
1 parent 44c5288 commit 344a113

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/backend/libpq/auth-scram.c

+7-8
Original file line numberDiff line numberDiff line change
@@ -343,21 +343,20 @@ pg_be_scram_exchange(void *opaq, char *input, int inputlen,
343343
* If we performed a "mock" authentication that we knew would fail
344344
* from the get go, this is where we fail.
345345
*
346+
* The SCRAM specification includes an error code,
347+
* "invalid-proof", for authentication failure, but it also allows
348+
* erroring out in an application-specific way. We choose to do
349+
* the latter, so that the error message for invalid password is
350+
* the same for all authentication methods. The caller will call
351+
* ereport(), when we return SASL_EXCHANGE_FAILURE with no output.
352+
*
346353
* NB: the order of these checks is intentional. We calculate the
347354
* client proof even in a mock authentication, even though it's
348355
* bound to fail, to thwart timing attacks to determine if a role
349356
* with the given name exists or not.
350357
*/
351358
if (!verify_client_proof(state) || state->doomed)
352359
{
353-
/*
354-
* Signal invalid-proof, although the real reason might also
355-
* be e.g. that the password has expired, or the user doesn't
356-
* exist. "e=other-error" might be more correct, but
357-
* "e=invalid-proof" is more likely to give a nice error
358-
* message to the user.
359-
*/
360-
*output = psprintf("e=invalid-proof");
361360
result = SASL_EXCHANGE_FAILURE;
362361
break;
363362
}

0 commit comments

Comments
 (0)