An empty password in connection configuration

An empty password in connection configuration

Description

If a connection has an empty password or passphrase, check the server account’s authentication method. For password authentication, the server decides whether it accepts an empty value.

Potential impact

If the server accepts it, anyone who can reach the service may be able to act with the account’s permissions, such as reading, changing or deleting data, sending mail or using a queue. If it rejects the value, connection failures can disrupt service.

Remediation

For password authentication, supply a strong, nondefault password through protected environment variables or a secret store such as AWS Secrets Manager or Vault. Stop before connecting if it is missing or empty. For passwordless authentication, check the credentials and policy used by that method.

Examples

Before

javascript
// Supply an empty password in configuration
const mysql = require("mysql2/promise");

const config = {
  host: "db.internal",
  user: "app_user",
  password: "", // Whether an empty password is accepted depends on server authentication
  database: "app",
};

async function connect() {
  const conn = await mysql.createConnection(config);
  console.log("connected");
}

connect().catch(console.error);

After

javascript
// Load secrets from protected configuration and reject empty required values
const mysql = require("mysql2/promise");

function requiredEnv(name) {
  const v = process.env[name];
  if (!v || v.trim().length === 0) {
    throw new Error(`Missing required secret: ${name}`);
  }
  return v;
}

const dbPassword = requiredEnv("DB_PASSWORD");

const config = {
  host: process.env.DB_HOST || "db.internal",
  user: process.env.DB_USER || "app_user",
  password: dbPassword,
  database: process.env.DB_NAME || "app",
};

async function connect() {
  const conn = await mysql.createConnection(config);
  console.log("connected");
}

connect().catch((err) => {
  // Do not log sensitive values
  console.error("DB 연결 실패:", err.message);
  process.exit(1);
});

Here requiredEnv rejects a missing, empty or whitespace-only DB_PASSWORD before connecting to MySQL. Also check who can access the environment and how the account authenticates on the server.

References