Skip to content

Add anonymous_username option for SASL ANONYMOUS usernames - #120

Open
annelinlol wants to merge 1 commit into
processone:masterfrom
annelinlol:feat/anonymous-username
Open

annelinlol wants to merge 1 commit into
processone:masterfrom
annelinlol:feat/anonymous-username

Conversation

@annelinlol

@annelinlol annelinlol commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

SASL ANONYMOUS currently assigns a username made of a random number followed by a unique integer (digits only). Such a name can't be told apart from a registered account with a numeric username, so an ACL can only match anonymous users by the shape of the digits, and a registered account with a long enough number can look like one.

This adds an optional setting, passed through xmpp:set_config/1 like fqdn:

xmpp:set_config([{anonymous_username, {<<"guest-">>, 16}}]).

With it set, xmpp_sasl_anonymous assigns Prefix followed by Hex random lowercase hex characters (from crypto:strong_rand_bytes/1), for example guest-7fa598d93c1e04b2.

  • xmpp_config:anonymous_username/1 returns the setting, xmpp:get_config/0 reports it.
  • Invalid values (non-binary prefix, non-positive length) raise badarg, like the other options.
  • Unit tests in xmpp_sasl_anonymous (run by rebar3 eunit).

Compatibility: the default is undefined, which keeps the current username format unchanged. Since get_config/0 includes the key, a caller can check whether the library supports the option before setting it.

The ejabberd side (a top-level anonymous_username option) is in processone/ejabberd#4670.

The username assigned by SASL ANONYMOUS is a random number followed by a
unique integer, so it can't be told apart from a registered account
with a numeric name. The new option, set with xmpp:set_config/1:

  {anonymous_username, {Prefix, Hex}}

makes the username Prefix followed by Hex random lowercase hex
characters (crypto:strong_rand_bytes/1), for example
guest-7fa598d93c1e04b2 for {<<"guest-">>, 16}. The default, undefined,
keeps the current format. xmpp:get_config/0 reports the option, so
callers can tell whether the library supports it.
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