pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Nathan Bossart <nathandbossart@gmail.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Alexander Lakhin <exclusion@gmail.com>
Cc: pgsql-hackers <pgsql-hackers@postgresql.org>
Subject: Re: Should rolpassword be toastable?
Date: Thu, 19 Sep 2024 16:52:02 -0500
Message-ID: <ZuydAj4nrt4cpGU5@nathan> (raw)
In-Reply-To: <ZuxjAIOJ4GSa34KC@nathan>
References: <89e8649c-eb74-db25-7945-6d6b23992394@gmail.com>
	<1284094.1695479962@sss.pgh.pa.us>
	<67793ae1-3adc-a6e0-0bb3-c23a28c0627a@gmail.com>
	<a9524f94-316c-349a-6e4d-79b878706f82@gmail.com>
	<Zuwzp09o9uiG0f0F@nathan>
	<1986859.1726756275@sss.pgh.pa.us>
	<ZuxjAIOJ4GSa34KC@nathan>

On Thu, Sep 19, 2024 at 12:44:32PM -0500, Nathan Bossart wrote:
> On Thu, Sep 19, 2024 at 10:31:15AM -0400, Tom Lane wrote:
>> We could put an arbitrary limit (say, half of BLCKSZ) on the length of
>> passwords.
> 
> Something like that could be good enough.  I was thinking about actually
> validating that the hash had the correct form, but that might be a little
> more complex than is warranted here.

Oh, actually, I see that we are already validating the hash, but you can
create valid SCRAM-SHA-256 hashes that are really long.  So putting an
arbitrary limit (patch attached) is probably the correct path forward.  I'd
also remove pg_authid's TOAST table while at it.

-- 
nathan

Attachments:

fail_for_long_scram_hash.patch (text/plain, 966B) download diff --git a/src/backend/libpq/crypt.c b/src/backend/libpq/crypt.c index 629e51e00b..a723e8219a 100644 --- a/src/backend/libpq/crypt.c +++ b/src/backend/libpq/crypt.c @@ -121,6 +121,19 @@ encrypt_password(PasswordType target_type, const char *role, if (guessed_type != PASSWORD_TYPE_PLAINTEXT) { + /* + * Valid SCRAM-SHA-256 hashes can have very long "iterations" and + * "salt" fields, but we don't want to store anything that might get + * TOASTed, since de-TOASTing won't work during authentication because + * we haven't selected a database yet and cannot read pg_class. 256 + * bytes should be more than enough for all practical use, so fail for + * anything longer. + */ + if (guessed_type == PASSWORD_TYPE_SCRAM_SHA_256 && + strlen(password) > 256) + ereport(ERROR, + (errmsg("SCRAM-SHA-256 hash is too long"))); + /* * Cannot convert an already-encrypted password from one format to * another, so return it as it is.

view thread (27+ messages)  latest in thread

Message-ID: <ZuydAj4nrt4cpGU5@nathan>
Permalink:  ../ZuydAj4nrt4cpGU5@nathan/
Also on:    postgresql.org/message-id/ZuydAj4nrt4cpGU5@nathan

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: nathandbossart@gmail.com, tgl@sss.pgh.pa.us, exclusion@gmail.com
  Subject: Re: Should rolpassword be toastable?
  In-Reply-To: <ZuydAj4nrt4cpGU5@nathan>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox