{"record":{"id":"90484998f8ecca96","repo":"brianc/node-postgres","slug":"sasl-scram-server-first-message-iteration-missin","errorCode":null,"errorMessage":"SASL: SCRAM-SERVER-FIRST-MESSAGE: iteration missing","messagePattern":"SASL: SCRAM-SERVER-FIRST-MESSAGE: iteration missing","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/pg/lib/crypto/sasl.js","lineNumber":209,"sourceCode":"\nfunction parseServerFirstMessage(data) {\n  const attrPairs = parseAttributePairs(data)\n\n  const nonce = attrPairs.get('r')\n  if (!nonce) {\n    throw new Error('SASL: SCRAM-SERVER-FIRST-MESSAGE: nonce missing')\n  } else if (!isPrintableChars(nonce)) {\n    throw new Error('SASL: SCRAM-SERVER-FIRST-MESSAGE: nonce must only contain printable characters')\n  }\n  const salt = attrPairs.get('s')\n  if (!salt) {\n    throw new Error('SASL: SCRAM-SERVER-FIRST-MESSAGE: salt missing')\n  } else if (!isBase64(salt)) {\n    throw new Error('SASL: SCRAM-SERVER-FIRST-MESSAGE: salt must be base64')\n  }\n  const iterationText = attrPairs.get('i')\n  if (!iterationText) {\n    throw new Error('SASL: SCRAM-SERVER-FIRST-MESSAGE: iteration missing')\n  } else if (!/^[1-9][0-9]*$/.test(iterationText)) {\n    throw new Error('SASL: SCRAM-SERVER-FIRST-MESSAGE: invalid iteration count')\n  }\n  const iteration = parseInt(iterationText, 10)\n\n  return {\n    nonce,\n    salt,\n    iteration,\n  }\n}\n\nfunction parseServerFinalMessage(serverData) {\n  const attrPairs = parseAttributePairs(serverData)\n  const error = attrPairs.get('e')\n  const serverSignature = attrPairs.get('v')\n\n  if (error) {","sourceCodeStart":191,"sourceCodeEnd":227,"githubUrl":"https://github.com/brianc/node-postgres/blob/ff9d775abd12f29dd6df03945253b54eabbb29f2/packages/pg/lib/crypto/sasl.js#L191-L227","documentation":"Thrown by parseServerFirstMessage() when the server's first SASL message lacks the i= attribute (the iteration count). Per RFC 5802, the server must specify the PBKDF2 iteration count as a positive integer. Without it, the client cannot perform the key derivation with the correct work factor.","triggerScenarios":"At sasl.js:207-208, attrPairs.get('i') returns a falsy value (undefined). The parsed attribute Map has no 'i' key — the server omitted the iteration count.","commonSituations":"Malformed or truncated server first message; connecting to a non-conformant server that doesn't fully implement SCRAM-SHA-256; a proxy truncating the authentication exchange; network data loss cutting the message short.","solutions":["Verify the target is a standard PostgreSQL server with full SCRAM-SHA-256 support.","Remove intermediaries that might truncate the SASL message.","Test with psql using the same connection string.","Update node-postgres to the latest version."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await client.connect()\n} catch (err) {\n  if (err.message.includes('iteration missing')) {\n    throw new Error('SCRAM handshake failed: server sent no iteration count — verify server is PostgreSQL 10+')\n  }\n  throw err\n}","preventionTips":["Verify the target is a standard PostgreSQL server with full SCRAM-SHA-256 support.","Remove intermediaries that might truncate the SASL message.","Test with psql using the same connection string.","Enable SSL/TLS to protect the authentication stream."],"tags":["authentication","sasl","scram","protocol-error","connection"],"backgroundTag":null,"analyzedSha":"ff9d775abd12f29dd6df03945253b54eabbb29f2","analyzedAt":"2026-08-11T15:33:59.644Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}