mongodb/node-mongodb-native · error · MongoInvalidArgumentError
Unable to continue SCRAM without valid nonce
Error message
Unable to continue SCRAM without valid nonce
What it means
Thrown by continueScramConversation() (scram.ts:127) as a MongoInvalidArgumentError when authContext.nonce is falsy at the point of computing the client proof. Like error 82, this indicates the SCRAM conversation continued without prepare() having generated and stored a nonce. An internal invariant violation, not normally user-reachable.
Source
Thrown at src/cmap/auth/scram.ts:127
const db = credentials.source;
const saslStartCmd = makeFirstMessage(cryptoMethod, credentials, nonce);
const response = await connection.command(ns(`${db}.$cmd`), saslStartCmd, undefined);
await continueScramConversation(cryptoMethod, response, authContext);
}
async function continueScramConversation(
cryptoMethod: CryptoMethod,
response: Document,
authContext: AuthContext
): Promise<void> {
const connection = authContext.connection;
const credentials = authContext.credentials;
if (!credentials) {
throw new MongoMissingCredentialsError('AuthContext must provide credentials.');
}
if (!authContext.nonce) {
throw new MongoInvalidArgumentError('Unable to continue SCRAM without valid nonce');
}
const nonce = authContext.nonce;
const db = credentials.source;
const username = cleanUsername(credentials.username);
const password = credentials.password;
const processedPassword =
cryptoMethod === 'sha256' ? saslprep(password) : passwordDigest(username, password);
const payload: Binary = ByteUtils.isUint8Array(response.payload)
? new Binary(response.payload)
: response.payload;
const dict = parsePayload(payload);
const iterations = parseInt(dict.i, 10);
if (iterations && iterations < 4096) {View on GitHub (pinned to 3366c21a63)
Solutions
- Ensure prepare() runs to completion before auth()/continueScramConversation()
- Do not share a single AuthContext across concurrent connections
- Report as a bug with the driver version if using an unmodified MongoClient
Defensive patterns
Strategy: try-catch
Try / catch
try {
await client.connect();
} catch (e) {
if (e instanceof MongoInvalidArgumentError && /nonce/.test(e.message)) {
// internal invariant - file a driver bug
}
throw e;
} Prevention
- Do not override prepare() in ScramSHA subclasses without calling super
- Never reuse a single AuthContext across two concurrent auth attempts
- Pin driver versions in CI to detect regressions
When it happens
Trigger: continueScramConversation invoked without a preceding successful prepare(); a driver-internal state corruption where the nonce was cleared between prepare and continue; reauthenticating a pooled connection whose AuthContext was reset improperly.
Common situations: Driver defect; non-standard subclassing of ScramSHA that overrides prepare() without setting the nonce; concurrent reuse of an AuthContext across two auth attempts.
Related errors
- AuthContext must contain a valid nonce property
- Username required for mechanism '${this.mechanism}'
- AuthContext must provide credentials.
- Server returned an invalid iteration count ${iterations}
- Server returned an invalid nonce: ${rnonce}
AI-assisted analysis of mongodb/node-mongodb-native@3366c21a63 (2026-08-04).
Data as JSON: /data/errors/ad53972f11229f9e.json.
Report an issue: GitHub.