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 — Error: SASL: SCRAM-SERVER-FIRST-MESSAGE: client password must be a string · Issue #2757 · brianc/node-postgres

Error: SASL: SCRAM-SERVER-FIRST-MESSAGE: client password must be a string #2757

New issue
Copy link
New issue
Copy link
Open
Open
Error: SASL: SCRAM-SERVER-FIRST-MESSAGE: client password must be a string#2757
Copy link

Description

@yuneda
yuneda
opened on Jun 7, 2022
Issue body actions

https://github.com/brianc/node-postgres/blob/master/packages/pg/lib/sasl.js
Line 23 to 25

Reacted by bever1337, Jaime Leonardo Suncin Cruz, Alex Galhardo, 0shape, Mohammad, Soumya Deep Sarkar, Fedu, Vaggelis Manousakis and Nick Clyde

Activity

  1. yuneda commented on Jun 7, 2022

    @yuneda
    yuneda
    on Jun 7, 2022
    Author
    More actions
      if (typeof password !== 'string') {
        throw new Error('SASL: SCRAM-SERVER-FIRST-MESSAGE: client password must be a string')
      }
    
  2. sehrope commented on Jun 7, 2022

    @sehrope
    sehrope
    on Jun 7, 2022
    Contributor
    More actions

    Is there a question or issue? That check was added to the SASL code to provide the end user with a more informative error message rather than just failing due to the password being null / undefined.

  3. yuneda commented on Jun 7, 2022

    @yuneda
    yuneda
    on Jun 7, 2022
    Author
    More actions

    I'm using jest and supertest for testing my express APIs with Postgre.
    The error comes from my code below.

    const app = require('../../app');
    const request = require('supertest');
    let agent = request.agent(app);
    
    describe('Cars', function () {
      it('Get all car', (done) => {
        agent
          .get('/v1/cars')
          .expect('Content-Type', /json/)
          .then((response) => {
            expect(response.status).toEqual(200);
          });
        done();
      });
    });
    
  4. sehrope commented on Jun 7, 2022

    @sehrope
    sehrope
    on Jun 7, 2022
    Contributor
    More actions

    You're probably running your tests without the database password available to the test environment.

    If you're having an actual issue with this library then provide a self contained example that reproduces it.

    Reacted by bever1337 and Abhishek Prajapati
  5. alexianaa commented on Jul 20, 2022

    @alexianaa
    alexianaa
    on Jul 20, 2022
    More actions

    I changed the password using:

    $ sudo passwd postgres
    new password:
    password again:
    $ su postgres
    

    remember change the password at the file

    Reacted by Marcus Martins, Luan Melo, Iago Campelo and Thyago Henrique Moura dos Anjos
    Reacted by Nguyễn Văn Tuấn, fabrotec, Javohir Muhammadiyev, Carlos Peñaloza, jkazimierczak, Anya Rajan, Daniel Osvaldo Rahmanto, Rafa, SlipknoteDark, Ammar and 5 more
  6. sehrope commented on Aug 1, 2022

    @sehrope
    sehrope
    on Aug 1, 2022
    Contributor
    More actions

    @Quintinius The "localhost" in that connection URI would connect over TCP, not a unix socket. Check your pg_hba to see if TCP connections are requiring SASL. It's probably only local unix socket connections that are password-less.

  7. bever1337 commented on Aug 20, 2022

    @bever1337
    bever1337
    on Aug 20, 2022
    More actions

    Here is a minimal reproduction:

    # .env
    PGDATABASE=blahblahblah
    PGUSER=blahblahblah
    
    {
      "name": "example reproduction",
      "version": "1.0.0",
      "description": "",
      "main": "index.js",
      "scripts": {
        "test": "echo \"Error: no test specified\" && exit 1"
      },
      "author": "",
      "license": "UNLICENSED",
      "dependencies": {
        "dotenv": "^16.0.1",
        "pg": "^8.7.3"
      }
    }
    const { Pool } = require('pg');
    const  dotenv = require('dotenv');
    
    dotenv.config();
    
    async function main() {
      const pool = new Pool();
      const client = await pool.connect();
      client.release();
    }
    
    main();

    Environment requirements are a database, a database user, and no required database password. Observe that the script exits after some time in v16.14.0 but throws the SASL error in v18.7.0. Guarantee the password parameter is an empty string in both input options and .env files and observe no change in behavior.

    I am assuming there is a breaking change with a NodeJS data type.

    I've been using a database without a password for local testing and development. The database is only available on the local machine. node-postgres has been working fine in another project. I upgraded the node runtime to v18 so I could make use of experimental global Request/Response interfaces and can no longer use pg. Bummer! I hope this helps.

    When I add a password blahblahblah to user blahblahblah, the script works as-expected regardless of node runtime.

    Reacted by Omer Oran, Ran Halprin and Spase Markovski
  8. Vlado-99 commented on Sep 15, 2022

    @Vlado-99
    Vlado-99
    on Sep 15, 2022
    More actions

    Is there a question or issue?

    It is not possible to connect to database using connectionString anymore, if the database account is without password.
    This is a breaking change, issue.

    The problem - in my specific case - was outside this library. Sorry for noise.

  9. rhewy commented on Nov 20, 2022

    @rhewy
    rhewy
    on Nov 20, 2022
    More actions

    If a blank password is sent to the postgreSQL server then and error is thrown

    throw new Error('SASL: SCRAM-SERVER-FIRST-MESSAGE: client password must be a string')

    The error is very special; not caught by .catch on the client promise and not caught with a try catch

    Reacted by Wasiu Idowu
  10. rhewy commented on Nov 20, 2022

    @rhewy
    rhewy
    on Nov 20, 2022
    More actions

    Port can be blank --> defaults to 5432
    Username can be blank --> defaults to the OS username
    Host can be blank --> defaults to localhost

    Just a blank password caused the problem

  11. rhewy commented on Nov 20, 2022

    @rhewy
    rhewy
    on Nov 20, 2022
    More actions

    This seemed to help; if the password is blank/empty set it to a single space

        var connConfig = {
            host: req.body.host,
            port: req.body.port,
            database: req.body.database,
            user: req.body.username,
            password: req.body.password
        };
    
        connConfig.password = connConfig.password.length == 0 ? " " : connConfig.password
    
       
  12. rhewy commented on Nov 20, 2022

    @rhewy
    rhewy
    on Nov 20, 2022 · Hidden as off-topic
    show commentMore actions
  13. Nikire commented on Dec 25, 2022

    @Nikire
    Nikire
    on Dec 25, 2022
    More actions

    Hi ! just want to share my solution, I was getting this error by badly importing some models and using them before I sync the server
    The way I was importing the models :
    const { models: { User, Post } } = require('../sequelize');

    The problem was that I was importing the models and using it directly in a helpers/utils/functions file,
    and then I solve it by passing the models through parameters :

    async findPostAndUser(postId, userId, Post, User) {
    const post = await Post.findOne({ where: { id: { [Op.eq]: postId } } });
    const user = await User.findOne({ where: { id: { [Op.eq]: userId } } });
    return [post, user];}

    Reacted by Ran Halprin
  14. jgoux commented on Jan 19, 2023

    @jgoux
    jgoux
    on Jan 19, 2023
    More actions

    We are hitting this issue too, any password-protected database receiving a connection string with an empty password is raising this error.

    I absolutely have no clue why we can't catch this error, this is actually my main issue. Does anyone know why it's not possible to catch this one? 😅

  15. rhewy commented on Jan 19, 2023

    @rhewy
    rhewy
    on Jan 19, 2023 · Hidden as off-topic
    show commentMore actions
  16. jean-pita commented on Dec 19, 2023

    @jean-pita
    jean-pita
    on Dec 19, 2023
    More actions

    I'm using typeorm and I had to export an environment variable with the database connection string:

    export DATABASE_URL=postgres://postgres:postgres@localhost:5432/default

  17. shuvo-halder commented on Dec 8, 2024

    @shuvo-halder
    shuvo-halder
    on Dec 8, 2024 · Hidden as duplicate
    show commentMore actions
  18. rhewy commented on Dec 8, 2024

    @rhewy
    rhewy
    on Dec 8, 2024
    More actions

    Your password is blank/null. Somewhere you need to set it.

  19. Kartagia commented on May 10, 2025

    @Kartagia
    Kartagia
    on May 10, 2025
    More actions

    Postgresql allows empty password strings, but the library does not. The problem is that somewhere in the node-postgresql code someone uses test if (password) { set password } instead of if(password !== undefined) as they should. The problem is stupidity not doing tests properly, but lazily.

  20. Kartagia commented on May 10, 2025

    @Kartagia
    Kartagia
    on May 10, 2025
    More actions

    Found cause of this problem. It is as I expected, the stupid lazy testing with falsy instead of undefined.

    Package: pg
    Location: packages/pg/lib/connection-parameters.js
    Function: vars (lines 8 -12)

    const val = function (key, config, envVar) {
      if (envVar === undefined) {
        envVar = process.env['PG' + key.toUpperCase()]
      } else if (envVar === false) {
        // do nothing ... use false
      } else {
        envVar = process.env[envVar]
      }
    
      return config[key] || envVar || defaults[key] 
    }
    

    The return clause uses falsy testing instead of testing undefinedness. This is not how testing should be done, if empty strings (or zeros) are allowed as values.

    I am trying to figure out how to create fix patch for this, as the fix is simply defining return statement at line 18:

    return (configKey[key] ?? envVar) ?? defaults[key]
    

    or with following, if support for older syntax is wanted.

    return (configKey[key] == null ? (envVar == null ? defaults[key] : envVar) : configKey[key])
    

    Also the uses pg-connection-string package for parsing connection string assumes all segments of the postgresql query exists, or socket file is used. The latter is NOT show in the documentation pages at all.

  21. saatvik-10 commented on Dec 1, 2025

    @saatvik-10
    saatvik-10
    on Dec 1, 2025
    More actions

    in my case, am using prisma v7 and getting this err....checked everything, both the db url in env and docker pswd are fine still this err

    import { PrismaClient } from './generated/prisma/client';
    import { PrismaPg } from '@prisma/adapter-pg';

    declare global {
    var prisma: PrismaClient | undefined;
    }

    const adapter = new PrismaPg({
    connectionString: process.env.DATABASE_URL
    });

    export const db = globalThis.prisma || new PrismaClient({
    adapter
    });

    if (process.env.NODE_ENV !== 'production') {
    globalThis.prisma = db;
    }

    Reacted by Anshu Gahire, ccf19881030.github.io and Khurshid Ernazarov
  22. FosRexx commented on Dec 3, 2025

    @FosRexx
    FosRexx
    on Dec 3, 2025
    More actions

    in my case, am using prisma v7 and getting this err....checked everything, both the db url in env and docker pswd are fine still this err

    import { PrismaClient } from './generated/prisma/client'; import { PrismaPg } from '@prisma/adapter-pg';

    declare global { var prisma: PrismaClient | undefined; }

    const adapter = new PrismaPg({ connectionString: process.env.DATABASE_URL });

    export const db = globalThis.prisma || new PrismaClient({ adapter });

    if (process.env.NODE_ENV !== 'production') { globalThis.prisma = db; }

    Had the exact same issue. My error was not explicitly passing the connectionString to the PrismaPg adapter, as I incorrectly assumed it would automatically pick it up from the Prisma configuration. Once I explicitly filled in the connectionString with the DATABASE_URL, the error went away. I recommend you double check your DATABASE_URL and ensure you have configured a password for your database user, as some people have found that an empty password field causes this specific adapter issue.

    Reacted by Khurshid Ernazarov
  23. saatvik-10 commented on Dec 7, 2025

    @saatvik-10
    saatvik-10
    on Dec 7, 2025
    More actions

    the DATABASE_URL, the error went away. I recommend you double ch

    still getting the same error....the project is not taking env, just logging undefined (using monorepo)

    Reacted by Khurshid Ernazarov
  24. techforces commented on Dec 17, 2025

    @techforces
    techforces
    on Dec 17, 2025
    More actions

    Had the exact same issue. My error was not explicitly passing the connectionString to the PrismaPg adapter

    Jesus exactly what I was experiencing.
    I have .env file where I have declared my DATABASE_URL but I forgot to enable using the .env parameters inside my Prisma.ts file where I was defining the PrismaClient. It was undefined this entire time. Simply adding import "dotenv/config" fixed it.

  25. saatvik-10 commented on Dec 18, 2025

    @saatvik-10
    saatvik-10
    on Dec 18, 2025
    More actions

    the new prisma version already has that still the issue was coming.....imported the env in both web and server and it worked but then it eliminates the meaning of a mono repo in some way......putting env in every folder instead of the package/db only (db connection url)

  26. henrybastos commented on Feb 18, 2026

    @henrybastos
    henrybastos
    on Feb 18, 2026
    More actions

    Hi! I'm using NestJS and Prisma and also came across this problem, but I managed to solve it.

    In NestJS docs, for a Prisma service, it uses an adapter (which instead of PrismaBetterSqlite3 I was using PrismaPg).

    But instead of:

    new PrismaPg({ url: process.env.DATABASE_URL });

    I did:

    const pool = new pg.Pool({ connectionString: process.env.DATABASE_URL });
    const adapter = new PrismaPg(pool);

    and the problem disappeared :)

    System info:

    @nestjs/common: "^11.0.0"
    @nestjs/core: "^11.0.0"
    prisma: "^7.4.0"
    pg: "^8.18.0"
    @types/pg: "^8.16.0"
    @prisma/adapter-pg: "^7.4.0"
    @prisma/client: "^7.4.0"
    OS: Windows 10
    
  27. charmander commented on Feb 18, 2026

    @charmander
    charmander
    on Feb 18, 2026
    Collaborator
    More actions

    @henrybastos PrismaPg documentation suggests:

    new PrismaPg({ connectionString: process.env.DATABASE_URL })
    Reacted by Henry Bastos da Silva
  28. henrybastos commented on Feb 18, 2026

    @henrybastos
    henrybastos
    on Feb 18, 2026
    More actions

    @henrybastos PrismaPg documentation suggests:

    new PrismaPg({ connectionString: process.env.DATABASE_URL })

    Oh right! I was using the same url parameter as the PrismaBetterSqlite3, now it makes sense. Thanks

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.