{"id":"741f24558ab59018","repo":"brianc/node-postgres","slug":"sasl-scram-server-first-message-nonce-missing","errorCode":null,"errorMessage":"SASL: SCRAM-SERVER-FIRST-MESSAGE: nonce missing","messagePattern":"SASL: SCRAM-SERVER-FIRST-MESSAGE: nonce missing","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/pg/lib/crypto/sasl.js","lineNumber":197,"sourceCode":"\n  return new Map(\n    text.split(',').map((attrValue) => {\n      if (!/^.=/.test(attrValue)) {\n        throw new Error('SASL: Invalid attribute pair entry')\n      }\n      const name = attrValue[0]\n      const value = attrValue.substring(2)\n      return [name, value]\n    })\n  )\n}\n\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 {","sourceCodeStart":179,"sourceCodeEnd":215,"githubUrl":"https://github.com/brianc/node-postgres/blob/c5e8c9a57bff6d9160ec5dbd5c4f4c1e4c460711/packages/pg/lib/crypto/sasl.js#L179-L215","documentation":"Thrown by parseServerFirstMessage (sasl.js:195-197) when the server's first SCRAM message has no 'r' attribute (the combined nonce). The nonce is mandatory in the server-first message per RFC 5802; its absence indicates a truncated or malformed message. The code reads attrPairs.get('r') and throws if it is falsy.","triggerScenarios":"The server's AuthenticationSASLContinue payload lacks the r=<nonce> attribute. This is parsed from the serverData string passed to continueSession.","commonSituations":"A non-compliant server sending an incomplete SCRAM first message. A proxy truncating the message. Wire-level corruption. Rare with genuine PostgreSQL.","solutions":["Verify the target is a genuine, unproxied PostgreSQL server.","Check for PgBouncer or other intermediaries that may alter SASL messages.","Enable SSL to ensure message integrity during authentication."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await client.connect();\n} catch (err) {\n  if (/nonce missing/i.test(err.message)) {\n    console.error('SCRAM first message missing nonce — non-compliant server or truncated message.');\n  }\n  throw err;\n}","preventionTips":["Connect to a genuine PostgreSQL server with a compliant SCRAM implementation.","Check intermediaries (PgBouncer, load balancers) for message truncation.","Enable SSL to protect the authentication exchange."],"tags":["sasl","protocol","validation","authentication"],"analyzedSha":"c5e8c9a57bff6d9160ec5dbd5c4f4c1e4c460711","analyzedAt":"2026-08-03T18:47:28.334Z","schemaVersion":2}