passwordcheck: Make the user name check case-insensitive

Started by Anthony Sotolongo4 days ago15 messageshackers

Thread notes

1 note#discussion
hackorum-bot#discussion
hackorum-bot
2 days ago

@global #discussion

#discussion
Jump to latest
#1Anthony Sotolongo
asotolongo@gmail.com

Hi hackers,

contrib/passwordcheck rejects clear-text passwords that contain the role
name, but the check uses a plain strstr(), so it is case-sensitive. A
different capitalization is enough to get around it. For example, for a
role named "alice":

ALTER ROLE alice PASSWORD 'Alice2024!';

is accepted, although the password obviously contains the role name.

The attached patch lowercases both the password and the role name with
str_tolower() before checking whether the password contains the role
name, so the check becomes case-insensitive.

Best regards

Attachments:

t259756_1
v1-0001-passwordcheck-Make-the-user-name-check-case-insen.patchtext/x-patch; charset=US-ASCII; name=v1-0001-passwordcheck-Make-the-user-name-check-case-insen.patchDownload+31-10
#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Anthony Sotolongo (#1)
Re: passwordcheck: Make the user name check case-insensitive

Anthony Sotolongo <asotolongo@gmail.com> writes:

contrib/passwordcheck rejects clear-text passwords that contain the role
name, but the check uses a plain strstr(), so it is case-sensitive. A
different capitalization is enough to get around it. For example, for a
role named "alice":
ALTER ROLE alice PASSWORD 'Alice2024!';
is accepted, although the password obviously contains the role name.

passwordcheck is only intended as sample code, not a production-grade
check for weak passwords. I'm not sure we want to give people the
impression that it's good for anything more than that as-is.

The attached patch lowercases both the password and the role name with
str_tolower() before checking whether the password contains the role
name, so the check becomes case-insensitive.

One reason I'm hesitant about that is that we don't really know the
name's encoding for sure, at least not in the ALTER ROLE pathway.
This problem is bigger than passwordcheck of course, but I'm not
in a hurry to make it worse by assuming that we know how to
case-fold strings found in a shared catalog.

regards, tom lane

#3Anthony Sotolongo
asotolongo@gmail.com
In reply to: Tom Lane (#2)
Re: passwordcheck: Make the user name check case-insensitive

Thanks for the explanation, Tom.
Given that passwordcheck is meant as sample code, I'll not continue with
this patch. In addition, I didn't know that the role name comes from a
shared catalog, so its encoding can't be assumed.

Regards,
Anthony

El mar, 24 nov 2026 a las 23:31, Tom Lane (<tgl@sss.pgh.pa.us>) escribió:

Show quoted text

Anthony Sotolongo <asotolongo@gmail.com> writes:

contrib/passwordcheck rejects clear-text passwords that contain the role
name, but the check uses a plain strstr(), so it is case-sensitive. A
different capitalization is enough to get around it. For example, for a
role named "alice":
ALTER ROLE alice PASSWORD 'Alice2024!';
is accepted, although the password obviously contains the role name.

passwordcheck is only intended as sample code, not a production-grade
check for weak passwords. I'm not sure we want to give people the
impression that it's good for anything more than that as-is.

The attached patch lowercases both the password and the role name with
str_tolower() before checking whether the password contains the role
name, so the check becomes case-insensitive.

One reason I'm hesitant about that is that we don't really know the
name's encoding for sure, at least not in the ALTER ROLE pathway.
This problem is bigger than passwordcheck of course, but I'm not
in a hurry to make it worse by assuming that we know how to
case-fold strings found in a shared catalog.

regards, tom lane

#4Jakub Wartak
jakub.wartak@enterprisedb.com
In reply to: Tom Lane (#2)
Re: passwordcheck: Make the user name check case-insensitive

On Wed, Nov 25, 2026 at 3:31 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:

Good morning Tom,

passwordcheck is only intended as sample code, not a production-grade
check for weak passwords. I'm not sure we want to give people the
impression that it's good for anything more than that as-is.

JFYI, I witnessed cases where people asked for adding functionality into
the passwordcheck (even if that was just for CrackLib) purley because of
the fact that it is provided as ready to load extension inside the
distributed packages (and yes docs say "You can adapt this module to your
needs by changing the source code").

Wouldn't it be better then to just deprecate it in PG20 release notes and
*not* compile by default (unless somebody enhances it greatly; modern
password rules are kind of like: minN chars + min A upper/lowercase
letters + min B numbers + some symbols).

-J.

#5Greg Sabino Mullane
htamfids@gmail.com
In reply to: Tom Lane (#2)
Re: passwordcheck: Make the user name check case-insensitive

On Tue, Nov 24, 2026 at 9:32 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:

passwordcheck is only intended as sample code, not a production-grade
check for weak passwords.

It's definitely being used out in the wild, as is, mostly because it is in
the "blessed" contrib directory. If we don't want people to use in
production, we should move it to the docs and pull it from contrib.

Cheers,
Greg

#6Nathan Bossart
nathandbossart@gmail.com
In reply to: Jakub Wartak (#4)
Re: passwordcheck: Make the user name check case-insensitive

On Wed, Nov 25, 2026 at 02:48:18PM +0100, Jakub Wartak wrote:

On Wed, Nov 25, 2026 at 3:31 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:

passwordcheck is only intended as sample code, not a production-grade
check for weak passwords. I'm not sure we want to give people the
impression that it's good for anything more than that as-is.

JFYI, I witnessed cases where people asked for adding functionality into
the passwordcheck (even if that was just for CrackLib) purley because of
the fact that it is provided as ready to load extension inside the
distributed packages (and yes docs say "You can adapt this module to your
needs by changing the source code").

Wouldn't it be better then to just deprecate it in PG20 release notes and
*not* compile by default (unless somebody enhances it greatly; modern
password rules are kind of like: minN chars + min A upper/lowercase
letters + min B numbers + some symbols).

I think we are in a tricky position when it comes to this module. We claim
it's intended as sample code, and approximately half of its documentation
is warnings about its limitations, but it's apparently still rather
well-used. So we kind of want people to stop using it, but many users will
probably be unhappy with removing it.

If we're not going to consider improvement requests for it, perhaps we
should mark it deprecated but leave it around indefinitely. Else, I think
we should be open to adding further configurability.

--
nathan

#7Tom Lane
tgl@sss.pgh.pa.us
In reply to: Nathan Bossart (#6)
Re: passwordcheck: Make the user name check case-insensitive

Nathan Bossart <nathandbossart@gmail.com> writes:

On Wed, Nov 25, 2026 at 02:48:18PM +0100, Jakub Wartak wrote:

Wouldn't it be better then to just deprecate it in PG20 release notes and
*not* compile by default (unless somebody enhances it greatly; modern
password rules are kind of like: minN chars + min A upper/lowercase
letters + min B numbers + some symbols).

I think we are in a tricky position when it comes to this module. We claim
it's intended as sample code, and approximately half of its documentation
is warnings about its limitations, but it's apparently still rather
well-used. So we kind of want people to stop using it, but many users will
probably be unhappy with removing it.
If we're not going to consider improvement requests for it, perhaps we
should mark it deprecated but leave it around indefinitely. Else, I think
we should be open to adding further configurability.

The fundamental problem I've got with it is that it's nearly a no-op
when presented with a pre-encrypted password, which one hopes is close
to 100% of the time in a well-run installation. To the extent that
people are presenting cleartext passwords so that the check does
something, I think they are suffering a net negative in security.
There's not anything we can do about that by messing with
passwordcheck itself.

So yeah, I'd really prefer to deprecate it. The functionality
could move into psql's \password command, perhaps.

regards, tom lane

#8Daniel Gustafsson
daniel@yesql.se
In reply to: Tom Lane (#7)
Re: passwordcheck: Make the user name check case-insensitive

On 25 Nov 2026, at 20:24, Tom Lane <tgl@sss.pgh.pa.us> wrote:

So yeah, I'd really prefer to deprecate it. The functionality
could move into psql's \password command, perhaps.

It probably won't satisfy most of the users of passwordcheck, but I still like
the idea.

If we deprecate and remove passwordcheck someone can, and most likely will,
pick it up and make a third party extension out of it, which is perfectly fine.

--
Daniel Gustafsson

#9Andreas Karlsson
andreas.karlsson@percona.com
In reply to: Daniel Gustafsson (#8)
Re: passwordcheck: Make the user name check case-insensitive

On 11/25/26 20:30, Daniel Gustafsson wrote:

If we deprecate and remove passwordcheck someone can, and most likely will,
pick it up and make a third party extension out of it, which is perfectly fine.

What is the process for deprecating a contrib module like this? Should
we have a warning in a couple of versions in the documentation before
ripping it out? Should the code also log some warning?

--
Andreas Karlsson
Percona

#10Nathan Bossart
nathandbossart@gmail.com
In reply to: Andreas Karlsson (#9)
Re: passwordcheck: Make the user name check case-insensitive

On Wed, Nov 25, 2026 at 08:34:08PM +0100, Andreas Karlsson wrote:

On 11/25/26 20:30, Daniel Gustafsson wrote:

If we deprecate and remove passwordcheck someone can, and most likely will,
pick it up and make a third party extension out of it, which is perfectly fine.

What is the process for deprecating a contrib module like this? Should we
have a warning in a couple of versions in the documentation before ripping
it out? Should the code also log some warning?

I don't know if we should bother actually removing it, at least anytime
soon. Regardless, I'd start by adding a warning message in the docs (like
what's there for MD5 passwords) and making sure we list it in the v20
release notes next year. Care to draft a patch?

Of course, we should probably wait a little longer for feedback before we
proceed...

--
nathan

#11Andreas Karlsson
andreas.karlsson@percona.com
In reply to: Nathan Bossart (#10)
Re: passwordcheck: Make the user name check case-insensitive

On 11/25/26 21:42, Nathan Bossart wrote:

On Wed, Nov 25, 2026 at 08:34:08PM +0100, Andreas Karlsson wrote:

On 11/25/26 20:30, Daniel Gustafsson wrote:

If we deprecate and remove passwordcheck someone can, and most likely will,
pick it up and make a third party extension out of it, which is perfectly fine.

What is the process for deprecating a contrib module like this? Should we
have a warning in a couple of versions in the documentation before ripping
it out? Should the code also log some warning?

I don't know if we should bother actually removing it, at least anytime
soon. Regardless, I'd start by adding a warning message in the docs (like
what's there for MD5 passwords) and making sure we list it in the v20
release notes next year. Care to draft a patch?

Sure, I could do that when I have some extra time unless someone else
really wants to.

Of course, we should probably wait a little longer for feedback before we
proceed...

+1

--
Andreas Karlsson
Percona

#12Laurenz Albe
laurenz.albe@cybertec.at
In reply to: Daniel Gustafsson (#8)
Re: passwordcheck: Make the user name check case-insensitive

On Wed, 2026-11-25 at 20:30 +0100, Daniel Gustafsson wrote:

On 25 Nov 2026, at 20:24, Tom Lane <tgl@sss.pgh.pa.us> wrote:

So yeah, I'd really prefer to deprecate it. The functionality
could move into psql's \password command, perhaps.

It probably won't satisfy most of the users of passwordcheck, but I still like
the idea.

If we deprecate and remove passwordcheck someone can, and most likely will,
pick it up and make a third party extension out of it, which is perfectly fine.

We have been there before; see the lengthy thread that led to the addition
of the contrib [1]/messages/by-id/flat/D960CB61B694CF459DCFB4B0128514C203937F49@exadv11.host.magwien.gv.at.

The idea to check passwords on the client was deemed useless [2]/messages/by-id/937d27e10910140844v4bc96cd8r33cddcd3a12bf795@mail.gmail.com:

Surely you can see that it is *absolutely pointless* to put an
password complexity checking in the client? All a user would need to
do is grab a copy of psql to bypass it. If they can't do that, there's
probably a scripting language or 12 that would make it similarly easy.

The contrib was accepted a) as a code sample and b) to satisfy a checkbox
item [3]/messages/by-id/1649.1255550447@sss.pgh.pa.us:

Okay, fine, so we're not looking for actual high-grade security,
we're looking to tick off a checkbox in the minds of not terribly
well-informed people. Then the plugin mechanism as currently proposed
will do the job just fine.

Perhaps things have changed, and people today care less about checkbox
items to pass the requirements for a certification. Not sure.

My personal opinion is that the warnings attached to passwordcheck are
clear enough for anybody who really cares. I don't think that the change
proposed in this thread will add any value, but I wouldn't take that as
a reason to remove the module. Mundus vult decipi, and I don't think
removing passwordcheck will increase security anywhere.

Yours,
Laurenz Albe

[1]: /messages/by-id/flat/D960CB61B694CF459DCFB4B0128514C203937F49@exadv11.host.magwien.gv.at
[2]: /messages/by-id/937d27e10910140844v4bc96cd8r33cddcd3a12bf795@mail.gmail.com
[3]: /messages/by-id/1649.1255550447@sss.pgh.pa.us

#13Daniel Gustafsson
daniel@yesql.se
In reply to: Laurenz Albe (#12)
Re: passwordcheck: Make the user name check case-insensitive

On 26 Nov 2026, at 17:12, Laurenz Albe <laurenz.albe@cybertec.at> wrote:

The contrib was accepted a) as a code sample

Putting working code in contrib/ and expecting users to not run it due to it
being a code sample is IMHO an idea which turned out not to work. contrib/ is
seen as a source of "blessed" extensions, which for a lot of stuff in contrib/
is far from reality.

If we want to publish code samples we should add them to the documentation and
properly explain them there. IMHO.

--
Daniel Gustafsson

#14Laurenz Albe
laurenz.albe@cybertec.at
In reply to: Daniel Gustafsson (#13)
Re: passwordcheck: Make the user name check case-insensitive

On Fri, 2026-11-27 at 10:08 +0100, Daniel Gustafsson wrote:

On 26 Nov 2026, at 17:12, Laurenz Albe <laurenz.albe@cybertec.at> wrote:

The contrib was accepted a) as a code sample

Putting working code in contrib/ and expecting users to not run it due to it
being a code sample is IMHO an idea which turned out not to work.  contrib/ is
seen as a source of "blessed" extensions, which for a lot of stuff in contrib/
is far from reality.

If we want to publish code samples we should add them to the documentation and
properly explain them there. IMHO.

I can agree with that. What do you think about point b) in my message?

Yours,
Laurenz Albe

#15Michael Paquier
michael@paquier.xyz
In reply to: Laurenz Albe (#14)
Re: passwordcheck: Make the user name check case-insensitive

On Fri, Nov 27, 2026 at 04:08:43PM +0100, Laurenz Albe wrote:

On Fri, 2026-11-27 at 10:08 +0100, Daniel Gustafsson wrote:

If we want to publish code samples we should add them to the documentation and
properly explain them there. IMHO.

I can agree with that. What do you think about point b) in my message?

I kind of disagree with the point of putting code samples in the docs.
These prove to rot and be forgotten very easily, and they're not easy
to check. You could add some sample module in src/test/modules/
instead, which would make sure that the code always works, under the
condition that it is useful for.. Tests. Then just have the docs
point at a wanted path in the code tree.
--
Michael