fix: validate stanza-id 'by' attr and route MUC MAM correctly (XEP-0359, XEP-0313) #102
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Issue 1 — Security:
<stanza-id>byattribute not validated (XEP-0359)Title
XEP-0359:
<stanza-id>accepted without validating thebyattributeDescription
The
<stanza-id>element (XEP-0359) is parsed in both_handle_chat()and_handle_groupchat()without checking thebyattribute against the expected entity.XEP-0359 §5 (Security Considerations):
Current code
message.c,
_handle_chat():The same pattern exists in
_handle_groupchat().Impact
A malicious remote contact or a compromised MUC participant can inject a forged
<stanza-id by="evil.example">element into a message. Since thebyattribute is never checked:<stanza-id>matching an existing archive-id, causing the client to flag a legitimate live message as a duplicate and silently drop it.Expected behavior
For 1:1 chat messages, the
byattribute must match the bare JID of the user's own server (account domain).For MUC messages, the
byattribute must match the bare JID of the room.Any
<stanza-id>element whosebydoes not match the expected entity should be ignored.Suggested fix
References
Issue 2 — MUC MAM messages misrouted through
_handle_chatTitle
MUC MAM results handled as 1:1 chat / private MUC message instead of room message
Description
When a MUC room responds to a MAM query (XEP-0313 §7), the result messages are sent as:
The outer
<message>has notypeattribute (ortype="chat"), so_message_handler()routes it to thetype == NULLbranch, which calls_handle_mam()._handle_mam()unconditionally calls_handle_chat()on the inner forwarded<message type="groupchat">.Inside
_handle_chat():If the room is active (which it normally is when MAM is requested), the MUC MAM message is misrouted to
_handle_muc_private_message().If the room is not active, it falls through and is treated as a regular 1:1 chat message with a wrong JID.
Expected behavior
_handle_mam()should detect the inner message type. Iftype="groupchat", it should delegate to a MUC-aware MAM handler that processes the message as room history (similar tosv_ev_room_history), not as a 1:1 chat.Suggested approach
References