Philipp Hörist pushed to branch master at gajim / python-nbxmpp
Commits:
d656c4ca by Philipp Hörist at 2026-08-13T19:29:42+02:00
fix: WebSocket: Disconnect on parsing errors
- - - - -
19519cfa by Philipp Hörist at 2026-08-13T19:57:43+02:00
imprv: Fallback: Improve range validation
- - - - -
3 changed files:
- nbxmpp/dispatcher.py
- nbxmpp/modules/fallback.py
- test/unit/test_fallback.py
Changes:
=====================================
nbxmpp/dispatcher.py
=====================================
@@ -459,7 +459,13 @@ class StanzaDispatcher(Observable):
data = self.replace_non_character(data)
if self._client.is_websocket:
- stanza = Node(node=data)
+ try:
+ stanza = Node(node=data)
+ except (ExpatError, ValueError) as error:
+ self._log.error("XML parsing error: %s", error)
+ self.notify("parsing-error", str(error))
+ return
+
if is_websocket_stream_error(stanza):
for tag in stanza.getChildren():
name = tag.getName()
=====================================
nbxmpp/modules/fallback.py
=====================================
@@ -16,6 +16,13 @@ class FallbackRange:
start: int
end: int
+ def __post_init__(self):
+ if self.start < 0 or self.end < 0:
+ raise ValueError("Range with negative numbers: %s", self)
+
+ if self.start >= self.end:
+ raise ValueError("Range with start > end: %s", self)
+
FallbackLangMapT = dict[str | None, FallbackRange | None]
FallbacksForT = dict[str, FallbackLangMapT | None]
@@ -61,12 +68,8 @@ def parse_fallback_indication(
assert end is not None
try:
range_ = FallbackRange(start=int(start), end=int(end))
- except Exception:
- log.warning("Incorrect range on fallback indication")
- return
-
- if range_.start < 0 or range_.end < 0:
- log.warning("Fallback range with negative numbers: %s",
range_)
+ except Exception as error:
+ log.warning("Incorrect range on fallback indication: %s",
error)
return
fallback_lang_map[lang] = range_
=====================================
test/unit/test_fallback.py
=====================================
@@ -64,6 +64,20 @@ class TestFallback(StanzaHandlerTest):
self.assertIsNone(fallbacks_for)
+ xml = """
+ <message to='[email protected]' id='message-id2' type='groupchat'>
+ <body>> Anna wrote:\n> Hi, how are you?\nGreat</body>
+ <fallback xmlns='urn:xmpp:fallback:0' for='urn:xmpp:test:0'>
+ <body start='10' end='10' />
+ </fallback>
+ </message>
+ """
+
+ message = nbxmpp.Message(node=xml)
+ fallbacks_for = parse_fallback_indication(log, message)
+
+ self.assertIsNone(fallbacks_for)
+
def test_strip_fallback(self):
fallbacks_for: FallbacksForT = {
"urn:xmpp:test:1": {
View it on GitLab:
https://dev.gajim.org/gajim/python-nbxmpp/-/compare/ce11ba7dc67a478449778680e58723cbecf7121d...19519cfad695b24ea6a114583ed7e3dae4f4cd32
--
View it on GitLab:
https://dev.gajim.org/gajim/python-nbxmpp/-/compare/ce11ba7dc67a478449778680e58723cbecf7121d...19519cfad695b24ea6a114583ed7e3dae4f4cd32
You're receiving this email because of your account on dev.gajim.org.
_______________________________________________
Commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]