Version in base suite: 13.0.1-1+deb131u Base version: prosody_13.0.1-1+deb131u Target version: prosody_13.0.1-1+deb131u2 Base file: /srv/ftp-master.debian.org/ftp/pool/main/p/prosody/prosody_13.0.1-1+deb131u.dsc Target file: /srv/ftp-master.debian.org/policy/pool/main/p/prosody/prosody_13.0.1-1+deb131u2.dsc changelog | 6 patches/0015-util.datamanager-Don-t-leave-hole-in-array-after-rem.patch | 29 patches/0016-mod_auth_ldap-Always-fail-empty-passwords.patch | 34 patches/0017-mod_legacyauth-Run-password-through-saslprep-and-rej.patch | 33 patches/0018-mod_invites-mod_invites_register-Prevent-reuse-of-va.patch | 85 + patches/0019-stanza_router-Ensure-stanza-events-are-always-fired-.patch | 45 patches/0020-MUC-Use-correct-actor-when-kicking-on-reserved-nick-.patch | 102 + patches/0021-MUC-Reject-mediated-invites-from-unaffiliated-non-oc.patch | 181 +++ patches/0022-MUC-Forbid-unaffiliated-non-occupant-MAM-queries-by-.patch | 227 ++++ patches/0023-util.stanza-Add-support-for-parsing-xs-boolean-and-x.patch | 117 ++ patches/0024-util.rsm-Strictly-validate-integers.patch | 122 ++ patches/0025-mod_mam-Return-error-on-invalid-RSM-fields.patch | 25 patches/0026-mod_muc_mam-Return-error-on-invalid-RSM-fields.patch | 25 patches/0027-mod_storage_sql-Reject-invalid-RSM-limit.patch | 56 + patches/0028-mod_storage_memory-Reject-invalid-RSM-limit.patch | 23 patches/0029-net.http.parser-Fix-handling-of-chunked-request.patch | 64 + patches/0030-mod_http_file_share-Enforce-valid-content-type-in-sl.patch | 31 patches/0031-mod_dialback-Reject-dialback-requests-for-hosts-with.patch | 23 patches/0032-stanza_router-reject-stanzas-to-hosts-with-mod_s2s-d.patch | 24 patches/0033-net.http.parser-Error-on-sink-write-failure.patch | 74 + patches/0034-mod_http_file_share-Limit-data-written-to-sink-based.patch | 47 patches/0035-mod_tokenauth-Apply-role-if-any-from-OAuth-token-to-.patch | 29 patches/0036-mod_invites_register-Stricter-validation-of-registra.patch | 47 patches/0037-mod_invites_register-Don-t-restrict-username-for-ros.patch | 24 patches/0038-mod_invites-mod_invites_register-Use-new-allowed_use.patch | 79 + patches/0039-net.http.server-Ensure-finish_cb-is-always-called-on.patch | 57 + patches/0040-util.xmppstream-Initialize-SAX-handlers-with-max_ele.patch | 24 patches/0041-util.xmppstream-Preserve-max_elements-if-not-explici.patch | 26 patches/0042-util.xmppstream-More-robust-processing-of-stream-abo.patch | 87 + patches/0043-util.xmppstream-Add-tests-for-limits-behaviour.patch | 106 + patches/0044-util.xmppstream-More-accurate-byte-accounting-for-st.patch | 344 ++++++ patches/0045-net.http.parser-Avoid-responding-twice-to-some-HTTP-.patch | 37 patches/0046-net.http-Normalize-URI-scheme-fixes-2018.patch | 52 patches/0047-mod_bosh-Apply-c2s_max_child_elements-to-BOSH-stream.patch | 31 patches/0048-mod_component-Apply-component-s2s-_max_child_element.patch | 38 patches/0049-mod_pep-Don-t-send-notifications-to-contacts-that-no.patch | 550 ++++++++++ patches/0050-util.xmppstream-Discard-data-and-callbacks-after-a-s.patch | 129 ++ patches/0051-MUC-Don-t-relay-arbitrary-child-elements-in-mediated.patch | 171 +++ patches/0052-mod_component-Fix-overly-long-line-luacheck.patch | 23 patches/0053-mod_register_ibr-Fire-event-on-registration-failure.patch | 66 + patches/0054-mod_register_ibr-Include-validated_invite-in-user-re.patch | 27 patches/0055-mod_invites-mod_invites_register-Restrict-concurrent.patch | 158 ++ patches/series | 41 43 files changed, 3519 insertions(+) dpkg-source: warning: cannot verify inline signature for /srv/release.debian.org/tmp/tmp0hso_peo/prosody_13.0.1-1+deb131u.dsc: no acceptable signature found dpkg-source: warning: cannot verify inline signature for /srv/release.debian.org/tmp/tmp0hso_peo/prosody_13.0.1-1+deb131u2.dsc: no acceptable signature found diff -Nru prosody-13.0.1/debian/changelog prosody-13.0.1/debian/changelog --- prosody-13.0.1/debian/changelog 2026-05-05 07:37:27.000000000 +0000 +++ prosody-13.0.1/debian/changelog 2026-12-01 12:43:09.000000000 +0000 @@ -1,3 +1,9 @@ +prosody (13.0.1-1+deb131u2) trixie-security; urgency=medium + + * patches from upstream related to https://prosody.im/security/advisory_2026_8112eaa9/ + + -- Victor Seva Tue, 01 Dec 2026 13:43:09 +0100 + prosody (13.0.1-1+deb131u) trixie-security; urgency=medium * CVE-2026-43504 fix diff -Nru prosody-13.0.1/debian/patches/0015-util.datamanager-Don-t-leave-hole-in-array-after-rem.patch prosody-13.0.1/debian/patches/0015-util.datamanager-Don-t-leave-hole-in-array-after-rem.patch --- prosody-13.0.1/debian/patches/0015-util.datamanager-Don-t-leave-hole-in-array-after-rem.patch 1970-01-01 00:00:00.000000000 +0000 +++ prosody-13.0.1/debian/patches/0015-util.datamanager-Don-t-leave-hole-in-array-after-rem.patch 2026-12-01 12:43:09.000000000 +0000 @@ -0,0 +1,29 @@ +From: Matthew Wild +Date: Mon, 9 Nov 2026 15:57:07 +0000 +Subject: util.datamanager: Don't leave hole in array after removing callback + +--- + util/datamanager.lua | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/util/datamanager.lua b/util/datamanager.lua +index 8192d12..18406bf 100644 +--- a/util/datamanager.lua ++++ b/util/datamanager.lua +@@ -23,6 +23,7 @@ local next = next; + local type = type; + local t_insert = table.insert; + local t_concat = table.concat; ++local t_remove = table.remove; + local envloadfile = require"prosody.util.envload".envloadfile; + local envload = require"prosody.util.envload".envload; + local serialize = require "prosody.util.serialization".serialize; +@@ -121,7 +122,7 @@ local function remove_callback(func) + if callbacks[func] then + for i, f in ipairs(callbacks) do + if f == func then +- callbacks[i] = nil; ++ t_remove(callbacks, i); + callbacks[f] = nil; + return true; + end diff -Nru prosody-13.0.1/debian/patches/0016-mod_auth_ldap-Always-fail-empty-passwords.patch prosody-13.0.1/debian/patches/0016-mod_auth_ldap-Always-fail-empty-passwords.patch --- prosody-13.0.1/debian/patches/0016-mod_auth_ldap-Always-fail-empty-passwords.patch 1970-01-01 00:00:00.000000000 +0000 +++ prosody-13.0.1/debian/patches/0016-mod_auth_ldap-Always-fail-empty-passwords.patch 2026-12-01 12:43:09.000000000 +0000 @@ -0,0 +1,34 @@ +From: Matthew Wild +Date: Tue, 10 Nov 2026 15:06:02 +0000 +Subject: mod_auth_ldap: Always fail empty passwords + +Some LDAP servers (e.g. Active Directory) may accept empty passwords, and in +bind mode this might lead to Prosody incorrectly permitting an authentication. + +Empty passwords are forbidden by SASL PLAIN, which is most commonly used in +LDAP deployments, however servers with mod_legacyauth enabled may be +vulnerable as it forwards empty passwords to mod_auth_ldap. + +mod_auth_ldap will now reject all empty passwords without consulting the +directory. + +We believe the only affected configurations to be those with Active Directory +(and possibly Samba AD/DC) *and* mod_legacyauth enabled (it is not enabled in +the default configuration). +--- + plugins/mod_auth_ldap.lua | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/plugins/mod_auth_ldap.lua b/plugins/mod_auth_ldap.lua +index 569cef6..f92cda9 100644 +--- a/plugins/mod_auth_ldap.lua ++++ b/plugins/mod_auth_ldap.lua +@@ -101,7 +101,7 @@ if ldap_mode == "getpasswd" then + end + + function provider.test_password(username, password) +- return provider.get_password(username) == password; ++ return password ~= "" and provider.get_password(username) == password; + end + + function provider.get_sasl_handler() diff -Nru prosody-13.0.1/debian/patches/0017-mod_legacyauth-Run-password-through-saslprep-and-rej.patch prosody-13.0.1/debian/patches/0017-mod_legacyauth-Run-password-through-saslprep-and-rej.patch --- prosody-13.0.1/debian/patches/0017-mod_legacyauth-Run-password-through-saslprep-and-rej.patch 1970-01-01 00:00:00.000000000 +0000 +++ prosody-13.0.1/debian/patches/0017-mod_legacyauth-Run-password-through-saslprep-and-rej.patch 2026-12-01 12:43:09.000000000 +0000 @@ -0,0 +1,33 @@ +From: Matthew Wild +Date: Tue, 10 Nov 2026 15:10:02 +0000 +Subject: mod_legacyauth: Run password through saslprep and reject + empty/invalid passwords + +--- + plugins/mod_legacyauth.lua | 6 ++++++ + 1 file changed, 6 insertions(+) + +diff --git a/plugins/mod_legacyauth.lua b/plugins/mod_legacyauth.lua +index 048cd3e..932a0ac 100644 +--- a/plugins/mod_legacyauth.lua ++++ b/plugins/mod_legacyauth.lua +@@ -8,6 +8,7 @@ + + + ++local saslprep = require "prosody.encodings".stringprep.saslprep; + local st = require "prosody.util.stanza"; + local t_concat = table.concat; + +@@ -63,6 +64,11 @@ module:hook("stanza/iq/jabber:iq:auth:query", function(event) + session.send(st.error_reply(stanza, "modify", "bad-request")); + return true; + end ++ password = saslprep(password); ++ if not password or password == "" then ++ session.send(st.error_reply(stanza, "modify", "bad-request", "No valid password supplied")); ++ return true; ++ end + if usermanager.test_password(username, session.host, password) then + -- Authentication successful! + local success, err = sessionmanager.make_authenticated(session, username); diff -Nru prosody-13.0.1/debian/patches/0018-mod_invites-mod_invites_register-Prevent-reuse-of-va.patch prosody-13.0.1/debian/patches/0018-mod_invites-mod_invites_register-Prevent-reuse-of-va.patch --- prosody-13.0.1/debian/patches/0018-mod_invites-mod_invites_register-Prevent-reuse-of-va.patch 1970-01-01 00:00:00.000000000 +0000 +++ prosody-13.0.1/debian/patches/0018-mod_invites-mod_invites_register-Prevent-reuse-of-va.patch 2026-12-01 12:43:09.000000000 +0000 @@ -0,0 +1,85 @@ +From: Matthew Wild +Date: Tue, 10 Nov 2026 15:24:29 +0000 +Subject: mod_invites, + mod_invites_register: Prevent reuse of valid invitations by the same session + +A validated invite is cached on the current session, and it was not cleared +after use, effectively allowing one single-use invitation to be used repeatedly +as long as the client did not disconnect. + +We now set a flag when the in-memory invitation has been used once, unless it +is legitimately a reusable invitation. +--- + plugins/mod_invites.lua | 4 ++++ + plugins/mod_invites_register.lua | 15 ++++++++++++--- + 2 files changed, 16 insertions(+), 3 deletions(-) + +diff --git a/plugins/mod_invites.lua b/plugins/mod_invites.lua +index c6a66a8..863558c 100644 +--- a/plugins/mod_invites.lua ++++ b/plugins/mod_invites.lua +@@ -146,6 +146,8 @@ local valid_invite_mt = { __index = valid_invite_methods }; + function valid_invite_methods:use() + if self.reusable then + return true; ++ elseif self.used then ++ return false; + end + + if self.username then +@@ -155,6 +157,8 @@ function valid_invite_methods:use() + end + token_storage:set(nil, self.token, nil); + ++ self.used = true; ++ + return true; + end + +diff --git a/plugins/mod_invites_register.lua b/plugins/mod_invites_register.lua +index d9274ce..b51d2f3 100644 +--- a/plugins/mod_invites_register.lua ++++ b/plugins/mod_invites_register.lua +@@ -16,6 +16,15 @@ if prosody.process_type == "prosody" then + end + end + ++ ++local function get_validated_invite(event) ++ local validated_invite = event.validated_invite or (event.session and event.session.validated_invite); ++ if not validated_invite or validated_invite.used then ++ return nil; ++ end ++ return validated_invite; ++end ++ + local legacy_invite_stream_feature = st.stanza("register", { xmlns = "urn:xmpp:invite" }):up(); + local invite_stream_feature = st.stanza("register", { xmlns = "urn:xmpp:ibr-token:0" }):up(); + module:hook("stream-features", function(event) +@@ -90,7 +99,7 @@ end); + + -- Registration attempt - ensure a valid preauth token has been supplied + module:hook("user-registering", function (event) +- local validated_invite = event.validated_invite or (event.session and event.session.validated_invite); ++ local validated_invite = get_validated_invite(event); + if invite_only and not validated_invite then + event.allowed = false; + event.reason = "Registration on this server is through invitation only"; +@@ -130,7 +139,7 @@ end + + -- Registration successful, if there was a preauth token, mark it as used + module:hook("user-registered", function (event) +- local validated_invite = event.validated_invite or (event.session and event.session.validated_invite); ++ local validated_invite = get_validated_invite(event); + if not validated_invite then + return; + end +@@ -169,7 +178,7 @@ end); + -- Equivalent of user-registered but for when the account already existed + -- (i.e. password reset) + module:hook("user-password-reset", function (event) +- local validated_invite = event.validated_invite or (event.session and event.session.validated_invite); ++ local validated_invite = get_validated_invite(event); + if not validated_invite then + return; + end diff -Nru prosody-13.0.1/debian/patches/0019-stanza_router-Ensure-stanza-events-are-always-fired-.patch prosody-13.0.1/debian/patches/0019-stanza_router-Ensure-stanza-events-are-always-fired-.patch --- prosody-13.0.1/debian/patches/0019-stanza_router-Ensure-stanza-events-are-always-fired-.patch 1970-01-01 00:00:00.000000000 +0000 +++ prosody-13.0.1/debian/patches/0019-stanza_router-Ensure-stanza-events-are-always-fired-.patch 2026-12-01 12:43:09.000000000 +0000 @@ -0,0 +1,45 @@ +From: Matthew Wild +Date: Tue, 10 Nov 2026 16:16:49 +0000 +Subject: stanza_router: Ensure stanza events are always fired on the correct + host + +For unauthenticated sessions or elements not in the default stream namespace, +we preferred to dispatch on the host specified in the 'to' attribute (if any). +This is incorrect, as such stanzas/elements should only be handled by the +session's own host. + +s2s dialback elements are now the only exception that permits dispatching by +arbitrary 'to' attributes. It would be good to refactor this away in a future +update. +--- + core/stanza_router.lua | 17 ++++++++++++++++- + 1 file changed, 16 insertions(+), 1 deletion(-) + +diff --git a/core/stanza_router.lua b/core/stanza_router.lua +index 197c5f6..87b3ed2 100644 +--- a/core/stanza_router.lua ++++ b/core/stanza_router.lua +@@ -127,7 +127,22 @@ function core_process_stanza(origin, stanza) + end + core_post_stanza(origin, stanza, origin.full_jid); + else +- local h = hosts[stanza.attr.to or origin.host]; ++ -- Non-stanza elements or stanzas from unauthed sessions ++ local h; ++ if xmlns == "jabber:server:dialback" and ( ++ origin.type == "s2sin" or origin.type == "s2sout" or origin.type == "s2sin_unauthed" or origin.type == "s2sout_unauthed" ++ ) then ++ -- TODO: Refactor mod_dialback so we don't need this special exception ++ h = hosts[stanza.attr.to or origin.host]; ++ else ++ local to_host = stanza.attr.to; ++ if to_host == nil or to_host == origin.host then ++ h = hosts[origin.host]; ++ else ++ log("debug", "Not dispatching %s addressed to %s from %s session on %s", ++ stanza.name, to_host, origin.type, origin.host); ++ end ++ end + if h then + local event; + if xmlns == nil then diff -Nru prosody-13.0.1/debian/patches/0020-MUC-Use-correct-actor-when-kicking-on-reserved-nick-.patch prosody-13.0.1/debian/patches/0020-MUC-Use-correct-actor-when-kicking-on-reserved-nick-.patch --- prosody-13.0.1/debian/patches/0020-MUC-Use-correct-actor-when-kicking-on-reserved-nick-.patch 1970-01-01 00:00:00.000000000 +0000 +++ prosody-13.0.1/debian/patches/0020-MUC-Use-correct-actor-when-kicking-on-reserved-nick-.patch 2026-12-01 12:43:09.000000000 +0000 @@ -0,0 +1,102 @@ +From: Matthew Wild +Date: Wed, 11 Nov 2026 17:32:11 +0000 +Subject: MUC: Use correct actor when kicking on reserved nick conflict + +This also preserves registration data when the kick or affiliation change +fails. + +Some tests needed to be updated because the actor is now passed through to +stanzas. +--- + plugins/muc/muc.lib.lua | 28 ++++++++++++++++++++++------ + spec/scansion/muc_register.scs | 2 ++ + spec/scansion/muc_show_offline.scs | 2 ++ + 3 files changed, 26 insertions(+), 6 deletions(-) + +diff --git a/plugins/muc/muc.lib.lua b/plugins/muc/muc.lib.lua +index 359afc8..3a9e66b 100644 +--- a/plugins/muc/muc.lib.lua ++++ b/plugins/muc/muc.lib.lua +@@ -1077,20 +1077,36 @@ function room_mt:handle_admin_query_set_command(origin, stanza) + local reason = item:get_child_text("reason"); + local success, errtype, err + if item.attr.affiliation and item.attr.jid and not item.attr.role then +- local registration_data = self:get_affiliation_data(item.attr.jid) or {}; +- if reason then +- registration_data.reason = reason; +- end ++ local reserved_nickname; + if item.attr.nick then + local room_nick = self.jid.."/"..item.attr.nick; + local existing_occupant = self:get_occupant_by_nick(room_nick); + if existing_occupant and existing_occupant.bare_jid ~= item.attr.jid then + module:log("debug", "Existing occupant for %s: %s does not match %s", room_nick, existing_occupant.bare_jid, item.attr.jid); +- self:set_role(true, room_nick, nil, "This nickname is reserved"); ++ success, errtype, err = self:set_role(actor, room_nick, nil, "This nickname is reserved"); ++ if not success then ++ origin.send(st.error_reply(stanza, errtype, err, "Nickname conflict")); ++ return true; ++ end + end + module:log("debug", "Reserving %s for %s (%s)", item.attr.nick, item.attr.jid, item.attr.affiliation); +- registration_data.reserved_nickname = item.attr.nick; ++ reserved_nickname = item.attr.nick; + end ++ ++ local registration_data = {}; ++ local existing_registration = self:get_affiliation_data(item.attr.jid); ++ if existing_registration then ++ for k, v in pairs(existing_registration) do ++ registration_data[k] = v; ++ end ++ end ++ if reason then ++ registration_data.reason = reason; ++ end ++ if reserved_nickname then ++ registration_data.reserved_nickname = reserved_nickname; ++ end ++ + success, errtype, err = self:set_affiliation(actor, item.attr.jid, item.attr.affiliation, reason, registration_data); + elseif item.attr.role and item.attr.nick and not item.attr.affiliation then + success, errtype, err = self:set_role(actor, self.jid.."/"..item.attr.nick, item.attr.role, reason); +diff --git a/spec/scansion/muc_register.scs b/spec/scansion/muc_register.scs +index 915a732..c83c526 100644 +--- a/spec/scansion/muc_register.scs ++++ b/spec/scansion/muc_register.scs +@@ -248,6 +248,7 @@ Romeo receives: + + + ++ + This nickname is reserved + + +@@ -270,6 +271,7 @@ Rosaline receives: + + + ++ + This nickname is reserved + + +diff --git a/spec/scansion/muc_show_offline.scs b/spec/scansion/muc_show_offline.scs +index c06a892..92ef7d5 100644 +--- a/spec/scansion/muc_show_offline.scs ++++ b/spec/scansion/muc_show_offline.scs +@@ -253,6 +253,7 @@ Romeo receives: + + + ++ + This nickname is reserved + + +@@ -275,6 +276,7 @@ Rosaline receives: + + + ++ + This nickname is reserved + + diff -Nru prosody-13.0.1/debian/patches/0021-MUC-Reject-mediated-invites-from-unaffiliated-non-oc.patch prosody-13.0.1/debian/patches/0021-MUC-Reject-mediated-invites-from-unaffiliated-non-oc.patch --- prosody-13.0.1/debian/patches/0021-MUC-Reject-mediated-invites-from-unaffiliated-non-oc.patch 1970-01-01 00:00:00.000000000 +0000 +++ prosody-13.0.1/debian/patches/0021-MUC-Reject-mediated-invites-from-unaffiliated-non-oc.patch 2026-12-01 12:43:09.000000000 +0000 @@ -0,0 +1,181 @@ +From: Matthew Wild +Date: Thu, 12 Nov 2026 11:47:48 +0000 +Subject: MUC: Reject mediated invites from unaffiliated non-occupants + +--- + plugins/muc/muc.lib.lua | 18 +++- + spec/scansion/muc_invite_non_occupant.scs | 132 ++++++++++++++++++++++++++++++ + 2 files changed, 148 insertions(+), 2 deletions(-) + create mode 100644 spec/scansion/muc_invite_non_occupant.scs + +diff --git a/plugins/muc/muc.lib.lua b/plugins/muc/muc.lib.lua +index 3a9e66b..4c438ed 100644 +--- a/plugins/muc/muc.lib.lua ++++ b/plugins/muc/muc.lib.lua +@@ -1258,12 +1258,26 @@ function room_mt:handle_presence_to_room(origin, stanza) + return handled; + end + +--- Need visitor role or higher to invite ++-- Need to be an occupant or affiliated with the room, and ++-- have (or be entitled to) a role above visitor to invite + module:hook("muc-pre-invite", function(event) + local room, stanza = event.room, event.stanza; + local _from = stanza.attr.from; + local inviter = room:get_occupant_by_real_jid(_from); +- local role = inviter and inviter.role or room:get_default_role(room:get_affiliation(_from)); ++ local role; ++ if inviter then ++ role = inviter.role; ++ else -- Not in room ++ local affiliation = room:get_affiliation(_from); ++ if not affiliation then ++ -- Unaffiliated JIDs that have not joined have no business with the ++ -- room: they may not know its password, and must not be able to ++ -- relay messages through it ++ event.origin.send(st.error_reply(stanza, "cancel", "not-acceptable", "You are not currently connected to this chat", room.jid)); ++ return true; ++ end ++ role = room:get_default_role(affiliation); ++ end + if valid_roles[role or "none"] <= valid_roles.visitor then + event.origin.send(st.error_reply(stanza, "auth", "forbidden")); + return true; +diff --git a/spec/scansion/muc_invite_non_occupant.scs b/spec/scansion/muc_invite_non_occupant.scs +new file mode 100644 +index 0000000..1e864d6 +--- /dev/null ++++ b/spec/scansion/muc_invite_non_occupant.scs +@@ -0,0 +1,132 @@ ++# MUC: Mediated invites from unaffiliated non-occupants are rejected ++ ++[Client] Romeo ++ jid: user@localhost ++ password: password ++ ++[Client] Juliet ++ jid: user2@localhost/balcony ++ password: password ++ ++----- ++ ++Romeo connects ++ ++Romeo sends: ++ ++ ++ ++ ++Romeo receives: ++ ++ ++ ++ ++ ++ ++ ++ ++Romeo receives: ++ ++ ++# Submit config form, setting a password ++Romeo sends: ++ ++ ++ ++ ++ http://jabber.org/protocol/muc#roomconfig ++ ++ ++ cauldronburn ++ ++ ++ ++ ++ ++Romeo receives: ++ ++ ++ ++Juliet connects ++ ++Juliet sends: ++ ++ ++Juliet receives: ++ ++ ++# Juliet has not joined and has no affiliation, but asks the room to invite her ++ ++Juliet sends: ++ ++ ++ ++ ++ ++ ++Juliet receives: ++ ++ ++ ++ ++ ++ ++# Romeo, an occupant, can still invite Juliet, and the invite carries the password ++ ++Romeo sends: ++ ++ ++ ++ ++ ++ ++Juliet receives: ++ ++ ++ ++ ++ ++ cauldronburn ++ ++ room@conference.localhost/Romeo invited you to the room room@conference.localhost ++ ++ ++ ++# Romeo makes Juliet a member; she can then request an invite without joining ++ ++Romeo sends: ++ ++ ++ ++ ++ ++ ++Romeo receives: ++ ++ ++ ++ ++ ++ ++Romeo receives: ++ ++ ++Juliet sends: ++ ++ ++ ++ ++ ++ ++Juliet receives: ++ ++ ++ ++ ++ ++ cauldronburn ++ ++ user2@localhost/balcony invited you to the room room@conference.localhost ++ ++ diff -Nru prosody-13.0.1/debian/patches/0022-MUC-Forbid-unaffiliated-non-occupant-MAM-queries-by-.patch prosody-13.0.1/debian/patches/0022-MUC-Forbid-unaffiliated-non-occupant-MAM-queries-by-.patch --- prosody-13.0.1/debian/patches/0022-MUC-Forbid-unaffiliated-non-occupant-MAM-queries-by-.patch 1970-01-01 00:00:00.000000000 +0000 +++ prosody-13.0.1/debian/patches/0022-MUC-Forbid-unaffiliated-non-occupant-MAM-queries-by-.patch 2026-12-01 12:43:09.000000000 +0000 @@ -0,0 +1,227 @@ +From: Matthew Wild +Date: Thu, 12 Nov 2026 15:02:02 +0000 +Subject: MUC: Forbid unaffiliated non-occupant MAM queries by default + +The new option muc_mam_allow_unjoined_queries can be set to `true` to restore +the old behaviour, except for password-protected rooms which always disallow +unjoined queries. +--- + plugins/mod_muc_mam.lua | 12 +++ + spec/scansion/muc_mam_unjoined.scs | 178 +++++++++++++++++++++++++++++++++++++ + 2 files changed, 190 insertions(+) + create mode 100644 spec/scansion/muc_mam_unjoined.scs + +diff --git a/plugins/mod_muc_mam.lua b/plugins/mod_muc_mam.lua +index 23bb7da..c1aebbb 100644 +--- a/plugins/mod_muc_mam.lua ++++ b/plugins/mod_muc_mam.lua +@@ -50,6 +50,9 @@ end + local log_all_rooms = module:get_option_boolean("muc_log_all_rooms", false); + local log_by_default = module:get_option_boolean("muc_log_by_default", true); + ++-- Whether unaffiliated JIDs that have not joined may query the archive of open rooms ++local allow_unjoined_queries = module:get_option_boolean("muc_mam_allow_unjoined_queries", false); ++ + local archive_store = "muc_log"; + local archive = module:open_store(archive_store, "archive"); + +@@ -150,6 +153,15 @@ module:hook("iq-set/bare/"..xmlns_mam..":query", function(event) + return true; + end + ++ -- Unaffiliated and not in the room? Only allowed if enabled, and ++ -- never for password-protected rooms, as they have not proven they know it ++ if not from_affiliation and not room:get_occupant_by_real_jid(orig_from) ++ and (not allow_unjoined_queries or room:get_password()) then ++ module:log("warn", "Forbidding archive access from <%s> to <%s> - not joined", orig_from, room.jid); ++ origin.send(st.error_reply(stanza, "auth", "forbidden", "You must be joined to access the message archive")) ++ return true; ++ end ++ + local qid = query.attr.queryid; + + -- Search query parameters +diff --git a/spec/scansion/muc_mam_unjoined.scs b/spec/scansion/muc_mam_unjoined.scs +new file mode 100644 +index 0000000..9180a6f +--- /dev/null ++++ b/spec/scansion/muc_mam_unjoined.scs +@@ -0,0 +1,178 @@ ++# MUC MAM: Archive queries from unaffiliated non-occupants are rejected ++ ++[Client] Romeo ++ jid: user@localhost ++ password: password ++ ++[Client] Juliet ++ jid: user2@localhost ++ password: password ++ ++----- ++ ++Romeo connects ++ ++Romeo sends: ++ ++ ++ ++ ++Romeo receives: ++ ++ ++ ++ ++ ++ ++ ++ ++Romeo receives: ++ ++ ++# Submit config form ++Romeo sends: ++ ++ ++ ++ ++ http://jabber.org/protocol/muc#roomconfig ++ ++ ++ ++ ++ ++Romeo receives: ++ ++ ++ ++Romeo sends: ++ ++ When shall we three meet again? ++ ++ ++Romeo receives: ++ ++ When shall we three meet again? ++ ++ ++ ++Juliet connects ++ ++# Juliet has not joined the room and has no affiliation with it ++ ++Juliet sends: ++ ++ ++ ++ ++Juliet receives: ++ ++ ++ ++ ++ ++ ++# After joining, she can query the archive ++ ++Juliet sends: ++ ++ ++ ++ ++ ++ ++Juliet receives: ++ ++ ++Juliet receives: ++ ++ ++Juliet receives: ++ ++ ++Romeo receives: ++ ++ ++Juliet sends: ++ ++ ++ ++ ++Juliet receives: ++ ++ ++ ++ ++ ++ When shall we three meet again? ++ ++ ++ ++ ++ ++ ++Juliet receives: ++ ++ ++# After leaving, she is refused again ++ ++Juliet sends: ++ ++ ++Juliet receives: ++ ++ ++Romeo receives: ++ ++ ++Juliet sends: ++ ++ ++ ++ ++Juliet receives: ++ ++ ++ ++ ++ ++ ++# Unless she is made a member ++ ++Romeo sends: ++ ++ ++ ++ ++ ++ ++Romeo receives: ++ ++ ++ ++ ++ ++ ++Romeo receives: ++ ++ ++Juliet sends: ++ ++ ++ ++ ++Juliet receives: ++ ++ ++ ++ ++ ++ When shall we three meet again? ++ ++ ++ ++ ++ ++ ++Juliet receives: ++ diff -Nru prosody-13.0.1/debian/patches/0023-util.stanza-Add-support-for-parsing-xs-boolean-and-x.patch prosody-13.0.1/debian/patches/0023-util.stanza-Add-support-for-parsing-xs-boolean-and-x.patch --- prosody-13.0.1/debian/patches/0023-util.stanza-Add-support-for-parsing-xs-boolean-and-x.patch 1970-01-01 00:00:00.000000000 +0000 +++ prosody-13.0.1/debian/patches/0023-util.stanza-Add-support-for-parsing-xs-boolean-and-x.patch 2026-12-01 12:43:09.000000000 +0000 @@ -0,0 +1,117 @@ +From: Matthew Wild +Date: Thu, 12 Nov 2026 15:39:28 +0000 +Subject: util.stanza: Add support for parsing xs:boolean and xs:int + +--- + spec/util_stanza_spec.lua | 34 ++++++++++++++++++++++++++++++++++ + teal-src/prosody/util/stanza.d.tl | 2 ++ + util/stanza.lua | 25 +++++++++++++++++++++++++ + 3 files changed, 61 insertions(+) + +diff --git a/spec/util_stanza_spec.lua b/spec/util_stanza_spec.lua +index f79f8cb..f1e125d 100644 +--- a/spec/util_stanza_spec.lua ++++ b/spec/util_stanza_spec.lua +@@ -378,6 +378,40 @@ describe("util.stanza", function() + end + end); + ++ describe("xs_boolean", function () ++ it("interprets XML Schema booleans", function () ++ assert.is_true(st.xs_boolean("true")); ++ assert.is_true(st.xs_boolean("1")); ++ assert.is_true(st.xs_boolean(" true\n")); ++ assert.is_false(st.xs_boolean("false")); ++ assert.is_false(st.xs_boolean("0")); ++ end); ++ it("returns nil for anything else", function () ++ for _, value in ipairs({ "", "TRUE", "yes", "2", "01", "true false" }) do ++ assert.is_nil(st.xs_boolean(value), value); ++ end ++ assert.is_nil(st.xs_boolean(nil)); ++ end); ++ end); ++ ++ describe("xs_int", function () ++ it("interprets XML Schema ints", function () ++ assert.equal(0, st.xs_int("0")); ++ assert.equal(10, st.xs_int(" 010\n")); ++ assert.equal(5, st.xs_int("+5")); ++ assert.equal(-2, st.xs_int("-2")); ++ assert.equal(2147483647, st.xs_int("2147483647")); ++ assert.equal(-2147483648, st.xs_int("-2147483648")); ++ assert.equal("integer", math.type(st.xs_int("10"))); ++ end); ++ it("returns nil for anything else", function () ++ for _, value in ipairs({ "", "-", "1.5", "1e3", "0x10", "ten", "1 2", "--1", "2147483648", "-2147483649", ("9"):rep(400) }) do ++ assert.is_nil(st.xs_int(value), value); ++ end ++ assert.is_nil(st.xs_int(nil)); ++ end); ++ end); ++ + describe("#is_stanza", function () + -- is_stanza(any) -> boolean + it("identifies stanzas as stanzas", function () +diff --git a/teal-src/prosody/util/stanza.d.tl b/teal-src/prosody/util/stanza.d.tl +index e1ab210..85b5911 100644 +--- a/teal-src/prosody/util/stanza.d.tl ++++ b/teal-src/prosody/util/stanza.d.tl +@@ -139,6 +139,8 @@ local record lib + error_reply : function ( stanza_t, stanza_error_type, stanza_error_condition, string, string ) : stanza_t + presence : function ( presence_attr ) : stanza_t + xml_escape : function ( string ) : string ++ xs_boolean : function ( string ) : boolean ++ xs_int : function ( string ) : integer + pretty_print : function ( string ) : string + end + +diff --git a/util/stanza.lua b/util/stanza.lua +index 2f4e964..599815d 100644 +--- a/util/stanza.lua ++++ b/util/stanza.lua +@@ -13,6 +13,7 @@ local t_remove = table.remove; + local t_concat = table.concat; + local s_match = string.match; + local tostring = tostring; ++local tonumber = tonumber; + local setmetatable = setmetatable; + local getmetatable = getmetatable; + local pairs = pairs; +@@ -340,6 +341,28 @@ end + local escape_table = { ["'"] = "'", ["\""] = """, ["<"] = "<", [">"] = ">", ["&"] = "&" }; + local function xml_escape(str) return (s_gsub(str, "['&<>\"]", escape_table)); end + ++-- Convert string from XML schema datatypes to Lua datatypes ++local function xs_boolean(str) ++ str = str and s_match(str, "^%s*(.-)%s*$"); ++ if str == "true" or str == "1" then ++ return true; ++ elseif str == "false" or str == "0" then ++ return false; ++ end ++end ++ ++-- xs:int is a 32-bit integer ++local function xs_int(str) ++ local sign, digits = s_match(str or "", "^%s*([+-]?)(%d+)%s*$"); ++ local n = digits and tonumber(digits); ++ if not n or n > 0x80000000 then return nil; end ++ if sign == "-" then ++ return -n; ++ elseif n < 0x80000000 then ++ return n; ++ end ++end ++ + local function _dostring(t, buf, self, _xml_escape, parentns) + local nsid = 0; + local name = t.name +@@ -625,5 +648,7 @@ return { + error_reply = error_reply; + presence = presence; + xml_escape = xml_escape; ++ xs_boolean = xs_boolean; ++ xs_int = xs_int; + pretty_print = pretty; + }; diff -Nru prosody-13.0.1/debian/patches/0024-util.rsm-Strictly-validate-integers.patch prosody-13.0.1/debian/patches/0024-util.rsm-Strictly-validate-integers.patch --- prosody-13.0.1/debian/patches/0024-util.rsm-Strictly-validate-integers.patch 1970-01-01 00:00:00.000000000 +0000 +++ prosody-13.0.1/debian/patches/0024-util.rsm-Strictly-validate-integers.patch 2026-12-01 12:43:09.000000000 +0000 @@ -0,0 +1,122 @@ +From: Matthew Wild +Date: Thu, 12 Nov 2026 15:41:31 +0000 +Subject: util.rsm: Strictly validate integers + +--- + spec/util_rsm_spec.lua | 35 +++++++++++++++++++++++++++++++++++ + util/rsm.lua | 27 +++++++++++++++++++++------ + 2 files changed, 56 insertions(+), 6 deletions(-) + +diff --git a/spec/util_rsm_spec.lua b/spec/util_rsm_spec.lua +index c046720..5f99f60 100644 +--- a/spec/util_rsm_spec.lua ++++ b/spec/util_rsm_spec.lua +@@ -61,6 +61,41 @@ describe("util.rsm", function () + end); + end); + ++ describe("parse", function () ++ local function parse(inner) ++ return rsm.parse(xml.parse(""..inner.."")); ++ end ++ ++ it("rejects invalid integers", function () ++ for _, value in ipairs({ "-2", "-1", "-0x1", "1.5", "1e3", "0x10", "", "ten", "1 2", "2147483648", ("9"):rep(400) }) do ++ local rs, invalid = parse(""..value..""); ++ assert.is_nil(rs.max, value); ++ assert.equal("max", invalid, value); ++ end ++ assert.same({ {}, "index" }, { parse("-1") }); ++ assert.same({ {}, "count" }, { parse("-1") }); ++ assert.same({ {}, "first" }, { parse("a") }); ++ end); ++ ++ it("keeps valid fields and reports the first invalid one", function () ++ assert.same({ { after = "a" }, "max" }, { parse("-2ax") }); ++ end); ++ ++ it("accepts valid integers", function () ++ assert.same({ { max = 0 } }, { parse("0") }); ++ assert.same({ { max = 10 } }, { parse(" 010 ") }); ++ assert.same({ { max = 2147483647 } }, { parse("2147483647") }); ++ assert.same({ { first = { "a" } } }, { parse("a") }); ++ end); ++ end); ++ ++ describe("get", function () ++ it("reports invalid values", function () ++ local query = xml.parse("-2"); ++ assert.same({ {}, "max" }, { rsm.get(query) }); ++ end); ++ end); ++ + describe("generate", function () + it("works", function () + local test = xml.parse(strip([[ +diff --git a/util/rsm.lua b/util/rsm.lua +index fc6a048..ebd30b1 100644 +--- a/util/rsm.lua ++++ b/util/rsm.lua +@@ -10,7 +10,7 @@ + -- + + local stanza = require"prosody.util.stanza".stanza; +-local tonumber = tonumber; ++local parse_xs_int = require"prosody.util.stanza".xs_int; + local s_format = string.format; + local type = type; + local pairs = pairs; +@@ -25,8 +25,15 @@ local element_parsers = {}; + + do + local parsers = element_parsers; ++ -- Counts and positions, so negative values are invalid as well ++ local function to_int(text) ++ local n = parse_xs_int(text); ++ if n and n >= 0 then ++ return n; ++ end ++ end + local function xs_int(st) +- return tonumber((st:get_text())); ++ return to_int(st:get_text()); + end + local function xs_string(st) + return st:get_text(); +@@ -41,7 +48,9 @@ do + parsers.index = xs_int; + + parsers.first = function(st) +- return { index = tonumber(st.attr.index); st:get_text() }; ++ local index = to_int(st.attr.index); ++ if st.attr.index and not index then return nil; end ++ return { index = index; st:get_text() }; + end; + parsers.last = xs_string; + parsers.count = xs_int; +@@ -80,16 +89,22 @@ local element_generators = setmetatable({ + }); + + ++-- Returns the parsed result set. Elements with invalid values are left out, ++-- and the name of the first such element is returned as a second value. + local function parse(set) +- local rs = {}; ++ local rs, invalid = {}, nil; + for tag in set:childtags() do + local name = tag.name; + local parser = name and element_parsers[name]; + if parser then +- rs[name] = parser(tag); ++ local value = parser(tag); ++ if value == nil then ++ invalid = invalid or name; ++ end ++ rs[name] = value; + end + end +- return rs; ++ return rs, invalid; + end + + local function generate(t) diff -Nru prosody-13.0.1/debian/patches/0025-mod_mam-Return-error-on-invalid-RSM-fields.patch prosody-13.0.1/debian/patches/0025-mod_mam-Return-error-on-invalid-RSM-fields.patch --- prosody-13.0.1/debian/patches/0025-mod_mam-Return-error-on-invalid-RSM-fields.patch 1970-01-01 00:00:00.000000000 +0000 +++ prosody-13.0.1/debian/patches/0025-mod_mam-Return-error-on-invalid-RSM-fields.patch 2026-12-01 12:43:09.000000000 +0000 @@ -0,0 +1,25 @@ +From: Matthew Wild +Date: Thu, 12 Nov 2026 15:44:37 +0000 +Subject: mod_mam: Return error on invalid RSM fields + +--- + plugins/mod_mam/mod_mam.lua | 6 +++++- + 1 file changed, 5 insertions(+), 1 deletion(-) + +diff --git a/plugins/mod_mam/mod_mam.lua b/plugins/mod_mam/mod_mam.lua +index 4eb4981..cd5f8bd 100644 +--- a/plugins/mod_mam/mod_mam.lua ++++ b/plugins/mod_mam/mod_mam.lua +@@ -139,7 +139,11 @@ module:hook("iq-set/self/"..xmlns_mam..":query", function(event) + end + + -- RSM stuff +- local qset = rsm.get(query); ++ local qset, invalid_rsm = rsm.get(query); ++ if invalid_rsm then ++ origin.send(st.error_reply(stanza, "modify", "bad-request", "Invalid value for RSM <"..invalid_rsm..">")); ++ return true; ++ end + local qmax = m_min(qset and qset.max or default_max_items, max_max_items); + local reverse = qset and qset.before or false; + diff -Nru prosody-13.0.1/debian/patches/0026-mod_muc_mam-Return-error-on-invalid-RSM-fields.patch prosody-13.0.1/debian/patches/0026-mod_muc_mam-Return-error-on-invalid-RSM-fields.patch --- prosody-13.0.1/debian/patches/0026-mod_muc_mam-Return-error-on-invalid-RSM-fields.patch 1970-01-01 00:00:00.000000000 +0000 +++ prosody-13.0.1/debian/patches/0026-mod_muc_mam-Return-error-on-invalid-RSM-fields.patch 2026-12-01 12:43:09.000000000 +0000 @@ -0,0 +1,25 @@ +From: Matthew Wild +Date: Thu, 12 Nov 2026 15:44:51 +0000 +Subject: mod_muc_mam: Return error on invalid RSM fields + +--- + plugins/mod_muc_mam.lua | 6 +++++- + 1 file changed, 5 insertions(+), 1 deletion(-) + +diff --git a/plugins/mod_muc_mam.lua b/plugins/mod_muc_mam.lua +index c1aebbb..614354f 100644 +--- a/plugins/mod_muc_mam.lua ++++ b/plugins/mod_muc_mam.lua +@@ -189,7 +189,11 @@ module:hook("iq-set/bare/"..xmlns_mam..":query", function(event) + end + + -- RSM stuff +- local qset = rsm.get(query); ++ local qset, invalid_rsm = rsm.get(query); ++ if invalid_rsm then ++ origin.send(st.error_reply(stanza, "modify", "bad-request", "Invalid value for RSM <"..invalid_rsm..">")); ++ return true; ++ end + local qmax = m_min(qset and qset.max or default_max_items, max_max_items); + local reverse = qset and qset.before or false; + diff -Nru prosody-13.0.1/debian/patches/0027-mod_storage_sql-Reject-invalid-RSM-limit.patch prosody-13.0.1/debian/patches/0027-mod_storage_sql-Reject-invalid-RSM-limit.patch --- prosody-13.0.1/debian/patches/0027-mod_storage_sql-Reject-invalid-RSM-limit.patch 1970-01-01 00:00:00.000000000 +0000 +++ prosody-13.0.1/debian/patches/0027-mod_storage_sql-Reject-invalid-RSM-limit.patch 2026-12-01 12:43:09.000000000 +0000 @@ -0,0 +1,56 @@ +From: Matthew Wild +Date: Thu, 12 Nov 2026 18:34:22 +0000 +Subject: mod_storage_sql: Reject invalid RSM limit + +--- + plugins/mod_storage_sql.lua | 7 ++++++- + spec/core_storagemanager_spec.lua | 11 +++++++++++ + 2 files changed, 17 insertions(+), 1 deletion(-) + +diff --git a/plugins/mod_storage_sql.lua b/plugins/mod_storage_sql.lua +index f053f72..046213c 100644 +--- a/plugins/mod_storage_sql.lua ++++ b/plugins/mod_storage_sql.lua +@@ -466,6 +466,11 @@ end + + function archive_store:find(username, query) + query = query or {}; ++ local limit = query.limit; ++ if limit ~= nil and (type(limit) ~= "number" or limit < 0 or limit % 1 ~= 0) then ++ -- Goes into the query text below, and a negative LIMIT means 'unlimited' to SQLite ++ return nil, "invalid-limit"; ++ end + local user,store = username,self.store; + local cache_key = jid_join(username, host, self.store); + local total = archive_item_count_cache:get(cache_key); +@@ -512,7 +517,7 @@ function archive_store:find(username, query) + if not ok then return ok, err; end + + sql_query = sql_query:format(t_concat(where, " AND "), query.reverse +- and "DESC" or "ASC", query.limit and " LIMIT " .. query.limit or ""); ++ and "DESC" or "ASC", limit and (" LIMIT %d"):format(limit) or ""); + return engine:select(sql_query, unpack(args)); + end); + if not ok then return ok, result; end +diff --git a/spec/core_storagemanager_spec.lua b/spec/core_storagemanager_spec.lua +index 32a8d6f..e83614b 100644 +--- a/spec/core_storagemanager_spec.lua ++++ b/spec/core_storagemanager_spec.lua +@@ -539,6 +539,17 @@ describe("storagemanager", function () + end); + + ++ it("does not treat an invalid limit as unlimited", function () ++ for _, limit in ipairs({ -1, -2, 1.5 }) do ++ local data = archive:find("user", { limit = limit }); ++ local count = 0; ++ for _ in data or function () end do ++ count = count + 1; ++ end ++ assert.truthy(count < #test_data, "limit "..limit.." returned "..count.." items"); ++ end ++ end); ++ + it("can be queried in reverse", function () + + local data, err = archive:find("user", { diff -Nru prosody-13.0.1/debian/patches/0028-mod_storage_memory-Reject-invalid-RSM-limit.patch prosody-13.0.1/debian/patches/0028-mod_storage_memory-Reject-invalid-RSM-limit.patch --- prosody-13.0.1/debian/patches/0028-mod_storage_memory-Reject-invalid-RSM-limit.patch 1970-01-01 00:00:00.000000000 +0000 +++ prosody-13.0.1/debian/patches/0028-mod_storage_memory-Reject-invalid-RSM-limit.patch 2026-12-01 12:43:09.000000000 +0000 @@ -0,0 +1,23 @@ +From: Matthew Wild +Date: Thu, 12 Nov 2026 18:34:42 +0000 +Subject: mod_storage_memory: Reject invalid RSM limit + +--- + plugins/mod_storage_memory.lua | 4 ++++ + 1 file changed, 4 insertions(+) + +diff --git a/plugins/mod_storage_memory.lua b/plugins/mod_storage_memory.lua +index 49f94d1..4668e91 100644 +--- a/plugins/mod_storage_memory.lua ++++ b/plugins/mod_storage_memory.lua +@@ -106,6 +106,10 @@ function archive_store:find(username, query) + local count = nil; + local i, last_key = 0; + if query then ++ local limit = query.limit; ++ if limit ~= nil and (type(limit) ~= "number" or limit < 0 or limit % 1 ~= 0) then ++ return nil, "invalid-limit"; ++ end + items = array():append(items); + if query.key then + items:filter(function (item) diff -Nru prosody-13.0.1/debian/patches/0029-net.http.parser-Fix-handling-of-chunked-request.patch prosody-13.0.1/debian/patches/0029-net.http.parser-Fix-handling-of-chunked-request.patch --- prosody-13.0.1/debian/patches/0029-net.http.parser-Fix-handling-of-chunked-request.patch 1970-01-01 00:00:00.000000000 +0000 +++ prosody-13.0.1/debian/patches/0029-net.http.parser-Fix-handling-of-chunked-request.patch 2026-12-01 12:43:09.000000000 +0000 @@ -0,0 +1,64 @@ +From: Kim Alvefur +Date: Fri, 20 Feb 2026 15:08:03 +0100 +Subject: net.http.parser: Fix handling of chunked request + +How to determine whether a request/response has a body depends on +different things for requests and responses, which was not reflected in +the code. + +Test case based on + + curl http://localhost:5280/debug -H "Transfer-Encoding: chunked" --json '{"json":true}' + +Thanks isafashiondev +--- + net/http/parser.lua | 10 +++++++++- + spec/net_http_parser_spec.lua | 5 +++++ + 2 files changed, 14 insertions(+), 1 deletion(-) + +diff --git a/net/http/parser.lua b/net/http/parser.lua +index b7e8b46..f2340ea 100644 +--- a/net/http/parser.lua ++++ b/net/http/parser.lua +@@ -93,9 +93,12 @@ function httpstream.new(success_cb, error_cb, parser_type, options_cb) + end + end + if not first_line then error = true; return error_cb("invalid-status-line"); end +- chunked = have_body and headers["transfer-encoding"] == "chunked"; + len = tonumber(headers["content-length"]); -- TODO check for invalid len + if client then ++ -- The presence of a message body in a response, as detailed in Section 6.3, depends on both the request method to which it is responding ++ -- and the response status code. ++ -- -- RFC9112 Section 6 ++ chunked = have_body and headers["transfer-encoding"] == "chunked"; + -- FIXME handle '100 Continue' response (by skipping it) + if not have_body then len = 0; end + packet = { +@@ -111,6 +114,11 @@ function httpstream.new(success_cb, error_cb, parser_type, options_cb) + responseheaders = headers; + }; + else ++ -- The presence of a message body in a request is signaled by a Content-Length or Transfer-Encoding header field. Request message framing ++ -- is independent of method semantics. ++ -- -- RFC9112 Section 6 ++ chunked = headers["transfer-encoding"] == "chunked"; ++ have_body = chunked or len; + local parsed_url; + if path:byte() == 47 then -- starts with / + local _path, _query = path:match("([^?]*).?(.*)"); +diff --git a/spec/net_http_parser_spec.lua b/spec/net_http_parser_spec.lua +index 84a81f0..d81e4cc 100644 +--- a/spec/net_http_parser_spec.lua ++++ b/spec/net_http_parser_spec.lua +@@ -120,6 +120,11 @@ o + body = "Hello", count = 3; + } + ); ++ ++ test_stream( ++ "POST /debug HTTP/1.1\r\nHost: localhost:5280\r\nUser-Agent: curl/8.14.1\r\nTransfer-Encoding: chunked\r\nContent-Type: application/json\r\n" ++ .."Accept: application/json\r\n\r\nd\r\n{\"json\":true}\r\n0\r\n\r\n", ++ { count = 2; body = "{\"json\":true}" }) + end); + + it("should handle a stream of responses", function () diff -Nru prosody-13.0.1/debian/patches/0030-mod_http_file_share-Enforce-valid-content-type-in-sl.patch prosody-13.0.1/debian/patches/0030-mod_http_file_share-Enforce-valid-content-type-in-sl.patch --- prosody-13.0.1/debian/patches/0030-mod_http_file_share-Enforce-valid-content-type-in-sl.patch 1970-01-01 00:00:00.000000000 +0000 +++ prosody-13.0.1/debian/patches/0030-mod_http_file_share-Enforce-valid-content-type-in-sl.patch 2026-12-01 12:43:09.000000000 +0000 @@ -0,0 +1,31 @@ +From: Matthew Wild +Date: Fri, 13 Nov 2026 11:52:46 +0000 +Subject: mod_http_file_share: Enforce valid content type in slot requests + +--- + plugins/mod_http_file_share.lua | 10 +++++++++- + 1 file changed, 9 insertions(+), 1 deletion(-) + +diff --git a/plugins/mod_http_file_share.lua b/plugins/mod_http_file_share.lua +index 7b9aff7..90929a3 100644 +--- a/plugins/mod_http_file_share.lua ++++ b/plugins/mod_http_file_share.lua +@@ -228,9 +228,17 @@ function handle_slot_request(event) + local request = st.clone(stanza.tags[1], true); + local filename = request.attr.filename; + local filesize = tonumber(request.attr.size); +- local filetype = request.attr["content-type"] or "application/octet-stream"; ++ local filetype = request.attr["content-type"]; + local uploader = jid.bare(stanza.attr.from); + ++ ++ if filetype then ++ filetype = filetype:match("^[%w!#$&^_.+-]+/[%w!#$&^_.+-]+$"); -- RFC 6838 ++ end ++ if not filetype then ++ filetype = "application/octet-stream"; ++ end ++ + local may, why_not = may_upload(uploader, filename, filesize, filetype); + if not may then + origin.send(st.error_reply(stanza, why_not)); diff -Nru prosody-13.0.1/debian/patches/0031-mod_dialback-Reject-dialback-requests-for-hosts-with.patch prosody-13.0.1/debian/patches/0031-mod_dialback-Reject-dialback-requests-for-hosts-with.patch --- prosody-13.0.1/debian/patches/0031-mod_dialback-Reject-dialback-requests-for-hosts-with.patch 1970-01-01 00:00:00.000000000 +0000 +++ prosody-13.0.1/debian/patches/0031-mod_dialback-Reject-dialback-requests-for-hosts-with.patch 2026-12-01 12:43:09.000000000 +0000 @@ -0,0 +1,23 @@ +From: Matthew Wild +Date: Fri, 13 Nov 2026 11:55:12 +0000 +Subject: mod_dialback: Reject dialback requests for hosts with s2s disabled + +--- + plugins/mod_dialback.lua | 4 ++++ + 1 file changed, 4 insertions(+) + +diff --git a/plugins/mod_dialback.lua b/plugins/mod_dialback.lua +index a0a8bcb..9c85ea2 100644 +--- a/plugins/mod_dialback.lua ++++ b/plugins/mod_dialback.lua +@@ -92,6 +92,10 @@ module:hook("stanza/jabber:server:dialback:result", function(event) + origin.log("warn", "%s tried to connect to %s, which we don't serve", from, to); + origin:close("host-unknown"); + return true; ++ elseif not hosts[to].modules.s2s then ++ origin.log("warn", "%s tried to connect to %s, which has s2s disabled", from, to); ++ origin:close({ condition = "policy-violation", text = "Server-to-server communication is disabled for this host" }); ++ return true; + elseif not from then + origin:close("improper-addressing"); + return true; diff -Nru prosody-13.0.1/debian/patches/0032-stanza_router-reject-stanzas-to-hosts-with-mod_s2s-d.patch prosody-13.0.1/debian/patches/0032-stanza_router-reject-stanzas-to-hosts-with-mod_s2s-d.patch --- prosody-13.0.1/debian/patches/0032-stanza_router-reject-stanzas-to-hosts-with-mod_s2s-d.patch 1970-01-01 00:00:00.000000000 +0000 +++ prosody-13.0.1/debian/patches/0032-stanza_router-reject-stanzas-to-hosts-with-mod_s2s-d.patch 2026-12-01 12:43:09.000000000 +0000 @@ -0,0 +1,24 @@ +From: Matthew Wild +Date: Fri, 13 Nov 2026 11:56:51 +0000 +Subject: stanza_router: reject stanzas to hosts with mod_s2s disabled + +--- + core/stanza_router.lua | 5 +++++ + 1 file changed, 5 insertions(+) + +diff --git a/core/stanza_router.lua b/core/stanza_router.lua +index 87b3ed2..7d2788c 100644 +--- a/core/stanza_router.lua ++++ b/core/stanza_router.lua +@@ -123,6 +123,11 @@ function core_process_stanza(origin, stanza) + log("warn", "Remote server %s sent us a stanza for %s, closing stream", origin.from_host, host); + origin:close("host-unknown"); + return; ++ elseif not hosts[host].modules.s2s then ++ -- The stream is authenticated, but only checked for the host named in its header ++ log("warn", "Remote server %s sent us a stanza for %s, which has s2s disabled, closing stream", origin.from_host, host); ++ origin:close({ condition = "policy-violation", text = "Server-to-server communication is disabled for this host" }); ++ return; + end + end + core_post_stanza(origin, stanza, origin.full_jid); diff -Nru prosody-13.0.1/debian/patches/0033-net.http.parser-Error-on-sink-write-failure.patch prosody-13.0.1/debian/patches/0033-net.http.parser-Error-on-sink-write-failure.patch --- prosody-13.0.1/debian/patches/0033-net.http.parser-Error-on-sink-write-failure.patch 1970-01-01 00:00:00.000000000 +0000 +++ prosody-13.0.1/debian/patches/0033-net.http.parser-Error-on-sink-write-failure.patch 2026-12-01 12:43:09.000000000 +0000 @@ -0,0 +1,74 @@ +From: Matthew Wild +Date: Fri, 13 Nov 2026 13:29:21 +0000 +Subject: net.http.parser: Error on sink write failure + +--- + net/http/parser.lua | 5 ++++- + spec/net_http_parser_spec.lua | 38 ++++++++++++++++++++++++++++++++++++++ + 2 files changed, 42 insertions(+), 1 deletion(-) + +diff --git a/net/http/parser.lua b/net/http/parser.lua +index f2340ea..b303329 100644 +--- a/net/http/parser.lua ++++ b/net/http/parser.lua +@@ -185,7 +185,10 @@ function httpstream.new(success_cb, error_cb, parser_type, options_cb) + success_cb(packet); + elseif buffer:length() - chunk_start - 1 >= chunk_size then -- we have a chunk + buffer:discard(chunk_start - 1); +- (packet.body_sink or packet.body_buffer):write(buffer:read(chunk_size)); ++ if not (packet.body_sink or packet.body_buffer):write(buffer:read(chunk_size)) then ++ error = true; ++ return error_cb(packet.body_sink and "body-sink-write-failure" or "max-buffer-size-exceeded"); ++ end + buffer:discard(2); -- CRLF + else -- Partial chunk remaining + break; +diff --git a/spec/net_http_parser_spec.lua b/spec/net_http_parser_spec.lua +index d81e4cc..b0470b0 100644 +--- a/spec/net_http_parser_spec.lua ++++ b/spec/net_http_parser_spec.lua +@@ -173,6 +173,44 @@ Transfer-Encoding: chunked + ); + end); + ++ it("should stop when the body sink refuses a chunk", function () ++ local writes = 0; ++ local success_cb = spy.new(function (packet) ++ packet.body_sink = { ++ write = function (_, data) ++ writes = writes + 1; ++ return #data <= 3 or nil; ++ end; ++ }; ++ end); ++ local error_cb = spy.new(function () end); ++ local parser = http_parser.new(success_cb, error_cb, "server"); ++ parser:feed("PUT /upload HTTP/1.1\r\nTransfer-Encoding: chunked\r\n\r\n"); ++ parser:feed("3\r\nfoo\r\n6\r\nfoobar\r\n3\r\nbaz\r\n0\r\n\r\n"); ++ assert.equal(2, writes); ++ assert.spy(success_cb).was_called(1); -- only the early notification ++ assert.spy(error_cb).was_called(1); ++ assert.spy(error_cb).was_called_with("body-sink-write-failure"); ++ assert.is_nil(parser:feed("3\r\nbaz\r\n0\r\n\r\n")); ++ assert.equal(2, writes); ++ end); ++ ++ it("should reject chunked bodies larger than the buffer limit", function () ++ local success_cb = spy.new(function () end); ++ local error_cb = spy.new(function () end); ++ local parser = http_parser.new(success_cb, error_cb, "server", function () ++ return { body_size_limit = 32; buffer_size_limit = 64 }; ++ end); ++ parser:feed("POST / HTTP/1.1\r\nTransfer-Encoding: chunked\r\n\r\n"); ++ for _ = 1, 11 do ++ parser:feed("6\r\nfoobar\r\n"); ++ end ++ parser:feed("0\r\n\r\n"); ++ assert.spy(success_cb).was_called(1); -- only the early notification ++ assert.spy(error_cb).was_called(1); ++ assert.spy(error_cb).was_called_with("max-buffer-size-exceeded"); ++ end); ++ + it("should reject very large request heads", function() + local finished = false; + local success_cb = spy.new(function() diff -Nru prosody-13.0.1/debian/patches/0034-mod_http_file_share-Limit-data-written-to-sink-based.patch prosody-13.0.1/debian/patches/0034-mod_http_file_share-Limit-data-written-to-sink-based.patch --- prosody-13.0.1/debian/patches/0034-mod_http_file_share-Limit-data-written-to-sink-based.patch 1970-01-01 00:00:00.000000000 +0000 +++ prosody-13.0.1/debian/patches/0034-mod_http_file_share-Limit-data-written-to-sink-based.patch 2026-12-01 12:43:09.000000000 +0000 @@ -0,0 +1,47 @@ +From: Matthew Wild +Date: Fri, 13 Nov 2026 13:30:42 +0000 +Subject: mod_http_file_share: Limit data written to sink based on slot + request + +--- + plugins/mod_http_file_share.lua | 20 +++++++++++++++++++- + 1 file changed, 19 insertions(+), 1 deletion(-) + +diff --git a/plugins/mod_http_file_share.lua b/plugins/mod_http_file_share.lua +index 90929a3..b8eb759 100644 +--- a/plugins/mod_http_file_share.lua ++++ b/plugins/mod_http_file_share.lua +@@ -277,6 +277,24 @@ function handle_slot_request(event) + return true; + end + ++-- Wrap a file handle so that no more than the pre-agreed size is written to ++-- disk (a chunked upload has no Content-Length) ++local function limited_sink(fh, limit, request) ++ local written = 0; ++ return { ++ write = function (_, data) ++ written = written + #data; ++ if written > limit then ++ module:log("debug", "Upload exceeds expected size of %s", B(limit)); ++ return nil, upload_errors.new("filesize", { request = request }); ++ end ++ return fh:write(data); ++ end; ++ seek = function (_, ...) return fh:seek(...); end; ++ close = function () return fh:close(); end; ++ }; ++end ++ + function handle_upload(event, path) -- PUT /upload/:slot + local request = event.request; + local upload_info = request.http_file_share_upload_info; +@@ -335,7 +353,7 @@ function handle_upload(event, path) -- PUT /upload/:slot + os.remove(filename.."~"); + end + end +- request.body_sink = fh; ++ request.body_sink = limited_sink(fh, upload_info.filesize, request); + if request.body == false then + if request.headers.expect == "100-continue" then + request.conn:write("HTTP/1.1 100 Continue\r\n\r\n"); diff -Nru prosody-13.0.1/debian/patches/0035-mod_tokenauth-Apply-role-if-any-from-OAuth-token-to-.patch prosody-13.0.1/debian/patches/0035-mod_tokenauth-Apply-role-if-any-from-OAuth-token-to-.patch --- prosody-13.0.1/debian/patches/0035-mod_tokenauth-Apply-role-if-any-from-OAuth-token-to-.patch 1970-01-01 00:00:00.000000000 +0000 +++ prosody-13.0.1/debian/patches/0035-mod_tokenauth-Apply-role-if-any-from-OAuth-token-to-.patch 2026-12-01 12:43:09.000000000 +0000 @@ -0,0 +1,29 @@ +From: Matthew Wild +Date: Mon, 16 Nov 2026 17:12:26 +0000 +Subject: mod_tokenauth: Apply role (if any) from OAuth token to SASL-authed + sessions + +Basically echoes what we already do for HTTP authed sessions. +--- + plugins/mod_tokenauth.lua | 8 ++++++++ + 1 file changed, 8 insertions(+) + +diff --git a/plugins/mod_tokenauth.lua b/plugins/mod_tokenauth.lua +index 4760788..94bcae4 100644 +--- a/plugins/mod_tokenauth.lua ++++ b/plugins/mod_tokenauth.lua +@@ -341,6 +341,14 @@ function sasl_handler(auth_provider, purpose, extra) + if auth_provider.is_enabled and not auth_provider.is_enabled(token_user) then + return true, false, token_info; + end ++ if token_info.role then ++ local role = select_role(token_user, token_host, token_info.role); ++ if not role then ++ module:log("debug", "SASL handler rejected token: user cannot assume role %s", token_info.role); ++ return nil, nil, extra; ++ end ++ sasl.role = role.name; ++ end + sasl.resource = resource; + sasl.token_info = token_info; + return token_user, true, token_info; diff -Nru prosody-13.0.1/debian/patches/0036-mod_invites_register-Stricter-validation-of-registra.patch prosody-13.0.1/debian/patches/0036-mod_invites_register-Stricter-validation-of-registra.patch --- prosody-13.0.1/debian/patches/0036-mod_invites_register-Stricter-validation-of-registra.patch 1970-01-01 00:00:00.000000000 +0000 +++ prosody-13.0.1/debian/patches/0036-mod_invites_register-Stricter-validation-of-registra.patch 2026-12-01 12:43:09.000000000 +0000 @@ -0,0 +1,47 @@ +From: Matthew Wild +Date: Thu, 10 Apr 2025 16:07:32 +0100 +Subject: mod_invites_register: Stricter validation of registration events + +This fixes two problems: + + 1) Account invites that were created with a specific username were not + in fact restricted to that username. + + 2) Password reset invites were not restricted to resetting passwords, + but could be used to create an arbitrary new account if the client + or registration frontend (e.g. mod_invites_register_web) doesn't + handle/enforce the username. + +This new validation ensures that registrations and resets are always for the +username specified in the invitation. +--- + plugins/mod_invites_register.lua | 16 ++++++++++++++-- + 1 file changed, 14 insertions(+), 2 deletions(-) + +diff --git a/plugins/mod_invites_register.lua b/plugins/mod_invites_register.lua +index b51d2f3..7d14c62 100644 +--- a/plugins/mod_invites_register.lua ++++ b/plugins/mod_invites_register.lua +@@ -110,8 +110,20 @@ module:hook("user-registering", function (event) + -- for this module to do... + return; + end +- if validated_invite and validated_invite.additional_data and validated_invite.additional_data.allow_reset then +- event.allow_reset = validated_invite.additional_data.allow_reset; ++ if validated_invite then ++ local username = validated_invite.username; ++ if username and username ~= event.username then ++ event.allowed = false; ++ event.reason = "The chosen username is not valid with this invitation"; ++ end ++ local reset_username = validated_invite.additional_data and validated_invite.additional_data.allow_reset; ++ if reset_username then ++ if reset_username ~= event.username then ++ event.allowed = false; ++ event.reason = "Incorrect username for password reset"; ++ end ++ event.allow_reset = reset_username; ++ end + end + end); + diff -Nru prosody-13.0.1/debian/patches/0037-mod_invites_register-Don-t-restrict-username-for-ros.patch prosody-13.0.1/debian/patches/0037-mod_invites_register-Don-t-restrict-username-for-ros.patch --- prosody-13.0.1/debian/patches/0037-mod_invites_register-Don-t-restrict-username-for-ros.patch 1970-01-01 00:00:00.000000000 +0000 +++ prosody-13.0.1/debian/patches/0037-mod_invites_register-Don-t-restrict-username-for-ros.patch 2026-12-01 12:43:09.000000000 +0000 @@ -0,0 +1,24 @@ +From: Matthew Wild +Date: Wed, 16 Apr 2025 12:02:31 +0100 +Subject: mod_invites_register: Don't restrict username for roster invites + (thanks lissine) + +The username field of roster invites is the username of the inviter. It is not +possible for a roster invite to restrict the registration username. +--- + plugins/mod_invites_register.lua | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/plugins/mod_invites_register.lua b/plugins/mod_invites_register.lua +index 7d14c62..f24ef49 100644 +--- a/plugins/mod_invites_register.lua ++++ b/plugins/mod_invites_register.lua +@@ -112,7 +112,7 @@ module:hook("user-registering", function (event) + end + if validated_invite then + local username = validated_invite.username; +- if username and username ~= event.username then ++ if validated_invite.type ~= "roster" and username and username ~= event.username then + event.allowed = false; + event.reason = "The chosen username is not valid with this invitation"; + end diff -Nru prosody-13.0.1/debian/patches/0038-mod_invites-mod_invites_register-Use-new-allowed_use.patch prosody-13.0.1/debian/patches/0038-mod_invites-mod_invites_register-Use-new-allowed_use.patch --- prosody-13.0.1/debian/patches/0038-mod_invites-mod_invites_register-Use-new-allowed_use.patch 1970-01-01 00:00:00.000000000 +0000 +++ prosody-13.0.1/debian/patches/0038-mod_invites-mod_invites_register-Use-new-allowed_use.patch 2026-12-01 12:43:09.000000000 +0000 @@ -0,0 +1,79 @@ +From: Matthew Wild +Date: Tue, 17 Nov 2026 11:48:07 +0000 +Subject: mod_invites, + mod_invites_register: Use new 'allowed_username' field for recording + username restriction + +Due to apparent confusion over the meaning of the 'username' field, it was +being (or not being) used for two separate purposes - the username of the +inviter (in roster subscription invites) and the account username restriction +in account-only invites. The latter was checked, but never actually triggered +because the username field was not populated in the non-roster case. + +Rather than continue the confusion, the username restriction now uses a +separate field. +--- + plugins/mod_invites.lua | 7 ++++++- + plugins/mod_invites_register.lua | 5 +++-- + 2 files changed, 9 insertions(+), 3 deletions(-) + +diff --git a/plugins/mod_invites.lua b/plugins/mod_invites.lua +index 863558c..dbcd256 100644 +--- a/plugins/mod_invites.lua ++++ b/plugins/mod_invites.lua +@@ -169,12 +169,14 @@ end + -- If no username is passed, but the registration is a roster invite + -- from a local user, the "inviter" field of the returned invite will + -- be set to their username. ++-- For "register" invites restricted to a single username, the ++-- "allowed_username" field of the returned invite will be set to it. + function get(token, username) + if not token then + return nil, "no-token"; + end + +- local valid_until, inviter; ++ local valid_until, inviter, allowed_username; + + -- Fetch from host store (account invite) + local token_info = token_storage:get(nil, token); +@@ -187,6 +189,8 @@ function get(token, username) + if token_info and token_info.type == "roster" then + username = jid_node(token_info.jid); + inviter = username; ++ elseif token_info and token_info.type == "register" then ++ allowed_username = jid_node(token_info.jid); + end + end + +@@ -202,6 +206,7 @@ function get(token, username) + token = token; + username = username; + inviter = inviter; ++ allowed_username = allowed_username; + type = token_info and token_info.type or "roster"; + uri = token_info and token_info.uri or get_uri("roster", username.."@"..module.host, token); + additional_data = token_info and token_info.additional_data or nil; +diff --git a/plugins/mod_invites_register.lua b/plugins/mod_invites_register.lua +index f24ef49..a4463db 100644 +--- a/plugins/mod_invites_register.lua ++++ b/plugins/mod_invites_register.lua +@@ -1,6 +1,7 @@ + local st = require "prosody.util.stanza"; + local jid_split = require "prosody.util.jid".split; + local jid_bare = require "prosody.util.jid".bare; ++local nodeprep = require "prosody.util.encodings".stringprep.nodeprep; + local rostermanager = require "prosody.core.rostermanager"; + + local require_encryption = module:get_option_boolean("c2s_require_encryption", +@@ -111,8 +112,8 @@ module:hook("user-registering", function (event) + return; + end + if validated_invite then +- local username = validated_invite.username; +- if validated_invite.type ~= "roster" and username and username ~= event.username then ++ local allowed_username = validated_invite.allowed_username; ++ if allowed_username and nodeprep(allowed_username) ~= event.username then + event.allowed = false; + event.reason = "The chosen username is not valid with this invitation"; + end diff -Nru prosody-13.0.1/debian/patches/0039-net.http.server-Ensure-finish_cb-is-always-called-on.patch prosody-13.0.1/debian/patches/0039-net.http.server-Ensure-finish_cb-is-always-called-on.patch --- prosody-13.0.1/debian/patches/0039-net.http.server-Ensure-finish_cb-is-always-called-on.patch 1970-01-01 00:00:00.000000000 +0000 +++ prosody-13.0.1/debian/patches/0039-net.http.server-Ensure-finish_cb-is-always-called-on.patch 2026-12-01 12:43:09.000000000 +0000 @@ -0,0 +1,57 @@ +From: Matthew Wild +Date: Tue, 17 Nov 2026 15:51:07 +0000 +Subject: net.http.server: Ensure finish_cb() is always called on socket + disconnection + +This fixes a potential leak, since at least 49ecfb070240 which introduced the +waiting_runners table. +--- + net/http/server.lua | 18 ++++++++++++++---- + 1 file changed, 14 insertions(+), 4 deletions(-) + +diff --git a/net/http/server.lua b/net/http/server.lua +index 1ef42b2..61821e2 100644 +--- a/net/http/server.lua ++++ b/net/http/server.lua +@@ -98,6 +98,7 @@ end, -1); + local runner_callbacks = {}; + + function runner_callbacks:ready() ++ if self.data.disconnected then return; end + self.data.conn:resume(); + end + +@@ -122,6 +123,7 @@ function listener.onconnect(conn) + local secure = conn:ssl() and true or nil; + local ip = conn:ip(); + session.thread = async.runner(function (request) ++ if session.disconnected then return; end -- Drop requests still queued behind the open one + local wait, done; + if request.partial == true then + -- Have the header for a request, we want to receive the rest +@@ -155,13 +157,21 @@ function listener.onconnect(conn) + end + + function listener.ondisconnect(conn) +- local open_response = conn._http_open_response; +- if open_response and open_response.on_destroy then +- open_response.finished = true; +- open_response:on_destroy(); ++ local session = sessions[conn]; ++ if session then ++ session.disconnected = true; + end + incomplete[conn] = nil; + sessions[conn] = nil; ++ local open_response = conn._http_open_response; ++ if open_response and not open_response.finished then ++ open_response.finished = true; ++ if open_response.on_destroy then ++ open_response:on_destroy(); ++ end ++ -- Nothing else will finish this response, so release the runner waiting on it ++ open_response:finish_cb(); ++ end + end + + function listener.ondetach(conn) diff -Nru prosody-13.0.1/debian/patches/0040-util.xmppstream-Initialize-SAX-handlers-with-max_ele.patch prosody-13.0.1/debian/patches/0040-util.xmppstream-Initialize-SAX-handlers-with-max_ele.patch --- prosody-13.0.1/debian/patches/0040-util.xmppstream-Initialize-SAX-handlers-with-max_ele.patch 1970-01-01 00:00:00.000000000 +0000 +++ prosody-13.0.1/debian/patches/0040-util.xmppstream-Initialize-SAX-handlers-with-max_ele.patch 2026-12-01 12:43:09.000000000 +0000 @@ -0,0 +1,24 @@ +From: Matthew Wild +Date: Fri, 23 Oct 2026 18:46:57 +0100 +Subject: util.xmppstream: Initialize SAX handlers with max_elements + +Introduced (both the feature and the bug) in 6c7549964d4d +--- + util/xmppstream.lua | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/util/xmppstream.lua b/util/xmppstream.lua +index 4f1e561..e4c122e 100644 +--- a/util/xmppstream.lua ++++ b/util/xmppstream.lua +@@ -277,8 +277,8 @@ local function new(session, stream_callbacks, stanza_size_limit, ex) + + local max_elements = ex and ex.max_elements; + +- local handlers, meta = new_sax_handlers(session, stream_callbacks, handle_progress); +- local parser = new_parser(handlers, ns_separator, false, max_elements); ++ local handlers, meta = new_sax_handlers(session, stream_callbacks, handle_progress, max_elements); ++ local parser = new_parser(handlers, ns_separator, false); + local parse = parser.parse; + + function session.open_stream(session, from, to) -- luacheck: ignore 432/session diff -Nru prosody-13.0.1/debian/patches/0041-util.xmppstream-Preserve-max_elements-if-not-explici.patch prosody-13.0.1/debian/patches/0041-util.xmppstream-Preserve-max_elements-if-not-explici.patch --- prosody-13.0.1/debian/patches/0041-util.xmppstream-Preserve-max_elements-if-not-explici.patch 1970-01-01 00:00:00.000000000 +0000 +++ prosody-13.0.1/debian/patches/0041-util.xmppstream-Preserve-max_elements-if-not-explici.patch 2026-12-01 12:43:09.000000000 +0000 @@ -0,0 +1,26 @@ +From: Matthew Wild +Date: Fri, 23 Oct 2026 18:48:15 +0100 +Subject: util.xmppstream: Preserve max_elements if not explicitly set + +Currently, setting (only) the stanza size limit can unintentionally clear +max_elements. This fixes that, at the cost of not being able to explicitly +disable max_elements... which I think is fine. +--- + util/xmppstream.lua | 4 +++- + 1 file changed, 3 insertions(+), 1 deletion(-) + +diff --git a/util/xmppstream.lua b/util/xmppstream.lua +index e4c122e..23b703f 100644 +--- a/util/xmppstream.lua ++++ b/util/xmppstream.lua +@@ -252,7 +252,9 @@ local function new_sax_handlers(session, stream_callbacks, cb_handleprogress, ma + end + + local function set_max_elements(new_max_elements) +- max_elements = new_max_elements; ++ if new_max_elements ~= nil then ++ max_elements = new_max_elements; ++ end + end + + return xml_handlers, { diff -Nru prosody-13.0.1/debian/patches/0042-util.xmppstream-More-robust-processing-of-stream-abo.patch prosody-13.0.1/debian/patches/0042-util.xmppstream-More-robust-processing-of-stream-abo.patch --- prosody-13.0.1/debian/patches/0042-util.xmppstream-More-robust-processing-of-stream-abo.patch 1970-01-01 00:00:00.000000000 +0000 +++ prosody-13.0.1/debian/patches/0042-util.xmppstream-More-robust-processing-of-stream-abo.patch 2026-12-01 12:43:09.000000000 +0000 @@ -0,0 +1,87 @@ +From: Matthew Wild +Date: Fri, 23 Oct 2026 18:58:51 +0100 +Subject: util.xmppstream: More robust processing of stream aborts + +Per the docs, expat can still call EndElement if XML_StopParser is called +within StartElement ( https://libexpat.github.io/doc/api/latest/#XML_StopParser ). + +This could cause xmppstream to emit incomplete stanzas alongside a stream +error. We now record that parsing has failed, and ignore callbacks. + +It also fixes an off-by-one in the depth counting which only allowed N-1 child +elements, instead of N. +--- + util/xmppstream.lua | 22 +++++++++++++++------- + 1 file changed, 15 insertions(+), 7 deletions(-) + +diff --git a/util/xmppstream.lua b/util/xmppstream.lua +index 23b703f..39a1e25 100644 +--- a/util/xmppstream.lua ++++ b/util/xmppstream.lua +@@ -71,7 +71,15 @@ local function new_sax_handlers(session, stream_callbacks, cb_handleprogress, ma + local stanza_size = 0; + local child_quota = 0; + local non_streamns_depth = 0; ++ local failed = false; ++ local function abort(parser) ++ failed = true; ++ if not parser.stop or not parser:stop() then ++ error("Failed to abort parsing"); ++ end ++ end + function xml_handlers:StartElement(tagname, attr) ++ if failed then return; end + if stanza and #chardata > 0 then + -- We have some character data in the buffer + t_insert(stanza, t_concat(chardata)); +@@ -90,11 +98,9 @@ local function new_sax_handlers(session, stream_callbacks, cb_handleprogress, ma + if stanza and child_quota then + -- Check stanza complexity limits + child_quota = child_quota - 1; +- if child_quota <= 0 then ++ if child_quota < 0 then ++ abort(self); + cb_error(session, "parse-error", "resource-constraint", "Stanza exceeds permitted children"); +- if not self.stop or not self:stop() then +- error("Failed to abort parsing"); +- end + return; + end + end +@@ -167,6 +173,7 @@ local function new_sax_handlers(session, stream_callbacks, cb_handleprogress, ma + end + end + function xml_handlers:CharacterData(data) ++ if failed then return; end + if stanza then + if lxp_supports_bytecount then + stanza_size = stanza_size + self:getcurrentbytecount(); +@@ -177,6 +184,8 @@ local function new_sax_handlers(session, stream_callbacks, cb_handleprogress, ma + end + end + function xml_handlers:EndElement(tagname) ++ -- Expat can still deliver EndElement for an empty tag after stop(). ++ if failed then return; end + if lxp_supports_bytecount then + stanza_size = stanza_size + self:getcurrentbytecount() + end +@@ -218,10 +227,8 @@ local function new_sax_handlers(session, stream_callbacks, cb_handleprogress, ma + end + + local function restricted_handler(parser) ++ abort(parser); + cb_error(session, "parse-error", "restricted-xml", "Restricted XML, see RFC 6120 section 11.1."); +- if not parser.stop or not parser:stop() then +- error("Failed to abort parsing"); +- end + end + + if lxp_supports_xmldecl then +@@ -245,6 +252,7 @@ local function new_sax_handlers(session, stream_callbacks, cb_handleprogress, ma + local function reset() + stanza, chardata, stanza_size = nil, {}, 0; + stack = {}; ++ failed = false; + end + + local function set_session(stream, new_session) -- luacheck: ignore 212/stream diff -Nru prosody-13.0.1/debian/patches/0043-util.xmppstream-Add-tests-for-limits-behaviour.patch prosody-13.0.1/debian/patches/0043-util.xmppstream-Add-tests-for-limits-behaviour.patch --- prosody-13.0.1/debian/patches/0043-util.xmppstream-Add-tests-for-limits-behaviour.patch 1970-01-01 00:00:00.000000000 +0000 +++ prosody-13.0.1/debian/patches/0043-util.xmppstream-Add-tests-for-limits-behaviour.patch 2026-12-01 12:43:09.000000000 +0000 @@ -0,0 +1,106 @@ +From: Matthew Wild +Date: Fri, 23 Oct 2026 19:00:58 +0100 +Subject: util.xmppstream: Add tests for limits behaviour + +--- + spec/util_xmppstream_spec.lua | 89 +++++++++++++++++++++++++++++++++++++++++++ + 1 file changed, 89 insertions(+) + +diff --git a/spec/util_xmppstream_spec.lua b/spec/util_xmppstream_spec.lua +index 38b3cbd..1d18ef5 100644 +--- a/spec/util_xmppstream_spec.lua ++++ b/spec/util_xmppstream_spec.lua +@@ -133,4 +133,93 @@ describe("util.xmppstream", function() + test([[]], false); + end); + end); ++ ++ describe("limits", function () ++ local header = ''; ++ local function new_stream(size_limit, max_elements) ++ local session = { notopen = true }; ++ local state = { stanzas = {}, errors = {}, opened = 0 }; ++ local stream = xmppstream.new(session, { ++ stream_ns = "streamns"; ++ default_ns = "stanzans"; ++ streamopened = function (s) ++ s.notopen = nil; ++ state.opened = state.opened + 1; ++ end; ++ handlestanza = function (_, stanza) table.insert(state.stanzas, stanza); end; ++ error = function (_, ...) table.insert(state.errors, {...}); end; ++ }, size_limit, { max_elements = max_elements }); ++ assert(stream:feed(header)); ++ return stream, state, session; ++ end ++ ++ it("applies the initial descendant limit", function () ++ local stream, state = new_stream(nil, 1); ++ assert.is_nil(stream:feed("")); ++ assert.same({{"parse-error", "resource-constraint", "Stanza exceeds permitted children"}}, state.errors); ++ assert.equal(0, #state.stanzas); ++ end); ++ ++ for _, stanza in ipairs({"", "", ""}) do ++ it("accepts up to the configured number of descendants: "..stanza, function () ++ local stream, state = new_stream(nil, 2); ++ assert(stream:feed(stanza)); ++ assert.equal(1, #state.stanzas); ++ assert.equal(0, #state.errors); ++ end); ++ end ++ ++ it("counts descendants at every depth", function () ++ local stream, state = new_stream(nil, 2); ++ assert.is_nil(stream:feed("")); ++ assert.equal(0, #state.stanzas); ++ end); ++ ++ it("allows zero descendants when configured with zero", function () ++ local stream, state = new_stream(nil, 0); ++ assert(stream:feed("text")); ++ assert.equal(1, #state.stanzas); ++ assert.is_nil(stream:feed("")); ++ assert.equal(1, #state.stanzas); ++ end); ++ ++ it("starts a fresh quota for each stanza", function () ++ local stream, state = new_stream(nil, 1); ++ assert(stream:feed((""):rep(3))); ++ assert.equal(3, #state.stanzas); ++ end); ++ ++ it("preserves the quota when only the byte limit changes", function () ++ local stream, state = new_stream(nil, 1); ++ stream:set_stanza_size_limit(20000); ++ assert.is_nil(stream:feed("")); ++ assert.equal(0, #state.stanzas); ++ end); ++ ++ it("updates the quota for subsequent stanzas", function () ++ local stream, state = new_stream(nil, 0); ++ stream:set_stanza_size_limit(20000, 2); ++ assert(stream:feed("")); ++ assert.equal(1, #state.stanzas); ++ stream:set_stanza_size_limit(20000, 0); ++ assert.is_nil(stream:feed("")); ++ assert.equal(1, #state.stanzas); ++ end); ++ ++ it("preserves the quota across resets", function () ++ local stream, state, session = new_stream(nil, 1); ++ stream:reset(); ++ session.notopen = true; ++ assert(stream:feed(header)); ++ assert.is_nil(stream:feed("")); ++ assert.equal(0, #state.stanzas); ++ end); ++ ++ it("does not limit descendants when no quota is configured", function () ++ local stream, state = new_stream(); ++ assert(stream:feed(""..(""):rep(100).."")); ++ assert.equal(100, #state.stanzas[1].tags); ++ end); ++ end); ++ + end); diff -Nru prosody-13.0.1/debian/patches/0044-util.xmppstream-More-accurate-byte-accounting-for-st.patch prosody-13.0.1/debian/patches/0044-util.xmppstream-More-accurate-byte-accounting-for-st.patch --- prosody-13.0.1/debian/patches/0044-util.xmppstream-More-accurate-byte-accounting-for-st.patch 1970-01-01 00:00:00.000000000 +0000 +++ prosody-13.0.1/debian/patches/0044-util.xmppstream-More-accurate-byte-accounting-for-st.patch 2026-12-01 12:43:09.000000000 +0000 @@ -0,0 +1,344 @@ +From: Matthew Wild +Date: Fri, 23 Oct 2026 19:32:45 +0100 +Subject: util.xmppstream: More accurate byte accounting for stanza size + limits (+ tests) + +Previously, byte accounting (for tracking stanza sizes) occurred between calls +to feed(). This adds fine-grained accounting within the parse itself. + +In the previous code, a stanza could end up slightly larger than the stanza +size limit if sufficient bytes were read within a single packet. This was +known, but deemed a minor issue. + +The following sequence of events lead to an oversized stanza, where 8192 is +assumed to be the read chunk size: + +- Set stanza size limit to 10,000 bytes +- Feed 8192 bytes of an incomplete stanza +- Feed another 1808 bytes -> exactly 10,000 bytes, accepted +- Feed a final 8192 bytes **including the closing tag** -> the 18,192-byte + stanza is delivered and accepted + +How much the limit can be exceeded therefore depends on the chunk size. +--- + spec/util_xmppstream_spec.lua | 107 ++++++++++++++++++++++++++++++++++++++++++ + util/xmppstream.lua | 70 +++++++++++++++++---------- + 2 files changed, 151 insertions(+), 26 deletions(-) + +diff --git a/spec/util_xmppstream_spec.lua b/spec/util_xmppstream_spec.lua +index 1d18ef5..27f6d7d 100644 +--- a/spec/util_xmppstream_spec.lua ++++ b/spec/util_xmppstream_spec.lua +@@ -153,6 +153,8 @@ describe("util.xmppstream", function() + return stream, state, session; + end + ++ -- Element limits ++ + it("applies the initial descendant limit", function () + local stream, state = new_stream(nil, 1); + assert.is_nil(stream:feed("")); +@@ -220,6 +222,111 @@ describe("util.xmppstream", function() + assert(stream:feed(""..(""):rep(100).."")); + assert.equal(100, #state.stanzas[1].tags); + end); ++ ++ -- Byte limits ++ ++ for _, stanza in ipairs({ ++ ''; ++ ""..("x"):rep(100)..""; ++ ""; ++ ""..(""):rep(30)..""; ++ ""..("&🙂\r\n"):rep(10)..""; ++ }) do ++ for _, allowance in ipairs({-1, 0, 1}) do ++ it("enforces the byte limit at "..allowance.." bytes from a "..#stanza.." byte stanza", function () ++ local stream, state = new_stream(#stanza + allowance); ++ local ok, err = stream:feed(stanza); ++ if allowance < 0 then ++ assert.is_nil(ok); ++ assert.equal("stanza-too-large", err); ++ assert.equal(0, #state.stanzas); ++ else ++ assert.truthy(ok); ++ assert.is_nil(err); ++ assert.equal(1, #state.stanzas); ++ end ++ end); ++ end ++ end ++ ++ it("checks a complete stream header before notifying the caller", function () ++ local session = { notopen = true }; ++ local opened = false; ++ local stream = xmppstream.new(session, { ++ stream_ns = "streamns"; ++ streamopened = function () opened = true; end; ++ }, #header - 1); ++ local ok, err = stream:feed(header); ++ assert.is_nil(ok); ++ assert.equal("stanza-too-large", err); ++ assert.is_false(opened); ++ end); ++ ++ it("accounts for a stream header even without an open callback", function () ++ local session = { notopen = true }; ++ local stream = xmppstream.new(session, { stream_ns = "streamns" }, 100); ++ assert(stream:feed(header)); ++ session.notopen = nil; ++ assert(stream:feed(""..("x"):rep(90))); ++ end); ++ ++ it("checks fragmented stanza content before delivery", function () ++ local stream, state = new_stream(100); ++ assert(stream:feed("")); ++ local ok, err = stream:feed(("x"):rep(100)..""); ++ assert.is_nil(ok); ++ assert.equal("stanza-too-large", err); ++ assert.equal(0, #state.stanzas); ++ end); ++ ++ it("counts incomplete tokens toward the size limit", function () ++ local stream, state = new_stream(100); ++ local ok, err = stream:feed(' "):rep(100))); ++ assert.equal(100, #state.stanzas); ++ assert(stream:feed((" "):rep(1000))); ++ assert(stream:feed("")); ++ assert.equal(101, #state.stanzas); ++ end); ++ ++ it("delivers preceding valid stanzas but stops at an oversized one", function () ++ local stream, state = new_stream(100); ++ local ok, err = stream:feed(''..("x"):rep(100)..''); ++ assert.is_nil(ok); ++ assert.equal("stanza-too-large", err); ++ assert.equal(1, #state.stanzas); ++ assert.equal("before", state.stanzas[1].attr.id); ++ end); ++ ++ it("keeps a size failure terminal until reset", function () ++ local stream, state, session = new_stream(100); ++ assert.is_nil(stream:feed(""..("x"):rep(100))); ++ local ok, err = stream:feed(""); ++ assert.is_nil(ok); ++ assert.equal("stanza-too-large", err); ++ assert.equal(0, #state.stanzas); ++ stream:reset(); ++ session.notopen = true; ++ assert(stream:feed(header.."")); ++ assert.equal(1, #state.stanzas); ++ end); ++ ++ it("applies byte limit updates inside the SAX handlers", function () ++ local stream, state = new_stream(1000); ++ stream:set_stanza_size_limit(100); ++ local ok, err = stream:feed(""..("x"):rep(100)..""); ++ assert.is_nil(ok); ++ assert.equal("stanza-too-large", err); ++ assert.equal(0, #state.stanzas); ++ end); ++ + end); + + end); +diff --git a/util/xmppstream.lua b/util/xmppstream.lua +index 39a1e25..eae026f 100644 +--- a/util/xmppstream.lua ++++ b/util/xmppstream.lua +@@ -43,7 +43,7 @@ local ns_pattern = "^([^"..ns_separator.."]*)"..ns_separator.."?(.*)$"; + + local function dummy_cb() end + +-local function new_sax_handlers(session, stream_callbacks, cb_handleprogress, max_elements) ++local function new_sax_handlers(session, stream_callbacks, cb_handleprogress, max_elements, stanza_size_limit) + local xml_handlers = {}; + + local cb_streamopened = stream_callbacks.streamopened; +@@ -71,13 +71,24 @@ local function new_sax_handlers(session, stream_callbacks, cb_handleprogress, ma + local stanza_size = 0; + local child_quota = 0; + local non_streamns_depth = 0; +- local failed = false; +- local function abort(parser) +- failed = true; ++ local failed; ++ local function abort(parser, reason) ++ failed = reason or "parsing aborted"; + if not parser.stop or not parser:stop() then + error("Failed to abort parsing"); + end + end ++ local function add_bytes(parser) ++ -- COMPAT lxp has supported byte counts for some time now ++ if lxp_supports_bytecount then ++ stanza_size = stanza_size + parser:getcurrentbytecount(); ++ if stanza_size_limit and stanza_size > stanza_size_limit then ++ abort(parser, "stanza-too-large"); ++ return false; ++ end ++ end ++ return true; ++ end + function xml_handlers:StartElement(tagname, attr) + if failed then return; end + if stanza and #chardata > 0 then +@@ -116,18 +127,17 @@ local function new_sax_handlers(session, stream_callbacks, cb_handleprogress, ma + end + + if not stanza then --if we are not currently inside a stanza +- if lxp_supports_bytecount then +- stanza_size = self:getcurrentbytecount(); +- end ++ stanza_size = 0; ++ if not add_bytes(self) then return; end + if session.notopen then + if tagname == stream_tag then + non_streamns_depth = 0; + stream_lang = attr["xml:lang"] or stream_lang; ++ if lxp_supports_bytecount then ++ cb_handleprogress(stanza_size); ++ end ++ stanza_size = 0; + if cb_streamopened then +- if lxp_supports_bytecount then +- cb_handleprogress(stanza_size); +- stanza_size = 0; +- end + cb_streamopened(session, attr); + end + else +@@ -143,9 +153,7 @@ local function new_sax_handlers(session, stream_callbacks, cb_handleprogress, ma + stanza = setmetatable({ name = name, attr = attr, tags = {} }, stanza_mt); + child_quota = max_elements; + else -- we are inside a stanza, so add a tag +- if lxp_supports_bytecount then +- stanza_size = stanza_size + self:getcurrentbytecount(); +- end ++ if not add_bytes(self) then return; end + t_insert(stack, stanza); + local oldstanza = stanza; + stanza = setmetatable({ name = name, attr = attr, tags = {} }, stanza_mt); +@@ -155,18 +163,20 @@ local function new_sax_handlers(session, stream_callbacks, cb_handleprogress, ma + end + + function xml_handlers:StartCdataSection() ++ if failed then return; end + if lxp_supports_bytecount then + if stanza then +- stanza_size = stanza_size + self:getcurrentbytecount(); ++ if not add_bytes(self) then return; end + else + cb_handleprogress(self:getcurrentbytecount()); + end + end + end + function xml_handlers:EndCdataSection() ++ if failed then return; end + if lxp_supports_bytecount then + if stanza then +- stanza_size = stanza_size + self:getcurrentbytecount(); ++ if not add_bytes(self) then return; end + else + cb_handleprogress(self:getcurrentbytecount()); + end +@@ -175,9 +185,7 @@ local function new_sax_handlers(session, stream_callbacks, cb_handleprogress, ma + function xml_handlers:CharacterData(data) + if failed then return; end + if stanza then +- if lxp_supports_bytecount then +- stanza_size = stanza_size + self:getcurrentbytecount(); +- end ++ if not add_bytes(self) then return; end + t_insert(chardata, data); + elseif lxp_supports_bytecount then + cb_handleprogress(self:getcurrentbytecount()); +@@ -186,9 +194,7 @@ local function new_sax_handlers(session, stream_callbacks, cb_handleprogress, ma + function xml_handlers:EndElement(tagname) + -- Expat can still deliver EndElement for an empty tag after stop(). + if failed then return; end +- if lxp_supports_bytecount then +- stanza_size = stanza_size + self:getcurrentbytecount() +- end ++ if not add_bytes(self) then return; end + if non_streamns_depth > 0 then + non_streamns_depth = non_streamns_depth - 1; + end +@@ -233,9 +239,12 @@ local function new_sax_handlers(session, stream_callbacks, cb_handleprogress, ma + + if lxp_supports_xmldecl then + function xml_handlers:XmlDecl(version, encoding, standalone) ++ if failed then return; end ++ if not add_bytes(self) then return; end + if lxp_supports_bytecount then +- cb_handleprogress(self:getcurrentbytecount()); ++ cb_handleprogress(stanza_size); + end ++ stanza_size = 0; + if (encoding and encoding:lower() ~= "utf-8") + or (standalone == "no") + or (version and version ~= "1.0") then +@@ -252,7 +261,7 @@ local function new_sax_handlers(session, stream_callbacks, cb_handleprogress, ma + local function reset() + stanza, chardata, stanza_size = nil, {}, 0; + stack = {}; +- failed = false; ++ failed = nil; + end + + local function set_session(stream, new_session) -- luacheck: ignore 212/stream +@@ -269,6 +278,9 @@ local function new_sax_handlers(session, stream_callbacks, cb_handleprogress, ma + reset = reset; + set_session = set_session; + set_max_elements = set_max_elements; ++ set_stanza_size_limit = function (limit) stanza_size_limit = limit; end; ++ get_error = function () return failed; end; ++ set_error = function (reason) failed = reason; end; + }; + end + +@@ -287,7 +299,7 @@ local function new(session, stream_callbacks, stanza_size_limit, ex) + + local max_elements = ex and ex.max_elements; + +- local handlers, meta = new_sax_handlers(session, stream_callbacks, handle_progress, max_elements); ++ local handlers, meta = new_sax_handlers(session, stream_callbacks, handle_progress, max_elements, stanza_size_limit); + local parser = new_parser(handlers, ns_separator, false); + local parse = parser.parse; + +@@ -317,12 +329,15 @@ local function new(session, stream_callbacks, stanza_size_limit, ex) + meta.reset(); + end, + feed = function (self, data) -- luacheck: ignore 212/self ++ if meta.get_error() then return nil, meta.get_error(); end + if lxp_supports_bytecount then + n_outstanding_bytes = n_outstanding_bytes + #data; + end + local _parser = parser; + local ok, err = parse(_parser, data); ++ if meta.get_error() then return nil, meta.get_error(); end + if lxp_supports_bytecount and n_outstanding_bytes > stanza_size_limit then ++ meta.set_error("stanza-too-large"); + return nil, "stanza-too-large"; + end + if parser ~= _parser then +@@ -333,7 +348,10 @@ local function new(session, stream_callbacks, stanza_size_limit, ex) + end, + set_session = meta.set_session; + set_stanza_size_limit = function (_, new_stanza_size_limit, new_max_elements) +- stanza_size_limit = new_stanza_size_limit; ++ if new_stanza_size_limit ~= nil then ++ stanza_size_limit = new_stanza_size_limit; ++ meta.set_stanza_size_limit(new_stanza_size_limit); ++ end + meta.set_max_elements(new_max_elements); + end; + }; diff -Nru prosody-13.0.1/debian/patches/0045-net.http.parser-Avoid-responding-twice-to-some-HTTP-.patch prosody-13.0.1/debian/patches/0045-net.http.parser-Avoid-responding-twice-to-some-HTTP-.patch --- prosody-13.0.1/debian/patches/0045-net.http.parser-Avoid-responding-twice-to-some-HTTP-.patch 1970-01-01 00:00:00.000000000 +0000 +++ prosody-13.0.1/debian/patches/0045-net.http.parser-Avoid-responding-twice-to-some-HTTP-.patch 2026-12-01 12:43:09.000000000 +0000 @@ -0,0 +1,37 @@ +From: Matthew Wild +Date: Tue, 17 Nov 2026 17:05:23 +0000 +Subject: net.http.parser: Avoid responding twice to some HTTP requests + +In situations where we respond to a request immediately after the headers +(e.g. the 404 when no handlers are found, or when mod_http_file_share rejects +an upload) the response could be sent to the client twice. +--- + net/http/server.lua | 8 ++++++++ + 1 file changed, 8 insertions(+) + +diff --git a/net/http/server.lua b/net/http/server.lua +index 61821e2..a250a4e 100644 +--- a/net/http/server.lua ++++ b/net/http/server.lua +@@ -246,6 +246,11 @@ function _M.hijack_response(response, listener) -- luacheck: ignore + end + function handle_request(conn, request, finish_cb) + --log("debug", "handler: %s", request.path); ++ local early_response = request.early_response; ++ if early_response and early_response.finished then ++ -- Already answered when only the headers had arrived, the body has now been read ++ return finish_cb(); ++ end + local headers = {}; + for k,v in pairs(request.headers) do headers[k:gsub("-", "_")] = v; end + request.headers = headers; +@@ -285,6 +290,9 @@ function handle_request(conn, request, finish_cb) + finish_cb = finish_cb; + }; + conn._http_open_response = response; ++ if request.partial then ++ request.early_response = response; ++ end + + local host = request.headers.host; + if host then host = host:gsub(":%d+$",""); end diff -Nru prosody-13.0.1/debian/patches/0046-net.http-Normalize-URI-scheme-fixes-2018.patch prosody-13.0.1/debian/patches/0046-net.http-Normalize-URI-scheme-fixes-2018.patch --- prosody-13.0.1/debian/patches/0046-net.http-Normalize-URI-scheme-fixes-2018.patch 1970-01-01 00:00:00.000000000 +0000 +++ prosody-13.0.1/debian/patches/0046-net.http-Normalize-URI-scheme-fixes-2018.patch 2026-12-01 12:43:09.000000000 +0000 @@ -0,0 +1,52 @@ +From: Kim Alvefur +Date: Fri, 20 Nov 2026 15:49:01 +0100 +Subject: net.http: Normalize URI scheme, fixes #2018 + +Prevent treating httpS and similar mixed casing as plain http, which +could lead to CWE-319. + +Requiring a scheme to be present also prevents an error upper-casing it +for a log call later. +--- + net/http.lua | 8 +++++++- + net/http/errors.lua | 4 ++++ + 2 files changed, 11 insertions(+), 1 deletion(-) + +diff --git a/net/http.lua b/net/http.lua +index 35a92d5..1a723e4 100644 +--- a/net/http.lua ++++ b/net/http.lua +@@ -230,11 +230,17 @@ end + local function request(self, u, ex, callback) + local req = url.parse(u); + +- if not (req and req.host) then ++ if not (req and req.host and req.scheme) then + callback("invalid-url", 0, req); + return nil, "invalid-url"; + end + ++ req.scheme = req.scheme:lower(); ++ if req.scheme ~= "http" and req.scheme ~= "https" then ++ callback("unsupported-scheme", 0, req); ++ return nil, "unsupported-scheme"; ++ end ++ + req.url = u; + req.http = self; + req.time = os_time(); +diff --git a/net/http/errors.lua b/net/http/errors.lua +index ca5f0cc..ee6236c 100644 +--- a/net/http/errors.lua ++++ b/net/http/errors.lua +@@ -40,6 +40,10 @@ local error_templates = { + code = 0, type = "modify", condition = "bad-request"; + text = "Invalid URL"; + }; ++ ["unsupported-scheme"] = { ++ code = 0, type = "modify", condition = "bad-request"; ++ text = "Unsupported URL scheme"; ++ }; + ["unable to resolve service"] = { + code = 0, type = "cancel", condition = "remote-server-not-found"; + text = "DNS resolution failed"; diff -Nru prosody-13.0.1/debian/patches/0047-mod_bosh-Apply-c2s_max_child_elements-to-BOSH-stream.patch prosody-13.0.1/debian/patches/0047-mod_bosh-Apply-c2s_max_child_elements-to-BOSH-stream.patch --- prosody-13.0.1/debian/patches/0047-mod_bosh-Apply-c2s_max_child_elements-to-BOSH-stream.patch 1970-01-01 00:00:00.000000000 +0000 +++ prosody-13.0.1/debian/patches/0047-mod_bosh-Apply-c2s_max_child_elements-to-BOSH-stream.patch 2026-12-01 12:43:09.000000000 +0000 @@ -0,0 +1,31 @@ +From: Matthew Wild +Date: Mon, 23 Nov 2026 16:46:24 +0000 +Subject: mod_bosh: Apply c2s_max_child_elements to BOSH streams + +--- + plugins/mod_bosh.lua | 5 ++++- + 1 file changed, 4 insertions(+), 1 deletion(-) + +diff --git a/plugins/mod_bosh.lua b/plugins/mod_bosh.lua +index 937e2a5..6e009a9 100644 +--- a/plugins/mod_bosh.lua ++++ b/plugins/mod_bosh.lua +@@ -46,6 +46,7 @@ local bosh_max_wait = module:get_option_period("bosh_max_wait", 120); + local consider_bosh_secure = module:get_option_boolean("consider_bosh_secure"); + local cross_domain = module:get_option("cross_domain_bosh"); + local unauthed_stanza_size_limit = module:get_option_integer("c2s_stanza_size_limit", 10000, 1000); ++local max_child_elements = module:get_option_integer("c2s_max_child_elements", 25000, 0); + + if cross_domain ~= nil then + module:log("info", "The 'cross_domain_bosh' option has been deprecated"); +@@ -123,7 +124,9 @@ function handle_POST(event) + local body = request.body; + + local context = { request = request, response = response, notopen = true }; +- local stream = new_xmpp_stream(context, stream_callbacks, unauthed_stanza_size_limit); ++ local stream = new_xmpp_stream(context, stream_callbacks, unauthed_stanza_size_limit, { ++ max_elements = max_child_elements; ++ }); + response.context = context; + context.stream = stream; + diff -Nru prosody-13.0.1/debian/patches/0048-mod_component-Apply-component-s2s-_max_child_element.patch prosody-13.0.1/debian/patches/0048-mod_component-Apply-component-s2s-_max_child_element.patch --- prosody-13.0.1/debian/patches/0048-mod_component-Apply-component-s2s-_max_child_element.patch 1970-01-01 00:00:00.000000000 +0000 +++ prosody-13.0.1/debian/patches/0048-mod_component-Apply-component-s2s-_max_child_element.patch 2026-12-01 12:43:09.000000000 +0000 @@ -0,0 +1,38 @@ +From: Matthew Wild +Date: Mon, 23 Nov 2026 16:48:41 +0000 +Subject: mod_component: Apply (component|s2s)_max_child_elements to component + streams + +Components are generally trusted, so I wouldn't call a limit strictly +necessary here. However I decided it's worth having for consistency, and we +also don't really want components able to emit stanzas that we can't actually +send over most s2s links. Also, the limits are designed to protect Prosody +from extreme cases - the component doesn't have to be malicious, it could just +be broken. +--- + plugins/mod_component.lua | 5 ++++- + 1 file changed, 4 insertions(+), 1 deletion(-) + +diff --git a/plugins/mod_component.lua b/plugins/mod_component.lua +index 51c7323..acf45a3 100644 +--- a/plugins/mod_component.lua ++++ b/plugins/mod_component.lua +@@ -29,6 +29,7 @@ local log = module._log; + local opt_keepalives = module:get_option_boolean("component_tcp_keepalives", module:get_option_boolean("tcp_keepalives", true)); + local stanza_size_limit = module:get_option_integer("component_stanza_size_limit", + module:get_option_integer("s2s_stanza_size_limit", 1024 * 512, 10000), 10000); ++local max_child_elements = module:get_option_integer("component_max_child_elements", module:get_option_integer("s2s_max_child_elements", 25000, 0), 0); + + local sessions = module:shared("sessions"); + +@@ -305,7 +306,9 @@ function listener.onconnect(conn) + + session.log("info", "Incoming Jabber component connection"); + +- local stream = new_xmpp_stream(session, stream_callbacks, stanza_size_limit); ++ local stream = new_xmpp_stream(session, stream_callbacks, stanza_size_limit, { ++ max_child_elements = max_child_elements; ++ }); + session.stream = stream; + + session.notopen = true; diff -Nru prosody-13.0.1/debian/patches/0049-mod_pep-Don-t-send-notifications-to-contacts-that-no.patch prosody-13.0.1/debian/patches/0049-mod_pep-Don-t-send-notifications-to-contacts-that-no.patch --- prosody-13.0.1/debian/patches/0049-mod_pep-Don-t-send-notifications-to-contacts-that-no.patch 1970-01-01 00:00:00.000000000 +0000 +++ prosody-13.0.1/debian/patches/0049-mod_pep-Don-t-send-notifications-to-contacts-that-no.patch 2026-12-01 12:43:09.000000000 +0000 @@ -0,0 +1,550 @@ +From: Matthew Wild +Date: Mon, 23 Nov 2026 19:57:08 +0000 +Subject: mod_pep: Don't send notifications to contacts that no longer have + permission to be subscribed + +Explicit subscriptions could remain even after a contact had been removed from +the roster, and they would continue to receive notifications from the node, +even though some actions (such as get-item) would be correctly forbidden. + +The core fix is the broadcast filter. This feels a bit hacky - why not just +clean up the subscription when the roster item is removed? Well, it's complicated... + +I've added a roster removal handler which will actually do that. But it's not +a complete solution on its own. For example: + +- it won't handle access_model=presence and a roster item that remains but has a revoked subscription +- it won't handle access_model=roster and a roster item that changes group +- roster-item-removed doesn't fire for all roster removals, only client-initiated ones +- roster-item-removed fires before the roster write succeeds + +I also considered automatically cleaning up subscriptions when be_subscribed +fails. But this felt potentially even more hacky. E.g. if a user revokes and +then re-approves a contact, the subscription would exist or not exist depending +on whether an item was published in the meantime. It also seems wrong to have +the filter have side-effects like this, and I'm not sure that it wouldn't break +stuff. + +In trunk we could potentially add hooks for all the cases where a roster item +changes, and update explicit subscriptions accordingly. But that was too big +a change for 13.0. +--- + plugins/mod_pep.lua | 30 ++- + .../scansion/pep_explicit_subscription_revoked.scs | 171 +++++++++++++ + .../pep_explicit_subscription_roster_remove.scs | 275 +++++++++++++++++++++ + 3 files changed, 474 insertions(+), 2 deletions(-) + create mode 100644 spec/scansion/pep_explicit_subscription_revoked.scs + create mode 100644 spec/scansion/pep_explicit_subscription_roster_remove.scs + +diff --git a/plugins/mod_pep.lua b/plugins/mod_pep.lua +index b0dfe42..e0b2556 100644 +--- a/plugins/mod_pep.lua ++++ b/plugins/mod_pep.lua +@@ -184,14 +184,19 @@ end + + local function get_subscriber_filter(username) + return function (jids, node) ++ local service = services[username]; + local broadcast_to = {}; + for jid, opts in pairs(jids) do +- broadcast_to[jid] = opts; ++ -- This filters out contacts which have an explicit subscription but ++ -- may no longer have permissions (for various reasons - permissions ++ -- may be complex) ++ if service:may(node, jid, "be_subscribed") then ++ broadcast_to[jid] = opts; ++ end + end + + local service_recipients = recipients[username]; + if service_recipients then +- local service = services[username]; + for recipient, nodes in pairs(service_recipients) do + if nodes:contains(node) and service:may(node, recipient, "subscribe") then + broadcast_to[recipient] = true; +@@ -414,6 +419,27 @@ module:hook("presence/bare", function(event) + end + end, 10); + ++-- Cancel explicit subscriptions of a contact removed from the roster, to ++-- nodes they could only access by being in the roster (XEP-0163 ยง7.1) ++module:hook("roster-item-removed", function (event) ++ local username, contact = event.username, event.jid; ++ local service = get_pep_service(username); ++ local subscriptions = service.subscriptions[contact]; ++ if not subscriptions then return; end ++ for jid, nodes in pairs(subscriptions) do ++ for node in pairs(nodes) do ++ -- The contact is still in the roster at this point, so service:may() ++ -- cannot tell us whether they are about to lose access ++ local node_obj = service.nodes[node]; -- nil if the node was deleted ++ local access_model = node_obj and node_obj.config.access_model; ++ if (access_model == "presence" or access_model == "roster") and not node_obj.affiliations[contact] then ++ module:log("debug", "Cancelling subscription of %s to %s of %s", jid, node, username); ++ service:remove_subscription(node, true, jid); ++ end ++ end ++ end ++end); ++ + module:hook("iq-result/bare/disco", function(event) + local origin, stanza = event.origin, event.stanza; + local disco = stanza:get_child("query", "http://jabber.org/protocol/disco#info"); +diff --git a/spec/scansion/pep_explicit_subscription_revoked.scs b/spec/scansion/pep_explicit_subscription_revoked.scs +new file mode 100644 +index 0000000..4b1a9b6 +--- /dev/null ++++ b/spec/scansion/pep_explicit_subscription_revoked.scs +@@ -0,0 +1,171 @@ ++# PEP: explicit subscription stops receiving notifications when presence subscription is revoked ++ ++[Client] Juliet ++ jid: pep-revoke-juliet@localhost ++ password: password ++ ++[Client] Romeo ++ jid: pep-revoke-romeo@localhost ++ password: password ++ ++----- ++ ++Juliet connects ++ ++Juliet sends: ++ ++ ++Juliet receives: ++ ++ ++Romeo connects ++ ++Romeo sends: ++ ++ ++Romeo receives: ++ ++ ++# Node with the default access model, 'presence' ++ ++Juliet sends: ++ ++ ++ ++ ++ one ++ ++ ++ ++ ++ ++Juliet receives: ++ ++ ++ ++ ++ ++ ++ ++ ++# Romeo gets a subscription to Juliet's presence ++ ++Romeo sends: ++ ++ ++Romeo receives: ++ ++ ++Juliet receives: ++ ++ ++Juliet sends: ++ ++ ++Romeo receives: ++ ++ ++ ++ ++ ++ ++ ++# Which allows him to explicitly subscribe to the node ++ ++Romeo sends: ++ ++ ++ ++ ++ ++ ++Romeo receives: ++ ++ ++ ++ ++ ++ ++Romeo receives: ++ ++ ++ ++ ++ one ++ ++ ++ ++ ++ ++Juliet sends: ++ ++ ++ ++ ++ two ++ ++ ++ ++ ++ ++Romeo receives: ++ ++ ++ ++ ++ two ++ ++ ++ ++ ++ ++Juliet receives: ++ ++ ++ ++ ++ ++ ++ ++ ++# Juliet revokes Romeo's presence subscription ++ ++Juliet sends: ++ ++ ++Romeo receives: ++ ++ ++Juliet sends: ++ ++ ++ ++ ++ three ++ ++ ++ ++ ++ ++Juliet receives: ++ ++ ++ ++ ++ ++ ++ ++ ++# Romeo must not have been notified, so the next thing he sees is the reply to this ++ ++Romeo sends: ++ ++ ++ ++ ++Romeo receives: ++ ++ ++Juliet disconnects ++ ++Romeo disconnects +diff --git a/spec/scansion/pep_explicit_subscription_roster_remove.scs b/spec/scansion/pep_explicit_subscription_roster_remove.scs +new file mode 100644 +index 0000000..7b8bf13 +--- /dev/null ++++ b/spec/scansion/pep_explicit_subscription_roster_remove.scs +@@ -0,0 +1,275 @@ ++# PEP: explicit subscriptions are cancelled when the subscriber is removed from the roster ++ ++[Client] Juliet ++ jid: pep-remove-juliet@localhost ++ password: password ++ ++[Client] Romeo ++ jid: pep-remove-romeo@localhost ++ password: password ++ ++----- ++ ++Juliet connects ++ ++Juliet sends: ++ ++ ++Juliet receives: ++ ++ ++Romeo connects ++ ++Romeo sends: ++ ++ ++Romeo receives: ++ ++ ++# Node with the default access model, 'presence' ++ ++Juliet sends: ++ ++ ++ ++ ++ one ++ ++ ++ ++ ++ ++Juliet receives: ++ ++ ++ ++ ++ ++ ++ ++ ++# Romeo gets a subscription to Juliet's presence ++ ++Romeo sends: ++ ++ ++Romeo receives: ++ ++ ++Juliet receives: ++ ++ ++Juliet sends: ++ ++ ++Romeo receives: ++ ++ ++ ++ ++ ++ ++ ++# Which allows him to explicitly subscribe to the node ++ ++Romeo sends: ++ ++ ++ ++ ++ ++ ++Romeo receives: ++ ++ ++ ++ ++ ++ ++Romeo receives: ++ ++ ++ ++ ++ one ++ ++ ++ ++ ++ ++# And to a second node, which has the 'open' access model ++ ++Juliet sends: ++ ++ ++ ++ ++ hello ++ ++ ++ ++ ++ ++ http://jabber.org/protocol/pubsub#publish-options ++ ++ ++ open ++ ++ ++ ++ ++ ++ ++Juliet receives: ++ ++ ++ ++ ++ ++ ++ ++ ++Romeo sends: ++ ++ ++ ++ ++ ++ ++Romeo receives: ++ ++ ++ ++ ++ ++ ++Romeo receives: ++ ++ ++ ++ ++ hello ++ ++ ++ ++ ++ ++Juliet sends: ++ ++ ++ ++ ++ ++ ++Juliet receives: ++ ++ ++ ++ ++ ++ ++ ++ ++# Juliet removes Romeo from her roster ++ ++Juliet sends: ++ ++ ++ ++ ++ ++ ++Romeo receives: ++ ++ ++Juliet receives: ++ ++ ++# The subscription he can no longer have is cancelled, the other is kept ++ ++Juliet sends: ++ ++ ++ ++ ++ ++ ++Juliet receives: ++ ++ ++ ++ ++ ++ ++Juliet sends: ++ ++ ++ ++ ++ ++ ++Juliet receives: ++ ++ ++ ++ ++ ++ ++ ++ ++Juliet sends: ++ ++ ++ ++ ++ two ++ ++ ++ ++ ++ ++Juliet receives: ++ ++ ++ ++ ++ ++ ++ ++ ++# Romeo must not be notified of that, so the next thing he sees is this ++ ++Juliet sends: ++ ++ ++ ++ ++ world ++ ++ ++ ++ ++ ++Romeo receives: ++ ++ ++ ++ ++ world ++ ++ ++ ++ ++ ++Juliet receives: ++ ++ ++ ++ ++ ++ ++ ++ ++Juliet disconnects ++ ++Romeo disconnects diff -Nru prosody-13.0.1/debian/patches/0050-util.xmppstream-Discard-data-and-callbacks-after-a-s.patch prosody-13.0.1/debian/patches/0050-util.xmppstream-Discard-data-and-callbacks-after-a-s.patch --- prosody-13.0.1/debian/patches/0050-util.xmppstream-Discard-data-and-callbacks-after-a-s.patch 1970-01-01 00:00:00.000000000 +0000 +++ prosody-13.0.1/debian/patches/0050-util.xmppstream-Discard-data-and-callbacks-after-a-s.patch 2026-12-01 12:43:09.000000000 +0000 @@ -0,0 +1,129 @@ +From: Matthew Wild +Date: Mon, 23 Nov 2026 20:17:42 +0000 +Subject: util.xmppstream: Discard data and callbacks after a stream reset + +If data was still pending in the buffer after a stream reset was issued, it +could continue to trigger callbacks on the new stream. +--- + util/xmppstream.lua | 68 ++++++++++++++++++++++++++++++++++++++++++----------- + 1 file changed, 54 insertions(+), 14 deletions(-) + +diff --git a/util/xmppstream.lua b/util/xmppstream.lua +index eae026f..a68bfe6 100644 +--- a/util/xmppstream.lua ++++ b/util/xmppstream.lua +@@ -16,6 +16,7 @@ local t_insert = table.insert; + local t_concat = table.concat; + local t_remove = table.remove; + local setmetatable = setmetatable; ++local pcall = pcall; + + -- COMPAT: w/LuaExpat 1.1.0 + local lxp_supports_doctype = pcall(lxp.new, { StartDoctypeDecl = false }); +@@ -233,6 +234,7 @@ local function new_sax_handlers(session, stream_callbacks, cb_handleprogress, ma + end + + local function restricted_handler(parser) ++ if failed then return; end + abort(parser); + cb_error(session, "parse-error", "restricted-xml", "Restricted XML, see RFC 6120 section 11.1."); + end +@@ -299,9 +301,17 @@ local function new(session, stream_callbacks, stanza_size_limit, ex) + + local max_elements = ex and ex.max_elements; + +- local handlers, meta = new_sax_handlers(session, stream_callbacks, handle_progress, max_elements, stanza_size_limit); +- local parser = new_parser(handlers, ns_separator, false); +- local parse = parser.parse; ++ -- Each parser gets its own SAX handlers, so that a parser replaced by ++ -- reset() shares no state with the new stream ++ local parser, parse, meta; ++ local function new_stream_parser() ++ local handlers; ++ handlers, meta = new_sax_handlers(session, stream_callbacks, handle_progress, max_elements, stanza_size_limit); ++ parser = new_parser(handlers, ns_separator, false); ++ parse = parser.parse; ++ end ++ new_stream_parser(); ++ local parsing; -- The parser currently inside parse(), if any + + function session.open_stream(session, from, to) -- luacheck: ignore 432/session + local send = session.sends2s or session.send; +@@ -323,36 +333,66 @@ local function new(session, stream_callbacks, stanza_size_limit, ex) + + return { + reset = function () +- parser = new_parser(handlers, ns_separator, false); +- parse = parser.parse; ++ local old_parser = parser; ++ -- Ignore any further events from the old parser. If we are being called ++ -- from one of its callbacks, this discards the rest of the data it was ++ -- fed: that was sent before the new stream began, so is not part of it. ++ meta.set_error("parsing aborted"); ++ if old_parser == parsing and old_parser.stop then ++ old_parser:stop(); ++ end ++ new_stream_parser(); + n_outstanding_bytes = 0; +- meta.reset(); + end, + feed = function (self, data) -- luacheck: ignore 212/self + if meta.get_error() then return nil, meta.get_error(); end ++ if parser == parsing then ++ -- Called from a callback of this parser, which it cannot recover from ++ meta.set_error("parsing aborted"); ++ if parser.stop then parser:stop(); end ++ return nil, "parsing aborted"; ++ end + if lxp_supports_bytecount then + n_outstanding_bytes = n_outstanding_bytes + #data; + end +- local _parser = parser; +- local ok, err = parse(_parser, data); ++ local _parser, outer_parser = parser, parsing; ++ parsing = _parser; ++ local success, ok, err = pcall(parse, _parser, data); ++ parsing = outer_parser; ++ local was_reset = parser ~= _parser; ++ if was_reset then ++ _parser:parse(); ++ _parser:close(); ++ end ++ if not success then ++ error(ok, 0); ++ end ++ -- After a reset, this is the state of the new stream + if meta.get_error() then return nil, meta.get_error(); end ++ if was_reset then return true; end ++ if not ok then ++ meta.set_error(err); ++ return nil, err; ++ end + if lxp_supports_bytecount and n_outstanding_bytes > stanza_size_limit then + meta.set_error("stanza-too-large"); + return nil, "stanza-too-large"; + end +- if parser ~= _parser then +- _parser:parse(); +- _parser:close(); +- end + return ok, err; + end, +- set_session = meta.set_session; ++ set_session = function (stream, new_session) ++ session = new_session; ++ return meta.set_session(stream, new_session); ++ end; + set_stanza_size_limit = function (_, new_stanza_size_limit, new_max_elements) + if new_stanza_size_limit ~= nil then + stanza_size_limit = new_stanza_size_limit; + meta.set_stanza_size_limit(new_stanza_size_limit); + end +- meta.set_max_elements(new_max_elements); ++ if new_max_elements ~= nil then ++ max_elements = new_max_elements; ++ meta.set_max_elements(new_max_elements); ++ end + end; + }; + end diff -Nru prosody-13.0.1/debian/patches/0051-MUC-Don-t-relay-arbitrary-child-elements-in-mediated.patch prosody-13.0.1/debian/patches/0051-MUC-Don-t-relay-arbitrary-child-elements-in-mediated.patch --- prosody-13.0.1/debian/patches/0051-MUC-Don-t-relay-arbitrary-child-elements-in-mediated.patch 1970-01-01 00:00:00.000000000 +0000 +++ prosody-13.0.1/debian/patches/0051-MUC-Don-t-relay-arbitrary-child-elements-in-mediated.patch 2026-12-01 12:43:09.000000000 +0000 @@ -0,0 +1,171 @@ +From: Matthew Wild +Date: Tue, 24 Nov 2026 14:16:22 +0000 +Subject: MUC: Don't relay arbitrary child elements in mediated + invites/declines + +--- + plugins/muc/muc.lib.lua | 11 +- + .../scansion/muc_mediated_invite_decline_relay.scs | 125 +++++++++++++++++++++ + 2 files changed, 130 insertions(+), 6 deletions(-) + create mode 100644 spec/scansion/muc_mediated_invite_decline_relay.scs + +diff --git a/plugins/muc/muc.lib.lua b/plugins/muc/muc.lib.lua +index 4c438ed..0ab08dc 100644 +--- a/plugins/muc/muc.lib.lua ++++ b/plugins/muc/muc.lib.lua +@@ -1293,9 +1293,9 @@ function room_mt:handle_mediated_invite(origin, stanza) + elseif module:fire_event("muc-pre-invite", {room = self, origin = origin, stanza = stanza}) then + return true; + end +- local invite = muc_util.filter_muc_x(st.clone(stanza)); +- invite.attr.from = self.jid; +- invite.attr.to = invitee; ++ -- Built from scratch, so that nothing else in the inviter's message is ++ -- sent from the room's JID ++ local invite = st.message({ from = self.jid; to = invitee; id = stanza.attr.id }); + invite:tag('x', {xmlns='http://jabber.org/protocol/muc#user'}) + :tag('invite', {from = stanza.attr.from;}) + :tag('reason'):text(payload:get_child_text("reason")):up() +@@ -1338,9 +1338,8 @@ function room_mt:handle_mediated_decline(origin, stanza) + elseif module:fire_event("muc-pre-decline", {room = self, origin = origin, stanza = stanza}) then + return true; + end +- local decline = muc_util.filter_muc_x(st.clone(stanza)); +- decline.attr.from = self.jid; +- decline.attr.to = declinee; ++ -- Built from scratch, as for invites ++ local decline = st.message({ from = self.jid; to = declinee; id = stanza.attr.id }); + decline:tag("x", {xmlns = "http://jabber.org/protocol/muc#user"}) + :tag("decline", {from = stanza.attr.from}) + :tag("reason"):text(payload:get_child_text("reason")):up() +diff --git a/spec/scansion/muc_mediated_invite_decline_relay.scs b/spec/scansion/muc_mediated_invite_decline_relay.scs +new file mode 100644 +index 0000000..a13f1ff +--- /dev/null ++++ b/spec/scansion/muc_mediated_invite_decline_relay.scs +@@ -0,0 +1,125 @@ ++# MUC: Mediated invites and declines must not relay arbitrary children of the sender's message from the room's JID ++ ++[Client] Romeo ++ jid: user@localhost ++ password: password ++ ++[Client] Juliet ++ jid: user2@localhost ++ password: password ++ ++[Client] Victim ++ jid: user3@localhost/victim ++ password: password ++ ++----- ++ ++Romeo connects ++ ++Romeo sends: ++ ++ ++ ++ ++Romeo receives: ++ ++ ++ ++ ++ ++ ++ ++ ++Romeo receives: ++ ++ ++Romeo sends: ++ ++ ++ ++ ++ http://jabber.org/protocol/muc#roomconfig ++ ++ ++ ++ ++ ++Romeo receives: ++ ++ ++Juliet connects ++ ++Juliet sends: ++ ++ ++ ++ ++Juliet receives: ++ ++ ++Juliet receives: ++ ++ ++Juliet receives: ++ ++ ++Romeo receives: ++ ++ ++Victim connects ++ ++Victim sends: ++ ++ ++Victim receives: ++ ++ ++# Juliet, an unaffiliated participant, smuggles extra children in an invite. ++# The invitee must get the generated body, not Juliet's. This is not a strict ++# match, as the order of and varies. ++Juliet sends: ++ ++ ++ ++ ++ Forged subject ++ Forged body from the room ++ t1 ++ ++ ++ ++ ++Victim receives: ++ ++ ++ ++ ++ room@conference.localhost/Juliet invited you to the room room@conference.localhost ++ ++ ++ ++# Declines are built the same way, and any JID may send them. ++# Only the decline itself may reach the target. ++Victim sends: ++ ++ ++ ++ ++ Forged subject ++ Forged body from the room ++ ++ ++ ++Juliet receives: ++ ++ ++ ++ ++ user3@localhost/victim declined your invite to the room room@conference.localhost ++ ++ ++Victim disconnects ++ ++Juliet disconnects ++ ++Romeo disconnects diff -Nru prosody-13.0.1/debian/patches/0052-mod_component-Fix-overly-long-line-luacheck.patch prosody-13.0.1/debian/patches/0052-mod_component-Fix-overly-long-line-luacheck.patch --- prosody-13.0.1/debian/patches/0052-mod_component-Fix-overly-long-line-luacheck.patch 1970-01-01 00:00:00.000000000 +0000 +++ prosody-13.0.1/debian/patches/0052-mod_component-Fix-overly-long-line-luacheck.patch 2026-12-01 12:43:09.000000000 +0000 @@ -0,0 +1,23 @@ +From: Matthew Wild +Date: Tue, 24 Nov 2026 19:34:16 +0000 +Subject: mod_component: Fix overly long line #luacheck + +--- + plugins/mod_component.lua | 4 +++- + 1 file changed, 3 insertions(+), 1 deletion(-) + +diff --git a/plugins/mod_component.lua b/plugins/mod_component.lua +index acf45a3..60b2b13 100644 +--- a/plugins/mod_component.lua ++++ b/plugins/mod_component.lua +@@ -29,7 +29,9 @@ local log = module._log; + local opt_keepalives = module:get_option_boolean("component_tcp_keepalives", module:get_option_boolean("tcp_keepalives", true)); + local stanza_size_limit = module:get_option_integer("component_stanza_size_limit", + module:get_option_integer("s2s_stanza_size_limit", 1024 * 512, 10000), 10000); +-local max_child_elements = module:get_option_integer("component_max_child_elements", module:get_option_integer("s2s_max_child_elements", 25000, 0), 0); ++local max_child_elements = module:get_option_integer("component_max_child_elements", ++ module:get_option_integer("s2s_max_child_elements", 25000, 0), 0 ++); + + local sessions = module:shared("sessions"); + diff -Nru prosody-13.0.1/debian/patches/0053-mod_register_ibr-Fire-event-on-registration-failure.patch prosody-13.0.1/debian/patches/0053-mod_register_ibr-Fire-event-on-registration-failure.patch --- prosody-13.0.1/debian/patches/0053-mod_register_ibr-Fire-event-on-registration-failure.patch 1970-01-01 00:00:00.000000000 +0000 +++ prosody-13.0.1/debian/patches/0053-mod_register_ibr-Fire-event-on-registration-failure.patch 2026-12-01 12:43:09.000000000 +0000 @@ -0,0 +1,66 @@ +From: Matthew Wild +Date: Wed, 25 Nov 2026 09:32:44 +0000 +Subject: mod_register_ibr: Fire event on registration failure + +This is necessary to allow cleanup in modules which do stuff in the +user-registering event, such as invite validation and consumption. +--- + core/features.lua | 3 +++ + plugins/mod_register_ibr.lua | 5 +++++ + 2 files changed, 8 insertions(+) + +diff --git a/core/features.lua b/core/features.lua +index 8e155f7..da01c97 100644 +--- a/core/features.lua ++++ b/core/features.lua +@@ -37,5 +37,8 @@ return { + + -- SIGUSR1 and 2 events + "signal-events"; ++ ++ -- user-registration-failed event in mod_register_ibr ++ "user-registration-failed"; + }; + }; +diff --git a/plugins/mod_register_ibr.lua b/plugins/mod_register_ibr.lua +index ee47a1e..a76b711 100644 +--- a/plugins/mod_register_ibr.lua ++++ b/plugins/mod_register_ibr.lua +@@ -185,6 +185,7 @@ module:hook("stanza/iq/jabber:iq:register:query", function(event) + error_type, error_condition, reason = user.error_type, user.error_condition, user.reason; + end + log("debug", "Registration disallowed by module: %s", reason or "no reason given"); ++ module:fire_event("user-registration-failed", user); + session.send(st.error_reply(stanza, error_type or "modify", error_condition or "not-acceptable", reason)); + return true; + end +@@ -197,11 +198,13 @@ module:hook("stanza/iq/jabber:iq:register:query", function(event) + session.send(st.reply(stanza)); -- reset ok! + else + session.log("error", "Unable to reset password for %s@%s: %s", username, host, err); ++ module:fire_event("user-registration-failed", user); + session.send(st.error_reply(stanza, err.type, err.condition, err.text)); + end + return true; + else + log("debug", "Attempt to register with existing username"); ++ module:fire_event("user-registration-failed", user); + session.send(st.error_reply(stanza, "cancel", "conflict", "The requested username already exists.")); + return true; + end +@@ -213,6 +216,7 @@ module:hook("stanza/iq/jabber:iq:register:query", function(event) + if not account_details:set(username, data) then + log("debug", "Could not store extra details"); + usermanager_delete_user(username, host); ++ module:fire_event("user-registration-failed", user); + session.send(st.error_reply(stanza, "wait", "internal-server-error", "Failed to write data to disk.")); + return true; + end +@@ -223,6 +227,7 @@ module:hook("stanza/iq/jabber:iq:register:query", function(event) + session = session }); + else + log("debug", "Could not create user", err); ++ module:fire_event("user-registration-failed", user); + session.send(st.error_reply(stanza, "cancel", "feature-not-implemented", err)); + end + return true; diff -Nru prosody-13.0.1/debian/patches/0054-mod_register_ibr-Include-validated_invite-in-user-re.patch prosody-13.0.1/debian/patches/0054-mod_register_ibr-Include-validated_invite-in-user-re.patch --- prosody-13.0.1/debian/patches/0054-mod_register_ibr-Include-validated_invite-in-user-re.patch 1970-01-01 00:00:00.000000000 +0000 +++ prosody-13.0.1/debian/patches/0054-mod_register_ibr-Include-validated_invite-in-user-re.patch 2026-12-01 12:43:09.000000000 +0000 @@ -0,0 +1,27 @@ +From: Matthew Wild +Date: Wed, 25 Nov 2026 09:37:49 +0000 +Subject: mod_register_ibr: Include validated_invite in user-registered event + +This allows us to trace the actual invite that was used for registering, and +matches what other modules (e.g. mod_invites_register_web, +mod_invites_register_api) already do. + +Fetching from the session has awkward edge cases which could lead to the +session not containing the original invite. +--- + plugins/mod_register_ibr.lua | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/plugins/mod_register_ibr.lua b/plugins/mod_register_ibr.lua +index a76b711..7c19fb0 100644 +--- a/plugins/mod_register_ibr.lua ++++ b/plugins/mod_register_ibr.lua +@@ -224,7 +224,7 @@ module:hook("stanza/iq/jabber:iq:register:query", function(event) + log("info", "User account created: %s@%s", username, host); + module:fire_event("user-registered", { + username = username, host = host, source = "mod_register", +- session = session }); ++ session = session, validated_invite = user.validated_invite }); + else + log("debug", "Could not create user", err); + module:fire_event("user-registration-failed", user); diff -Nru prosody-13.0.1/debian/patches/0055-mod_invites-mod_invites_register-Restrict-concurrent.patch prosody-13.0.1/debian/patches/0055-mod_invites-mod_invites_register-Restrict-concurrent.patch --- prosody-13.0.1/debian/patches/0055-mod_invites-mod_invites_register-Restrict-concurrent.patch 1970-01-01 00:00:00.000000000 +0000 +++ prosody-13.0.1/debian/patches/0055-mod_invites-mod_invites_register-Restrict-concurrent.patch 2026-12-01 12:43:09.000000000 +0000 @@ -0,0 +1,158 @@ +From: Matthew Wild +Date: Wed, 25 Nov 2026 10:00:09 +0000 +Subject: mod_invites, mod_invites_register: Restrict concurrent invite use + +Jumping through some hoops to make sure each invite token can only be used +once. + +Multiple sessions may do the preauth stage on the same token, which is fine. +If we tried to make this exclusive, we could run into issues with e.g. a ghost +session "locking" the invite and preventing a newer session from successfully +registering. + +Before this commit we considered an invitation used upon successful +registration. However this could allow multiple sessions to do simultaneous +registration using the same token - this is especially true if we have async +storage (which is something we're trying to move towards). + +So now we consider an invitation "used" as soon as we start registering, and +build upon the new user-registration-failed event to roll that back if it +fails (which is probably not a rare case... think username conflict, password +complexity not met, etc.) + +Until we actually confirm that registration succeeded, the "used" state is in +memory only (we have a cache for invites in this state). This prevents an +invitation remaining permanently locked in case of an issue during +registration. +--- + plugins/mod_invites.lua | 34 +++++++++++++++++++++++++++++++++- + plugins/mod_invites_register.lua | 24 +++++++++++++++++++++--- + 2 files changed, 54 insertions(+), 4 deletions(-) + +diff --git a/plugins/mod_invites.lua b/plugins/mod_invites.lua +index dbcd256..114baeb 100644 +--- a/plugins/mod_invites.lua ++++ b/plugins/mod_invites.lua +@@ -1,3 +1,4 @@ ++local cache = require "prosody.util.cache"; + local id = require "prosody.util.id"; + local it = require "prosody.util.iterators"; + local url = require "socket.url"; +@@ -143,10 +144,24 @@ end + local valid_invite_methods = {}; + local valid_invite_mt = { __index = valid_invite_methods }; + ++-- Tokens of invites that :use() is in the middle of using. This acts as a ++-- guard against multiple sessions using the same invite token concurrently. ++-- When it is full, further invites cannot be used until there is room. ++local registering_tokens = cache.new(128, function () ++ module:log("warn", "Max concurrent invitations already registering, rejecting"); ++ return false; ++end); ++ + function valid_invite_methods:use() + if self.reusable then + return true; +- elseif self.used then ++ elseif self.used or registering_tokens:get(self.token) or not registering_tokens:set(self.token, true) then ++ return false; ++ end ++ ++ -- The invite may have been used through another copy of it since get() ++ if not token_storage:get(self.subscription and self.username or nil, self.token) then ++ registering_tokens:set(self.token, nil); + return false; + end + +@@ -158,10 +173,23 @@ function valid_invite_methods:use() + token_storage:set(nil, self.token, nil); + + self.used = true; ++ registering_tokens:set(self.token, nil); + + return true; + end + ++-- Undo :use(), if what the invite was used for did not succeed after all ++function valid_invite_methods:restore() ++ if not self.used then ++ return; ++ end ++ if self.type == "roster" and self.username then ++ token_storage:set(self.username, self.token, self.expires); ++ end ++ token_storage:set(nil, self.token, self.info); ++ self.used = nil; ++end ++ + -- Get a validated invite (or nil, err). Must call :use() on the + -- returned invite after it is actually successfully used + -- For "roster" invites, the username of the local user (who issued +@@ -177,6 +205,7 @@ function get(token, username) + end + + local valid_until, inviter, allowed_username; ++ local subscription = username ~= nil; + + -- Fetch from host store (account invite) + local token_info = token_storage:get(nil, token); +@@ -205,6 +234,9 @@ function get(token, username) + return setmetatable({ + token = token; + username = username; ++ subscription = subscription; ++ info = token_info; ++ expires = valid_until; + inviter = inviter; + allowed_username = allowed_username; + type = token_info and token_info.type or "roster"; +diff --git a/plugins/mod_invites_register.lua b/plugins/mod_invites_register.lua +index a4463db..7bb84ad 100644 +--- a/plugins/mod_invites_register.lua ++++ b/plugins/mod_invites_register.lua +@@ -125,6 +125,17 @@ module:hook("user-registering", function (event) + end + event.allow_reset = reset_username; + end ++ if event.allowed and not event.validated_invite then ++ -- Other sessions may have validated the invite too. Use it now, so ++ -- that none of them can while the account is being created. It is ++ -- restored if registration fails. ++ if validated_invite:use() then ++ event.validated_invite = validated_invite; ++ else ++ event.allowed = false; ++ event.reason = "The invite token is invalid or expired"; ++ end ++ end + end + end); + +@@ -152,13 +163,13 @@ end + + -- Registration successful, if there was a preauth token, mark it as used + module:hook("user-registered", function (event) +- local validated_invite = get_validated_invite(event); +- if not validated_invite then ++ -- An invite validated by the session was used when registration began ++ local validated_invite = event.validated_invite; ++ if not validated_invite or not (validated_invite.used or validated_invite:use()) then + return; + end + local inviter_username = validated_invite.inviter; + local contact_username = event.username; +- validated_invite:use(); + + if inviter_username then + module:log("debug", "Creating mutual subscription between %s and %s", inviter_username, contact_username); +@@ -198,3 +209,10 @@ module:hook("user-password-reset", function (event) + validated_invite:use(); + end); + ++-- Registration did not succeed, allow the invite to be used again ++module:hook("user-registration-failed", function (event) ++ if event.validated_invite then ++ event.validated_invite:restore(); ++ end ++end); ++ diff -Nru prosody-13.0.1/debian/patches/series prosody-13.0.1/debian/patches/series --- prosody-13.0.1/debian/patches/series 2026-05-05 07:37:27.000000000 +0000 +++ prosody-13.0.1/debian/patches/series 2026-12-01 12:43:09.000000000 +0000 @@ -12,3 +12,44 @@ 0013-mod_bosh-Apply-different-stanza-size-limit-before-au.patch 0014-util.xmppstream-Support-limiting-total-number-of-des.patch 0015-mod_c2s-mod_s2s-Add-configurable-limit-for-stanza-ma.patch +0015-util.datamanager-Don-t-leave-hole-in-array-after-rem.patch +0016-mod_auth_ldap-Always-fail-empty-passwords.patch +0017-mod_legacyauth-Run-password-through-saslprep-and-rej.patch +0018-mod_invites-mod_invites_register-Prevent-reuse-of-va.patch +0019-stanza_router-Ensure-stanza-events-are-always-fired-.patch +0020-MUC-Use-correct-actor-when-kicking-on-reserved-nick-.patch +0021-MUC-Reject-mediated-invites-from-unaffiliated-non-oc.patch +0022-MUC-Forbid-unaffiliated-non-occupant-MAM-queries-by-.patch +0023-util.stanza-Add-support-for-parsing-xs-boolean-and-x.patch +0024-util.rsm-Strictly-validate-integers.patch +0025-mod_mam-Return-error-on-invalid-RSM-fields.patch +0026-mod_muc_mam-Return-error-on-invalid-RSM-fields.patch +0027-mod_storage_sql-Reject-invalid-RSM-limit.patch +0028-mod_storage_memory-Reject-invalid-RSM-limit.patch +0029-net.http.parser-Fix-handling-of-chunked-request.patch +0030-mod_http_file_share-Enforce-valid-content-type-in-sl.patch +0031-mod_dialback-Reject-dialback-requests-for-hosts-with.patch +0032-stanza_router-reject-stanzas-to-hosts-with-mod_s2s-d.patch +0033-net.http.parser-Error-on-sink-write-failure.patch +0034-mod_http_file_share-Limit-data-written-to-sink-based.patch +0035-mod_tokenauth-Apply-role-if-any-from-OAuth-token-to-.patch +0036-mod_invites_register-Stricter-validation-of-registra.patch +0037-mod_invites_register-Don-t-restrict-username-for-ros.patch +0038-mod_invites-mod_invites_register-Use-new-allowed_use.patch +0039-net.http.server-Ensure-finish_cb-is-always-called-on.patch +0040-util.xmppstream-Initialize-SAX-handlers-with-max_ele.patch +0041-util.xmppstream-Preserve-max_elements-if-not-explici.patch +0042-util.xmppstream-More-robust-processing-of-stream-abo.patch +0043-util.xmppstream-Add-tests-for-limits-behaviour.patch +0044-util.xmppstream-More-accurate-byte-accounting-for-st.patch +0045-net.http.parser-Avoid-responding-twice-to-some-HTTP-.patch +0046-net.http-Normalize-URI-scheme-fixes-2018.patch +0047-mod_bosh-Apply-c2s_max_child_elements-to-BOSH-stream.patch +0048-mod_component-Apply-component-s2s-_max_child_element.patch +0049-mod_pep-Don-t-send-notifications-to-contacts-that-no.patch +0050-util.xmppstream-Discard-data-and-callbacks-after-a-s.patch +0051-MUC-Don-t-relay-arbitrary-child-elements-in-mediated.patch +0052-mod_component-Fix-overly-long-line-luacheck.patch +0053-mod_register_ibr-Fire-event-on-registration-failure.patch +0054-mod_register_ibr-Include-validated_invite-in-user-re.patch +0055-mod_invites-mod_invites_register-Restrict-concurrent.patch