Philipp Hörist pushed to branch master at gajim / python-nbxmpp
Commits:
cd55d309 by Philipp Hörist at 2026-08-10T23:23:30+02:00
imprv: OMEMO: Harden devicelist parser
- - - - -
2 changed files:
- nbxmpp/modules/omemo.py
- + test/unit/test_omemo.py
Changes:
=====================================
nbxmpp/modules/omemo.py
=====================================
@@ -400,15 +400,16 @@ def _parse_devicelist(item: Node) -> list[int]:
if list_node is None:
raise MalformedStanzaError("No list node found", item)
- if not list_node.getChildren():
- return []
-
result: list[int] = []
- devices_nodes = list_node.getChildren()
- for dn in devices_nodes:
+ for dn in list_node.getTags("device", namespace=Namespace.OMEMO_TEMP):
_id = dn.getAttr("id")
- if _id:
+ if _id is None:
+ raise MalformedStanzaError("Device node without id attribute",
item)
+
+ try:
result.append(int(_id))
+ except Exception:
+ raise MalformedStanzaError("Non integer device id", item)
return result
=====================================
test/unit/test_omemo.py
=====================================
@@ -0,0 +1,21 @@
+import unittest
+
+from nbxmpp.modules.omemo import _parse_devicelist
+from nbxmpp.simplexml import Node
+
+
+class OMEMOTest(unittest.TestCase):
+
+ def test_parsing(self):
+
+ devicelist = """
+ <item id="current">
+ <list xmlns="eu.siacs.conversations.axolotl">
+ <device id="912561474" />
+ <device id="532656838" />
+ <device id="1" xmlns="test.namespace" />
+ </list>
+ </item>"""
+
+ devices = _parse_devicelist(Node(node=devicelist))
+ self.assertEqual(devices, [912561474, 532656838])
View it on GitLab:
https://dev.gajim.org/gajim/python-nbxmpp/-/commit/cd55d309b507ceeed65fec37d06937366f5973d8
--
View it on GitLab:
https://dev.gajim.org/gajim/python-nbxmpp/-/commit/cd55d309b507ceeed65fec37d06937366f5973d8
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]