From 72099dfde5cdc92e5e650d3bc3a62e8d7dfc3dd0 Mon Sep 17 00:00:00 2001 From: "Alexander \"PapaTutuWawa" Date: Mon, 23 Jan 2023 13:10:07 +0100 Subject: [PATCH] feat: Only add envelope elements that should be encrypted --- .../lib/src/xeps/xep_0384/xep_0384.dart | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/packages/moxxmpp/lib/src/xeps/xep_0384/xep_0384.dart b/packages/moxxmpp/lib/src/xeps/xep_0384/xep_0384.dart index 339a09c..c6d9f40 100644 --- a/packages/moxxmpp/lib/src/xeps/xep_0384/xep_0384.dart +++ b/packages/moxxmpp/lib/src/xeps/xep_0384/xep_0384.dart @@ -459,9 +459,25 @@ abstract class BaseOmemoManager extends XmppManagerBase { ); } - children.addAll( - envelope.firstTag('content')!.children, - ); + final envelopeChildren = envelope.firstTag('content')?.children; + if (envelopeChildren != null) { + children.addAll( + envelopeChildren + // Do not add forbidden elements from the envelope + .where((XMLNode child) { + for (final ignore in _doNotEncryptList) { + final xmlns = child.attributes['xmlns'] ?? ''; + if (child.tag == ignore.tag && xmlns == ignore.xmlns) { + return false; + } + } + + return true; + }), + ); + } else { + logger.warning('Invalid envelope element: No element'); + } if (!checkAffixElements(envelope, stanza.from!, ourJid)) { other['encryption_error'] = InvalidAffixElementsException();