#2019 authenticated stanza size limit is never applied to SASL-2 (XEP-0388) sessions — they keep `c2s_unauthed_stanza_size_limit` (10 KB) for their lifetime
Reporter
Feduka
Owner
Nobody
Created
Updated
Stars
★ (1)
Tags
Status-New
Type-Defect
Priority-Medium
Feduka
on
# Upstream report: authenticated stanza size limit is never applied to SASL-2 (XEP-0388) sessions — they keep `c2s_unauthed_stanza_size_limit` (10 KB) for their lifetime
**Ready to post at https://issues.prosody.im (New issue). Suggested title:**
> mod_c2s upgrades the stanza size limit only on `authentication-success`, which mod_sasl2 never fires — SASL-2 sessions keep the 10 KB pre-auth limit forever
---
## Environment
- Prosody **13.0.7** (Debian package `13.0.7-1~bookworm2`, PostgreSQL storage), `mod_sasl2` + `mod_sasl2_bind2` + `mod_sasl2_sm` + `mod_sasl2_fast` enabled.
- Code verified identical in the hg **13.0 branch** and **trunk tip** (checked 2026-11-23): `plugins/mod_c2s.lua` sets the pre-auth limit at session creation (13.0: line 367; trunk: line 370) and upgrades it only in the `authentication-success` hook (13.0: lines 484–491; trunk: 487 ff.). 13.0.7 is the latest stable release, so there is no upgrade path that avoids this.
## Root cause
`mod_c2s` initializes every session with the pre-auth limit:
```lua
-- mod_c2s.lua (13.0 branch, line 367)
session.stanza_size_limit = unauthed_stanza_size_limit; -- default 10 KB
```
and only raises it to `authed_stanza_size_limit` (default 256 KB) here:
```lua
-- mod_c2s.lua (13.0 branch, lines 484-491)
module:hook("authentication-success", function(event)
local session = event.session;
if session.stream then
session.stanza_size_limit = authed_stanza_size_limit;
session.stream:set_stanza_size_limit(session.stanza_size_limit);
end
end);
```
But the `authentication-success` event is fired **only** by the legacy SASL module (`mod_saslauth.lua:67`). `mod_sasl2` (XEP-0388) fires only `sasl2/c2s/success` and `sasl2/c2s/failure` and **never** `authentication-success` — our deployment already carries a small bridge module (`mod_sasl2_audit`) written precisely because of that gap, to feed SASL-2 outcomes into audit integrations that hook the legacy event.
Consequence: on any server with `mod_sasl2` enabled, **every modern client authenticates via XEP-0388, the upgrade never runs, and SASL-2 sessions keep the 10 KB pre-auth limit for their entire lifetime**. The stream features even advertise `<max-bytes>10000</max-bytes>` to those sessions, telling the client the truth.
## Impact
Any stanza larger than 10 KB sent by a SASL-2 client is rejected with a stream error and the connection is dropped:
```
<stream:error><policy-violation xmlns='urn:ietf:params:xml:ns:xmpp-streams'/>
<text xmlns='urn:ietf:params:xml:ns:xmpp-streams'>XML stanza is too big</text>
<stanza-too-big xmlns='urn:xmpp:errors'/></stream:error>
```
This silently breaks all client-to-server payloads over 10 KB, notably:
- **PEP publishes over 10 KB** — OMEMO2/OMEMO post-quantum device bundles (an ML-KEM bundle with more than ~3 one-time prekeys exceeds 10 KB), vCard4 with a photo, etc.;
- items published **before** SASL-2 was enabled keep serving from storage, which hides the breakage completely (clients fetch the stale item and never see an error until they try to republish).
Observed on our server: every SASL-2 client republishing an OMEMO2 bundle (~90–260 KB) was killed with `policy-violation` on every connect (`c2s stream for … closed: XML stanza is too big`, `Received invalid XML (stanza-too-large) …`), while legacy-SASL clients were unaffected.
## Reproduction
1. Enable `mod_sasl2` (bind2 optional).
2. Connect with any SASL-2 client and authenticate.
3. Send any stanza > 10 KB (e.g. a PEP publish) → stream is closed with `policy-violation` "XML stanza is too big".
Programmatic check: in `prosodyctl shell`, after a SASL-2 session authenticates, `session.stanza_size_limit` is `10000` instead of `262144`.
## Suggested fix (any one of these)
1. **In `mod_c2s`:** run the same upgrade on `sasl2/c2s/success` as well. This is what we run in production (works, verified):
```lua
-- mod_c2s_sasl2_limit.lua (custom module, loaded globally)
local limit = module:get_option_integer("c2s_stanza_size_limit", 1024*256, 10000);
module:hook("sasl2/c2s/success", function(event)
local session = event.session;
if not session then return; end
session.stanza_size_limit = limit;
if session.stream and session.stream.set_stanza_size_limit then
session.stream:set_stanza_size_limit(limit);
end
end, 500);
```
2. **In `mod_sasl2`:** fire `authentication-success` on success, matching the legacy path's semantics — this would also fix third-party modules that hook the legacy event for auditing/statistics.
3. Or upgrade the limit once on the post-authentication stream restart, which both auth paths share.
## Version details
- Reported against 13.0.7 (latest stable, released 2026-09); the relevant `mod_c2s` code in trunk tip on 2026-11-23 is unchanged (`hook("authentication-success", …)` remains the only upgrade path).
---
*Server-side evidence available on request (journald excerpts of the `stanza-too-large`/`policy-violation` closes, before/after logs with the workaround module showing `stanza size limit upgraded to 10485760 bytes after SASL2 auth` for every SASL-2 session).*
# Upstream report: authenticated stanza size limit is never applied to SASL-2 (XEP-0388) sessions — they keep `c2s_unauthed_stanza_size_limit` (10 KB) for their lifetime **Ready to post at https://issues.prosody.im (New issue). Suggested title:** > mod_c2s upgrades the stanza size limit only on `authentication-success`, which mod_sasl2 never fires — SASL-2 sessions keep the 10 KB pre-auth limit forever --- ## Environment - Prosody **13.0.7** (Debian package `13.0.7-1~bookworm2`, PostgreSQL storage), `mod_sasl2` + `mod_sasl2_bind2` + `mod_sasl2_sm` + `mod_sasl2_fast` enabled. - Code verified identical in the hg **13.0 branch** and **trunk tip** (checked 2026-11-23): `plugins/mod_c2s.lua` sets the pre-auth limit at session creation (13.0: line 367; trunk: line 370) and upgrades it only in the `authentication-success` hook (13.0: lines 484–491; trunk: 487 ff.). 13.0.7 is the latest stable release, so there is no upgrade path that avoids this. ## Root cause `mod_c2s` initializes every session with the pre-auth limit: ```lua -- mod_c2s.lua (13.0 branch, line 367) session.stanza_size_limit = unauthed_stanza_size_limit; -- default 10 KB ``` and only raises it to `authed_stanza_size_limit` (default 256 KB) here: ```lua -- mod_c2s.lua (13.0 branch, lines 484-491) module:hook("authentication-success", function(event) local session = event.session; if session.stream then session.stanza_size_limit = authed_stanza_size_limit; session.stream:set_stanza_size_limit(session.stanza_size_limit); end end); ``` But the `authentication-success` event is fired **only** by the legacy SASL module (`mod_saslauth.lua:67`). `mod_sasl2` (XEP-0388) fires only `sasl2/c2s/success` and `sasl2/c2s/failure` and **never** `authentication-success` — our deployment already carries a small bridge module (`mod_sasl2_audit`) written precisely because of that gap, to feed SASL-2 outcomes into audit integrations that hook the legacy event. Consequence: on any server with `mod_sasl2` enabled, **every modern client authenticates via XEP-0388, the upgrade never runs, and SASL-2 sessions keep the 10 KB pre-auth limit for their entire lifetime**. The stream features even advertise `<max-bytes>10000</max-bytes>` to those sessions, telling the client the truth. ## Impact Any stanza larger than 10 KB sent by a SASL-2 client is rejected with a stream error and the connection is dropped: ``` <stream:error><policy-violation xmlns='urn:ietf:params:xml:ns:xmpp-streams'/> <text xmlns='urn:ietf:params:xml:ns:xmpp-streams'>XML stanza is too big</text> <stanza-too-big xmlns='urn:xmpp:errors'/></stream:error> ``` This silently breaks all client-to-server payloads over 10 KB, notably: - **PEP publishes over 10 KB** — OMEMO2/OMEMO post-quantum device bundles (an ML-KEM bundle with more than ~3 one-time prekeys exceeds 10 KB), vCard4 with a photo, etc.; - items published **before** SASL-2 was enabled keep serving from storage, which hides the breakage completely (clients fetch the stale item and never see an error until they try to republish). Observed on our server: every SASL-2 client republishing an OMEMO2 bundle (~90–260 KB) was killed with `policy-violation` on every connect (`c2s stream for … closed: XML stanza is too big`, `Received invalid XML (stanza-too-large) …`), while legacy-SASL clients were unaffected. ## Reproduction 1. Enable `mod_sasl2` (bind2 optional). 2. Connect with any SASL-2 client and authenticate. 3. Send any stanza > 10 KB (e.g. a PEP publish) → stream is closed with `policy-violation` "XML stanza is too big". Programmatic check: in `prosodyctl shell`, after a SASL-2 session authenticates, `session.stanza_size_limit` is `10000` instead of `262144`. ## Suggested fix (any one of these) 1. **In `mod_c2s`:** run the same upgrade on `sasl2/c2s/success` as well. This is what we run in production (works, verified): ```lua -- mod_c2s_sasl2_limit.lua (custom module, loaded globally) local limit = module:get_option_integer("c2s_stanza_size_limit", 1024*256, 10000); module:hook("sasl2/c2s/success", function(event) local session = event.session; if not session then return; end session.stanza_size_limit = limit; if session.stream and session.stream.set_stanza_size_limit then session.stream:set_stanza_size_limit(limit); end end, 500); ``` 2. **In `mod_sasl2`:** fire `authentication-success` on success, matching the legacy path's semantics — this would also fix third-party modules that hook the legacy event for auditing/statistics. 3. Or upgrade the limit once on the post-authentication stream restart, which both auth paths share. ## Version details - Reported against 13.0.7 (latest stable, released 2026-09); the relevant `mod_c2s` code in trunk tip on 2026-11-23 is unchanged (`hook("authentication-success", …)` remains the only upgrade path). --- *Server-side evidence available on request (journald excerpts of the `stanza-too-large`/`policy-violation` closes, before/after logs with the workaround module showing `stanza size limit upgraded to 10485760 bytes after SASL2 auth` for every SASL-2 session).*