Skip to content

Abort SCRAM and report why when the client fails it - #895

Open
jcbrand wants to merge 2 commits into
masterfrom
scram-abort
Open

jcbrand wants to merge 2 commits into
masterfrom
scram-abort

Conversation

@jcbrand

@jcbrand jcbrand commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

When Strophe fails SCRAM on its own side, it reported Status.AUTHFAIL with elem = null and no condition, so a client couldn't tell why, or tell it apart from a rejection by the server.

Changes

  • New conditions in ErrorCondition: SCRAM_BAD_CHALLENGE (malformed or insecure challenge, e.g. fewer than 4096 iterations), SCRAM_BAD_NONCE, SCRAM_STALE_KEYS (stored { name, salt, iter, ck, sk } keys that no longer match the challenge) and SCRAM_BAD_SERVER_SIGNATURE.
  • On a bad challenge, bad nonce or stale keys, Strophe sends <abort/> (RFC 6120 § 6.4.4) instead of an empty <response/>, through a new _sasl_abort(condition).
  • _sasl_failure_cb() now also removes the failure handler, so each exchange is reported once.
  • A bad server signature in <success> is reported with its condition. A <success> without v= no longer throws, and counts as a bad signature.
  • If a custom mechanism's onChallenge() returns false without ending the exchange itself, Strophe aborts with UNKNOWN_REASON rather than sending an empty response.

The double AUTHFAIL

Verified against the old code: after a bad nonce it sent an empty <response/> and kept the failure handler, so the server's <failure><malformed-request/></failure> (RFC 6120 § 6.4.5) was reported as a second AUTHFAIL.

Why report immediately

The failure is reported as soon as the client aborts, with the condition and no element, and the server's <failure><aborted/></failure> is then ignored. Waiting for the server's reply instead would make the report depend on a server that has just sent a bad nonce or challenge, which may never answer, and its generic <aborted/> would replace the condition that says what went wrong.

This is additive, so it's meant for 6.1.0.

@jcbrand
jcbrand force-pushed the scram-abort branch 2 times, most recently from dbba2bc to cfdc95e Compare November 17, 2026 06:19
@jcbrand
jcbrand marked this pull request as ready for review November 17, 2026 06:20
When the client fails a SCRAM exchange, it sends <abort/> (RFC 6120
6.4.4) and reports a single AUTHFAIL with one of the new conditions
SCRAM_BAD_CHALLENGE, SCRAM_BAD_NONCE, SCRAM_STALE_KEYS or
SCRAM_BAD_SERVER_SIGNATURE, and a null element.

- A SCRAM <success> must carry the server signature computed for this
  exchange. A missing, malformed or wrong one (including <success>
  before any challenge was answered) fails auth and disconnects, since
  the server considers the stream authenticated.
- Mechanisms throw SASLError to fail; _sasl_challenge_cb is the only
  place that aborts. Any other throw from onChallenge() (e.g. invalid
  base64) aborts with UNKNOWN_REASON instead of hanging.
- An answer that arrives after its exchange ended is dropped, so it
  can't reach the server or abort a newer exchange.
- The server nonce must extend the client nonce with its own part.
- SASL data is reset at the start of each exchange and on failure.
The connection decided whether to check a SCRAM server signature by looking
for a client nonce in `_sasl_data`. Any other mechanism that kept a `cnonce`
there had every `<success>` rejected as SCRAM_BAD_SERVER_SIGNATURE.

Add `SASLMechanism.verifySuccess(connection, elem)`, which returns `true` by
default. A mechanism rejects the success by returning `false` (reported as
UNKNOWN_REASON) or by throwing a `SASLError` with the condition to report,
like `onChallenge()`. The SCRAM mechanisms now check the server signature
there, and the connection no longer knows about SCRAM.

Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant