GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Support libpq's `channel_binding` and `require_auth` (and enforce them against every authentication request) by jawj · Pull Request #3746 · brianc/node-postgres

Conversation

@jawj

@jawj jawj commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

This builds on my earlier PR, #3356, which added SCRAM-SHA-256-PLUS behind the enableChannelBinding option. As I noted then, that option let us enable channel binding but gave no way to require it. Being opt-in and non-standard, I suspect rather few users yet get the benefit of it.

This PR moves to using a libpq-style channel_binding parameter. It also introduces a libpq-style require_auth parameter, and makes sure both are enforced everywhere they need to be.

These changes make some connections more secure by default. They also provide users with the option to make connections even more secure, by specifying channel_binding=require or specific authentication modes, such as require_auth=scram-sha-256, that limit the damage that can be done by an MITM attack. And they bring node-postgres's connection options into closer alignment with libpq.

Because channel_binding=require authenticates the server, it also silences the deprecation warning that sslmode=prefer, sslmode=require and sslmode=verify-ca currently emit (this matters to Neon users, for example, who see those warnings even though the weaker guarantees they warn about cannot be exploited when the channel is bound).

channel_binding

  • Takes libpq's three values, disable, prefer and require, from the client config, a connection string, or PGCHANNELBINDING.
  • The default is now prefer: channel binding is used whenever the connection is over SSL and the server offers SCRAM-SHA-256-PLUS, and an unbound exchange is used otherwise. This matches libpq's default.
  • enableChannelBinding is still honored, with true meaning "prefer" and false meaning "disable" (it also accepts the three levels), but is now documented as deprecated.
  • channel_binding: 'require' needs SSL, so it is an error to combine it with SSL disabled — unless you are using the native (libpq) client, which negotiates SSL of its own accord and reports for itself if it ends up without.

require_auth

Names the authentication method(s) the server is allowed to ask for, with libpq's semantics: a comma-separated allow-list, or a block-list in which every entry is negated with !, plus none for a connection where the server asks for nothing. It can be set in the config, a connection string, or PGREQUIREAUTH — which an explicit require_auth: '' overrides, as in libpq.

  • The methods libpq recognizes are password, md5, scram-sha-256, gss, sspi and oauth, of which this client implements the first three. A setting that includes only methods we cannot satisfy (e.g. require_auth: 'gss') is an error at construction-time (but e.g. require_auth: 'gss,md5' is fine). The native client passes the setting to libpq and defers to it, so the full set is accepted there.
  • channel_binding: 'require' implies require_auth: 'scram-sha-256', since no other method supports channel binding. A require_auth value that rules out SCRAM contradicts that, so is also an error.

Enforcing them

The kind of bug I filed CVE-2025-49146 for against pgjdbc is a risk here — where channel_binding=require was honored inside the SCRAM exchange but a server could simply ask for a plain password instead!

So the check lives in one place that every authentication request passes through, modelled on libpq's check_expected_areq:

  • Requirements are checked before the client answers, so a refused request neither sends a password nor invokes a password callback.
  • The same check runs on AuthenticationOk, and again where the connection becomes usable, so a server cannot evade a requirement by declaring the client authenticated without asking for anything — or by sending no authentication message at all. libpq accepts nothing but an authentication request at that point in its handshake, whereas this client listens for every message from the start, so it needs the second check.
  • Authentication is answered once, whatever the two new parameters are set to. A server that asks again, having already said what it wanted and been given it, is refused.
  • A refused authentication request now stays refused. A server can pipeline an entire successful login into one packet, and the messages following the refused request were still acted on: the connection callback was invoked a second time, this time reporting success, a connect event was emitted, and the client was left looking usable. Such a client now reports the failure once and refuses to answer anything further.
  • Hashing an MD5 password and computing a SCRAM proof each take a turn of the event loop, and Connection#end() writes its Terminate before ending the stream, so both re-check that the connection has not been given up on before writing their answer.

Two related tightenings in the SCRAM code: the client counts itself channel-bound only once the server's signature has been verified, and only for SCRAM-SHA-256-PLUS, so an unbound exchange cannot satisfy require; and a server offering SCRAM-SHA-256-PLUS on a connection that is not encrypted is refused.

Naming

Both parameters keep libpq's spelling (the same as client_encoding and application_name do, for example). Since both exist to refuse weak authentication, a camelCased channelBinding or requireAuth throws rather than being quietly ignored, as does a channel binding level that is not one of the supported three. Both options can also be set on a Pool, which passes its options to the clients it creates.

Changing the default

Changing default behaviour was a concern last time round. prefer only ever upgrades a connection that is already over SSL, to a server that offers channel binding, and falls back to an unbound exchange otherwise, so there is nothing for a server to be surprised by. The one case where an outcome changes is a server whose certificate uses a signature algorithm the parser doesn't know (Ed448, for instance): that connection now fails rather than silently authenticating unbound. The same thing can happen in libpq. In either case, channel_binding: 'disable' restores the old outcome.

Tests

  • packages/pg/test/unit/client/auth-flow-tests.js drives a client through complete exchanges against a scripted SCRAM server using a real certificate, computing the server's replies from what the client actually sent, so it checks the gs2 header and the binding data rather than taking the client's word for either. This helps with @charmander's point on Add support for SCRAM-SHA-256-PLUS i.e. channel binding #3356 that the tests there would have passed with no implementation of channel binding at all. It covers each of the refusals above, including the pipelined login and the post-refusal races.
  • require-auth-tests.js covers the parsing and the requirement check. The ConnectionParameters and pg-connection-string tests cover resolution from config, connection strings and the environment, precedence between them, and each error.
  • The SCRAM integration tests now run over real SSL and assert whether the exchange was bound, and PGTESTNOSSL is no longer set in CI, so the SSL and channel binding tests actually run there (perhaps there is a good reason for setting PGTESTNOSSL in CI, though?). packages/pg/script/test-server.sh starts the same image CI uses under either podman or docker, for anyone who wants to run them locally.

Docs are in docs/pages/features/ssl.mdx and the pg-connection-string README, with a suggested CHANGELOG entry too.

DefinitelyTyped's @types/pg will need channel_binding and require_auth adding. I'll send a PR for that if and when these changes land.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

danielloader reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
jawj added 2 commits August 12, 2026 15:23
@jawj
Add support for channel_binding and require_auth connection parameter…
b93c6ea
…s, following libpq
@jawj
Merge remote-tracking branch 'upstream/master'
9febd2a
@jawj
jawj requested a review from hjr3 as a code owner August 12, 2026 15:28
jawj added 2 commits August 12, 2026 16:46
@jawj
Exclude Node 16 from SSL tests (libpq fails to get server cert in nat…
aea2cb9
…ive driver)
@jawj
Remove PGTESTNOSSL again, and guard the specific unavoidably-failing …
3124258
…Node 16 SSL test
@jawj

jawj commented Aug 25, 2026

Copy link
Copy Markdown
Contributor Author

@hjr3 or @brianc: any thoughts on this?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@charmander

charmander commented Aug 25, 2026

Copy link
Copy Markdown
Collaborator

(For what it’s worth: I haven’t reviewed the diff yet, but the PR description sounds perfect.)

jawj reacted with laugh emoji
All reactions
  • 😄 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

charmander
charmander reviewed Aug 25, 2026
View reviewed changes

@charmander charmander left a comment

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Partial review that doesn’t cover the core logic. Test refactoring suggestions needn’t block merge.)

Thanks for implementing all this!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread packages/pg/lib/channel-binding.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread packages/pg/lib/client.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread packages/pg/test/unit/client/auth-flow-tests.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread packages/pg/test/unit/client/auth-flow-tests.js Outdated
Comment on lines +160 to +162
await awaitQuiet()

assert.deepStrictEqual(connecting.errors, [])

@charmander charmander Aug 25, 2026

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And it looks like this kind of thing should be a flag to startClient that no errors are expected.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@jawj jawj Aug 28, 2026

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Certainly this is a common pattern. For now, I've refactored it into a waitForSuccess function, for symmetry with waitForError.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@jawj jawj Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@charmander Would you consider this resolved?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread packages/pg/test/unit/client/auth-flow-tests.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread packages/pg/test/unit/connection-parameters/creation-tests.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread CHANGELOG.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

hjr3
hjr3 reviewed Aug 26, 2026
View reviewed changes

@hjr3 hjr3 left a comment

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, this looks great. One minor piece of feedback on Options.channelBinding but this does not have to be blocking a merge.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread packages/pg-connection-string/index.d.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

jawj and others added 7 commits August 28, 2026 14:35
@jawj
Make enableChannelBinding emit a deprecation warning; allow booleans …
fd99925
…for enableChannelBinding but not channel_binding
@jawj
Remove some busy-waits from tests; abridged some comments
a246b6d
@jawj
Implement waitForSuccess in tests instead of waiting then testing for…
9686fb6
… no errors
@jawj
Small assertiomn tweak
20a6005
@jawj @charmander
Update CHANGELOG.md
170a64b
Co-authored-by: Charmander <[email protected]>
@jawj
Linting fixes
89c1215
@jawj
Disallow changing channelBinding after Client construction
887c1ca
@jawj

jawj commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

I think I've addressed all comments, so I'm hopeful this can now be merged. :)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

jawj added 4 commits September 7, 2026 16:35
@jawj
Channel-binding: more robust/exhaustive cert hash parsing and calcula…
ff69936
…tion
@jawj
Merge remote-tracking branch 'upstream/master'
8124def
@jawj
Lint fixes
36659c4
@jawj
Merge branch 'master' into master
b3d979c
@jawj

jawj commented Sep 7, 2026

Copy link
Copy Markdown
Contributor Author

Since this PR effectively changes channel binding from opt-in to opt-out, it becomes more important to support all potential certificate hash types.

So I thought it was worth putting in a bit more work to (a) make the hash/digest type parsing in signatureAlgorithmHashFromCertificate pretty much exhaustive, and (b) use node:crypto as a fallback for SubtleCrypto when calculating the hash (since it supports more algorithms).

@charmander and @hjr3 — please do let me know if there are any more changes you'd like to see.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jawj
Don't support old and insecure signature algorithms for channel binding
9722bfe
@jawj

jawj commented Sep 15, 2026

Copy link
Copy Markdown
Contributor Author

SCRAM-SHA-256 upgrades MD5 and SHA-1 to SHA-256, indicating an intention to be at least as secure as SHA-256. My updated signature algorithm-parsing code already had MD2, MD4, MDC2 and SHA-0 as explicitly unsupported. My latest commit disables two additional algorithms: RIPEMD160 and GOST94.

Any remaining blockers to merging?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jawj

jawj commented Sep 29, 2026

Copy link
Copy Markdown
Contributor Author

Sorry to chase, but any thoughts on getting this merged?

danielloader reacted with eyes emoji
All reactions
  • 👀 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@breken-ai breken-ai mentioned this pull request Oct 8, 2026
fix(pg-connection-string): keep %XX escapes with hex letters when re-encoding #3798
Open
@jawj

jawj commented Oct 17, 2026

Copy link
Copy Markdown
Contributor Author

Bun.sql has just merged channel binding support: oven-sh/bun#41703. Unlike psql they're defaulting it to disable for now, which I guess is a more conservative option we could also take here. Would be nice to get it merged one way or the other, though. :)

danielloader reacted with rocket emoji
All reactions
  • 🚀 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jawj

jawj commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

postgres.js v4 now also has channel binding, set to prefer by default.

@brianc @hjr3 @charmander is there anything particular blocking a merge here?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@charmander

charmander commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator

(Sorry if my adding a comment was misleading; I didn’t review the core parts of this pull request, and I don’t expect to find any significant time to volunteer for pg any time soon.)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@hjr3 hjr3 hjr3 left review comments
@charmander charmander charmander left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@jawj @charmander @hjr3
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.