Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1srP4M-001BgU-NU for pgsql-hackers@arkaria.postgresql.org; Thu, 19 Sep 2024 21:52:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1srP4K-008ir2-BW for pgsql-hackers@arkaria.postgresql.org; Thu, 19 Sep 2024 21:52:09 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1srP4K-008iqq-1U for pgsql-hackers@lists.postgresql.org; Thu, 19 Sep 2024 21:52:09 +0000 Received: from mail-il1-x130.google.com ([2607:f8b0:4864:20::130]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1srP4H-000523-D0 for pgsql-hackers@postgresql.org; Thu, 19 Sep 2024 21:52:08 +0000 Received: by mail-il1-x130.google.com with SMTP id e9e14a558f8ab-3a09d785423so5292645ab.0 for ; Thu, 19 Sep 2024 14:52:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726782725; x=1727387525; darn=postgresql.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=plOqi9Pr3ueFHefbVqe+2NlB3fWnSM4C1APpETHOeV8=; b=jbmgKO6Cqhbu+x7AO8lSLUz8sSs73A+MgzVUf3qvki8ovIThMfahvshqsYvv22cmrv 6HQWalvRJYM7Qaxh0emjxYqJxwi9jytfK8/JqZv9Ny+PPhedpboLg3QYcbiJvJr6MbhV j20wc+Up2b5IpwphzSZIfprT8oVeLLnrQGsePuyQ+lNlNMC5zjbIXoiYWQGkCAjVYjuB 2bmrDz7Q6PCHEAHh83JyhWyHuo3zonYj4cVzbIZatWE65Ii2WzS23vIPQ4H2qE7bhbPx luT+yN+tJ++ObIyY2scGr64JhZGdhly2NFNc5eZZxIDjBJGTS7nuNSBY12TD6Ck1RW3O y80w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726782725; x=1727387525; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=plOqi9Pr3ueFHefbVqe+2NlB3fWnSM4C1APpETHOeV8=; b=Dywhl7UflmM4dUOA+ajjv+keDpCMdLSempFce/qrjqmSHqkfiKE8px7gQTv+heoPyx 492KIE16nqPh9vE9TpWB/O4TiyqqT/chZa67d8HvRReayIDIshettzo5V/JSQq5iqJCA 4ttvbPMFdLZD2D/WbN5uEYyNXp+9x8q0gz1+B8eNBmoiMEyMAVZF+/KXgMhSs7ijw5gr 6ro0yeigFcmcS0dRzTEd92FDeKpmUMUYxVWXVbCbAb3JaoDyTutoJXv7HvXgpIiEiM48 jxsS9MJkA0Kkcb4IlZtdpnhraTABVfZ9jC8ZJLBeqCQIBNK8cR3ZaU5JglGPMeeAGlZB Hs8A== X-Forwarded-Encrypted: i=1; AJvYcCWSC1q7xu7hvM9pcmCR4WAtKfQULjzIBexpJSb39KX/8YzmT3MocwUWjMG1PUBuAcHBN43FRe+aTKoD6NDa@postgresql.org X-Gm-Message-State: AOJu0YxHT/zSp1B8KY9F8UHntX3LhzNupkummFEyCRBZPhUEQy2+hTA8 WpMXog8YRuCA3+TG9LqsviX2xyp4lWBfECa8FgRh924XbVTNuUK8AEQu5g== X-Google-Smtp-Source: AGHT+IFNwi0iK0s5Kh305Z7Bq6KLKMPx/K/etWr720ZgqKVWXGPW0oMkaq+Bi3d5JEB/scE7rc9EwQ== X-Received: by 2002:a05:6e02:184a:b0:39d:4ef6:b36d with SMTP id e9e14a558f8ab-3a0c9d17295mr6933385ab.7.1726782725162; Thu, 19 Sep 2024 14:52:05 -0700 (PDT) Received: from nathan (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-4d37ebf4b78sm3215481173.25.2024.09.19.14.52.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Sep 2024 14:52:04 -0700 (PDT) Date: Thu, 19 Sep 2024 16:52:02 -0500 From: Nathan Bossart To: Tom Lane Cc: Alexander Lakhin , pgsql-hackers Subject: Re: Should rolpassword be toastable? Message-ID: References: <89e8649c-eb74-db25-7945-6d6b23992394@gmail.com> <1284094.1695479962@sss.pgh.pa.us> <67793ae1-3adc-a6e0-0bb3-c23a28c0627a@gmail.com> <1986859.1726756275@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="OPwpp7vWUTj0xjp/" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --OPwpp7vWUTj0xjp/ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 --OPwpp7vWUTj0xjp/ Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="fail_for_long_scram_hash.patch" 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. --OPwpp7vWUTj0xjp/--