{"record":{"id":"91f8b3cb0cd8ee74","repo":"brianc/node-postgres","slug":"sasl-scram-server-first-message-salt-missing","errorCode":null,"errorMessage":"SASL: SCRAM-SERVER-FIRST-MESSAGE: salt missing","messagePattern":"SASL: SCRAM-SERVER-FIRST-MESSAGE: salt missing","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/pg/lib/crypto/sasl.js","lineNumber":203,"sourceCode":"      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 {\n    nonce,\n    salt,\n    iteration,\n  }\n}\n","sourceCodeStart":185,"sourceCodeEnd":221,"githubUrl":"https://github.com/brianc/node-postgres/blob/ff9d775abd12f29dd6df03945253b54eabbb29f2/packages/pg/lib/crypto/sasl.js#L185-L221","documentation":"Thrown by parseServerFirstMessage() when the server's first SASL message lacks the s= attribute (the salt). Per RFC 5802, the server must provide a base64-encoded salt for the PBKDF2 key derivation. Without it, the client cannot derive the salted password.","triggerScenarios":"At sasl.js:201-202, attrPairs.get('s') returns a falsy value (undefined). The parsed attribute Map has no 's' key — the server omitted the salt from its first message.","commonSituations":"Malformed or truncated server first message; connecting to a non-conformant server that doesn't fully implement SCRAM-SHA-256; a proxy corrupting or truncating the authentication exchange; network data loss.","solutions":["Verify the target is a standard PostgreSQL server (10+) with SCRAM-SHA-256 properly configured.","Remove any intermediary 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('salt missing')) {\n    throw new Error('SCRAM handshake failed: server sent no salt — 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"}