mongodb/node-mongodb-native · error · Error

Auth mechanism SCRAM-SHA-1 is not supported in FIPS mode

Error message

Auth mechanism SCRAM-SHA-1 is not supported in FIPS mode

What it means

Thrown by passwordDigest() (scram.ts:252) as a plain Error when the MD5 hash operation fails AND nodeCrypto.getFips() returns truthy - i.e. the process is running in FIPS mode, which disables MD5. SCRAM-SHA-1 relies on MD5 for the password digest, which is not FIPS-compliant, so the driver surfaces this explicit, more helpful error instead of the raw OpenSSL failure.

Source

Thrown at src/cmap/auth/scram.ts:252

    nodeCrypto = require('crypto');
  } catch (e) {
    throw new MongoRuntimeError(
      'Node.js crypto module is required for SCRAM-SHA-1 authentication',
      {
        cause: e
      }
    );
  }

  try {
    const md5 = nodeCrypto.createHash('md5');
    md5.update(`${username}:mongo:${password}`, 'utf8');
    return md5.digest('hex');
  } catch (err) {
    if (nodeCrypto.getFips()) {
      // This error is (slightly) more helpful than what comes from OpenSSL directly, e.g.
      // 'Error: error:060800C8:digital envelope routines:EVP_DigestInit_ex:disabled for FIPS'
      throw new Error('Auth mechanism SCRAM-SHA-1 is not supported in FIPS mode');
    }
    throw err;
  }
}

// XOR two buffers
function xor(a: Uint8Array, b: Uint8Array) {
  const length = Math.max(a.length, b.length);
  const res = [];

  for (let i = 0; i < length; i += 1) {
    res.push(a[i] ^ b[i]);
  }

  return ByteUtils.toBase64(ByteUtils.fromNumberArray(res));
}

async function H(method: CryptoMethod, text: Uint8Array): Promise<Uint8Array> {

View on GitHub (pinned to 3366c21a63)

Solutions

  1. Switch the user's auth mechanism to SCRAM-SHA-256, which is FIPS-compliant
  2. On the server, create a SCRAM-SHA-256 credential set: db.createUser({...mechanisms:['SCRAM-SHA-256']})
  3. Update the connection string to specify authMechanism=MONGODB-SCRAM-SHA-256
  4. Avoid enabling FIPS mode unless required - SCRAM-SHA-256 is the modern default on MongoDB 4.0+

Example fix

// before
const client = new MongoClient('mongodb://user:pass@host/?authMechanism=SCRAM-SHA-1');
// after
const client = new MongoClient('mongodb://user:pass@host/?authMechanism=SCRAM-SHA-256');
Defensive patterns

Strategy: validation

Validate before calling

import crypto from 'crypto';
function isFipsMode(): boolean {
  try { return Boolean((crypto as any).getFips?.()); } catch { return false; }
}
if (isFipsMode() && uri.includes('SCRAM-SHA-1')) {
  throw new Error('SCRAM-SHA-1 cannot be used in FIPS mode; switch to SCRAM-SHA-256');
}

Try / catch

try {
  await client.connect();
} catch (e) {
  if (e instanceof Error && /FIPS mode/i.test(e.message)) {
    // recreate user with SCRAM-SHA-256 and update the URI
  }
  throw e;
}

Prevention

When it happens

Trigger: Process launched with FIPS mode enabled (NODE_OPTIONS=--use-openssl-fips, or crypto.setFips(true), or a FIPS-compiled OpenSSL) while authenticating with SCRAM-SHA-1. MD5 is disabled in FIPS, so createHash('md5') throws.

Common situations: Compliance-regulated environments (US government, healthcare, finance) that mandate FIPS; Linux distributions with FIPS-hardened OpenSSL; setting FIPS for other libraries that then breaks SCRAM-SHA-1.

Related errors


AI-assisted analysis of mongodb/node-mongodb-native@3366c21a63 (2026-08-04). Data as JSON: /data/errors/8328c16c62768d8b.json. Report an issue: GitHub.