{"id":"8328c16c62768d8b","repo":"mongodb/node-mongodb-native","slug":"auth-mechanism-scram-sha-1-is-not-supported-in-fip","errorCode":null,"errorMessage":"Auth mechanism SCRAM-SHA-1 is not supported in FIPS mode","messagePattern":"Auth mechanism SCRAM-SHA-1 is not supported in FIPS mode","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/cmap/auth/scram.ts","lineNumber":252,"sourceCode":"    nodeCrypto = require('crypto');\n  } catch (e) {\n    throw new MongoRuntimeError(\n      'Node.js crypto module is required for SCRAM-SHA-1 authentication',\n      {\n        cause: e\n      }\n    );\n  }\n\n  try {\n    const md5 = nodeCrypto.createHash('md5');\n    md5.update(`${username}:mongo:${password}`, 'utf8');\n    return md5.digest('hex');\n  } catch (err) {\n    if (nodeCrypto.getFips()) {\n      // This error is (slightly) more helpful than what comes from OpenSSL directly, e.g.\n      // 'Error: error:060800C8:digital envelope routines:EVP_DigestInit_ex:disabled for FIPS'\n      throw new Error('Auth mechanism SCRAM-SHA-1 is not supported in FIPS mode');\n    }\n    throw err;\n  }\n}\n\n// XOR two buffers\nfunction xor(a: Uint8Array, b: Uint8Array) {\n  const length = Math.max(a.length, b.length);\n  const res = [];\n\n  for (let i = 0; i < length; i += 1) {\n    res.push(a[i] ^ b[i]);\n  }\n\n  return ByteUtils.toBase64(ByteUtils.fromNumberArray(res));\n}\n\nasync function H(method: CryptoMethod, text: Uint8Array): Promise<Uint8Array> {","sourceCodeStart":234,"sourceCodeEnd":270,"githubUrl":"https://github.com/mongodb/node-mongodb-native/blob/3366c21a6311e02f1be91da982f9b93d3cce99a0/src/cmap/auth/scram.ts#L234-L270","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Switch the user's auth mechanism to SCRAM-SHA-256, which is FIPS-compliant","On the server, create a SCRAM-SHA-256 credential set: db.createUser({...mechanisms:['SCRAM-SHA-256']})","Update the connection string to specify authMechanism=MONGODB-SCRAM-SHA-256","Avoid enabling FIPS mode unless required - SCRAM-SHA-256 is the modern default on MongoDB 4.0+"],"exampleFix":"// before\nconst client = new MongoClient('mongodb://user:pass@host/?authMechanism=SCRAM-SHA-1');\n// after\nconst client = new MongoClient('mongodb://user:pass@host/?authMechanism=SCRAM-SHA-256');","handlingStrategy":"validation","validationCode":"import crypto from 'crypto';\nfunction isFipsMode(): boolean {\n  try { return Boolean((crypto as any).getFips?.()); } catch { return false; }\n}\nif (isFipsMode() && uri.includes('SCRAM-SHA-1')) {\n  throw new Error('SCRAM-SHA-1 cannot be used in FIPS mode; switch to SCRAM-SHA-256');\n}","typeGuard":null,"tryCatchPattern":"try {\n  await client.connect();\n} catch (e) {\n  if (e instanceof Error && /FIPS mode/i.test(e.message)) {\n    // recreate user with SCRAM-SHA-256 and update the URI\n  }\n  throw e;\n}","preventionTips":["Default to SCRAM-SHA-256 on MongoDB 4.0+","Before enabling FIPS, ensure all DB users use SCRAM-SHA-256","Document the FIPS-compliance requirement in deployment runbooks"],"tags":["auth","scram","fips","crypto","compliance"],"analyzedSha":"3366c21a6311e02f1be91da982f9b93d3cce99a0","analyzedAt":"2026-08-04T13:40:15.335Z","schemaVersion":2}