From edcdedcaae098add2ed7b58d89e247e0207c1e8e Mon Sep 17 00:00:00 2001 From: Christopher Pickering Date: Wed, 15 Jun 2022 13:00:14 -0500 Subject: [PATCH] Added check for blank password. --- package-lock.json | 1 + package.json | 1 + server/util-server.js | 10 +++++++++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/package-lock.json b/package-lock.json index d213b883..b26f6008 100644 --- a/package-lock.json +++ b/package-lock.json @@ -53,6 +53,7 @@ "notp": "~2.0.3", "password-hash": "~1.2.2", "pg": "^8.7.3", + "pg-connection-string": "^2.5.0", "postcss-rtlcss": "~3.4.1", "postcss-scss": "~4.0.3", "prismjs": "^1.27.0", diff --git a/package.json b/package.json index 781e07b1..17c73689 100644 --- a/package.json +++ b/package.json @@ -105,6 +105,7 @@ "notp": "~2.0.3", "password-hash": "~1.2.2", "pg": "^8.7.3", + "pg-connection-string": "^2.5.0", "postcss-rtlcss": "~3.4.1", "postcss-scss": "~4.0.3", "prismjs": "^1.27.0", diff --git a/server/util-server.js b/server/util-server.js index 34139383..dc403cbd 100644 --- a/server/util-server.js +++ b/server/util-server.js @@ -12,6 +12,7 @@ const chroma = require("chroma-js"); const { badgeConstants } = require("./config"); const mssql = require("mssql"); const { Client } = require("pg"); +const postgresConParse = require("pg-connection-string").parse; const { NtlmClient } = require("axios-ntlm"); // From ping-lite @@ -265,11 +266,18 @@ exports.postgresQuery = function (connectionString, query) { return new Promise((resolve, reject) => { + const config = postgresConParse(connectionString); + + if (config.password === "") { + // See https://github.com/brianc/node-postgres/issues/1927 + return reject(new Error("Password is undefined.")); + } + const client = new Client({ connectionString }); client.connect(); - client.query(query) + return client.query(query) .then(res => { resolve(res); })