Skip to content

xmpp_stream_in: Offer SASL2 to a client stream that names no user - #121

Merged
prefiks merged 2 commits into
processone:masterfrom
annelinlol:feat/sasl2-anonymous
Nov 25, 2026
Merged

prefiks merged 2 commits into
processone:masterfrom
annelinlol:feat/sasl2-anonymous

Conversation

@annelinlol

@annelinlol annelinlol commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

SASL2 (XEP-0388) is offered only when the client's stream header names a user
in from, because the mechanisms are picked for that user's stored
credentials. A client that logs in anonymously has no user to name, so it can't
use SASL2 and can't bind inline with Bind2 (XEP-0386). It has to fall back to
RFC 6120 SASL and resource binding. Naming some made-up user doesn't help:
process_sasl2_success rejects any identity other than the named user, and the
anonymous identity is random.

XEP-0388 §3 (1.0.4) covers this case: "When the from attribute is absent, the
server SHOULD only offer mechanisms it can provide independently of the JID."

An earlier revision of this PR offered only ANONYMOUS there. That broke clients
that prefer SASL2 and don't send from (Gajim): they saw SASL2 with no password
mechanism and gave up instead of falling back to SASL. So such a stream now gets
in SASL2 the same mechanisms legacy SASL offers it, which is what the server
can provide without knowing the user in advance: legacy SASL does exactly that.

What changes, only for a client stream whose header names no user (no from,
or a from with no local part):

  • sasl2_stream_from is set to undefined rather than left unset, so SASL2
    can be offered.
  • The SASL2 mechanisms are those legacy SASL offers the same stream (the
    sasl_mechanisms callback, the same channel-binding and downgrade handling).
    The password is looked up through the get_password_fun callback for the
    user the mechanism names, as legacy SASL does.
  • FAST mechanisms (fast_mechanisms callback) are neither offered nor accepted
    on such a stream.
  • On success, the identity from the mechanism is used (any mechanism). There's no named user to
    compare it with. <success/> carries the <authorization-identifier/>,
    which is the full JID when Bind2 bound a resource, as on any SASL2 success.

Streams that name a user behave as before. One small side effect: if a
send_features call for SASL2 produces no <authentication/> (an already
authenticated stream), the stream's SASL2 marker is now dropped instead of
kept.

Tests: rebar3 dialyzer and rebar3 eunit pass. ejabberd's CT suite was run
against this branch through _checkouts (see the companion ejabberd PR). It
has new cases for anonymous SASL2 + Bind2 and for "no SASL2 when there's no
anonymous login".

The ejabberd side (hooks and tests) is processone/ejabberd#4671.

SASL2 was offered only when the stream header names a user in its
'from', since the mechanisms are picked for that user's stored
credentials. A client that logs in anonymously has no user to name, so
it could not use SASL2 nor bind inline with Bind2, and had to fall back
to SASL and resource binding.

XEP-0388 says that without 'from' the server SHOULD offer only the
mechanisms it can provide independently of the JID. Offer SASL2 to such
a stream with ANONYMOUS only, when the callback module lists it, and no
FAST mechanisms. As the user comes from the mechanism, there is no user
named in the header to compare it with. When ANONYMOUS isn't available
the stream gets no SASL2 feature, as before. Streams that name a user
are not changed.
…is named

A client stream whose header names no user was offered SASL2 with
ANONYMOUS alone, while SASL offered it the password mechanisms too. A
client that prefers SASL2, as Gajim does, then saw no mechanism for its
password and gave up, where before it fell back to SASL and logged in.

Offer such a stream the mechanisms of SASL, and look up the password of
the user the mechanism names, as SASL does, rather than that of a user
named in the header. Channel binding is as in SASL. FAST mechanisms
stay out, since FAST needs a user named in the header.
@prefiks

prefiks commented Nov 25, 2026

Copy link
Copy Markdown
Member

Look ok, i was sure when i was making initial implementation xep did mention that it should be only offered when client sent from attribute, i must have misread this, or that was latter addition.

After merge could you please update ejabberd pull counterpart making rebar.config/mix.exs pointint to xmpp commit that includes this?

@prefiks
prefiks merged commit 776973e into processone:master Nov 25, 2026
3 checks passed
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.

2 participants