-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error: SASL: SCRAM-SERVER-FIRST-MESSAGE: client password must be a string #2757
Comments
|
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. |
I'm using jest and supertest for testing my express APIs with Postgre.
|
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. |
I don't know if the root cause is the same, but I can reliably reproduce this just by trying to connect to a database that isn't password-protected, which I believe ought to be possible (even if not advisable in production, obviously...) new pg.Pool({
connectionString: "postgres://username@localhost/dbname"
}); |
@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. |
Here is a minimal reproduction:
{
"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 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. When I add a password |
The problem - in my specific case - was outside this library. Sorry for noise. |
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 |
Port can be blank --> defaults to 5432 Just a blank password caused the problem |
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
|
SpeculationCould be that a blank password causes a syntax error in the JavaScript code; could be uncatchable. |
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 problem was that I was importing the models and using it directly in a helpers/utils/functions file,
|
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? 😅 |
To use a Java analogy, it would be a difference between a compiler error versus a runtime error. The try catch does not get a chance to 'fire' as the JavaScript has syntax errors i.e. NOT compilable/runnable. Imagine a missing brace. This next part is complete speculation, some regular expression strips quotes so that only the text of the password is sent to the database, however, if the password is blank then striping the quotes turns the password from a string to undefine which then causes a syntax error blowing up the code before the try catch can do its thing. Or it could be something completely different. For comic relief, I recommend watching this (so much applies): The line below might help // ==================================================
// if the password is blank set it to a single space
// ==================================================
connConfig.password = connConfig.password.length == 0 ? " " : connConfig.password |
I'm using typeorm and I had to export an environment variable with the database connection string:
|
This comment was marked as duplicate.
This comment was marked as duplicate.
Your password is blank/null. Somewhere you need to set it. |
https://github.com/brianc/node-postgres/blob/master/packages/pg/lib/sasl.js
Line 23 to 25
The text was updated successfully, but these errors were encountered: