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 — No handlers for SASL errors · Issue #1927 · brianc/node-postgres

No handlers for SASL errors #1927

New issue
Copy link
New issue
Copy link
Open
Open
No handlers for SASL errors#1927
Copy link

Description

@sehrope
sehrope
opened on Jul 19, 2019
Issue body actions

Leaving a note here as a reminder to take another look at the SASL error handling. At first glance I don't think the errors would bubble up as they're thrown synchronously in the helper functions and the caller does not catch or emit them up to the client.

node-postgres/lib/sasl.js

Lines 4 to 17 in 0acaf9d

function startSession (mechanisms) {
if (mechanisms.indexOf('SCRAM-SHA-256') === -1) {
throw new Error('SASL: Only mechanism SCRAM-SHA-256 is currently supported')
}
const clientNonce = crypto.randomBytes(18).toString('base64')
return {
mechanism: 'SCRAM-SHA-256',
clientNonce,
response: 'n,,n=*,r=' + clientNonce,
message: 'SASLInitialResponse'
}
}

node-postgres/lib/client.js

Lines 142 to 146 in 0acaf9d

con.on('authenticationSASL', checkPgPass(function (msg) {
saslSession = sasl.startSession(msg.mechanisms)
con.sendSASLInitialResponseMessage(saslSession.mechanism, saslSession.response)
}))

Reacted by Roma P. and Jan Potoms

Activity

  1. gabegorelick commented on Dec 3, 2021

    @gabegorelick
    gabegorelick
    on Dec 3, 2021
    Contributor
    More actions

    At first glance I don't think the errors would bubble up as they're thrown synchronously in the helper functions and the caller does not catch or emit them up to the client.

    This is still an issue as of pg 8.7.1.

    To reproduce, attempt to connect to a PG instance that uses scram and don't specify a password when connecting:

    const client = new Client();
    try {
      await client.connect();
    } catch (err) {
      // this is never reached
    }

    You'll get an uncaught exception: Error: SASL: SCRAM-SERVER-FIRST-MESSAGE: client password must be a string. But this really should be raised by client.connect and not be unhandled.

    Reacted by Roma P. and Lars Hisken
  2. rpominov commented on Jun 6, 2022

    @rpominov
    rpominov
    on Jun 6, 2022
    More actions

    I’m building a CLI app that uses node-postgres.

    When I leave all connection arguments empty as a user of the app, it crashes with this very confusing error.

    As a developer of the app, I don’t see any way to catch this error to provide any context to the user as to why it crashed and exit gracefully.

    If it’s possible to prioritise fixing this, I would appreciate it greatly.

  3. charmander commented on Jun 6, 2022

    @charmander
    charmander
    on Jun 6, 2022
    Collaborator
    More actions

    @rpominov Check if it’s missing before making a connection attempt.

  4. rpominov commented on Jun 7, 2022

    @rpominov
    rpominov
    on Jun 7, 2022
    More actions

    I think postgres allows to setup the server so that you can connect without a password.

    Also checking the password is not trivial, as it can come from at least 4 places that I'm aware of:

    • password option,
    • connectionString option,
    • env variable,
    • .pgpass file.

    In general, there seem to be a lot of authentication methods that node-postgres supports that I don't fully understand. Ideally, I want to just pass the options to node-postgres and show any errors that it produces back to the user, while stating in the documentation that they can use whatever authentication method that the library supports.

  5. ephys commented on Jul 10, 2022

    @ephys
    ephys
    on Jul 10, 2022
    More actions

    We're encountering this issue over at Sequelize after updating our CI to use postgres 14 (PR sequelize/sequelize#14737)

    We have a test that checks that an error is raised is the password is invalid (in this case null), but because the error is not sent to Client.connect, we end up with an unhandled exception

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      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.