From 95c8d120b40e0bca89d1b6f83e902de9529e8006 Mon Sep 17 00:00:00 2001 From: Linus Jahn Date: Sat, 28 Jan 2023 17:36:09 +0100 Subject: IqHandling: Don't accept IQ results/errors --- src/client/QXmppIqHandling.cpp | 13 +++++++++++++ src/client/QXmppIqHandling.h | 8 +++----- 2 files changed, 16 insertions(+), 5 deletions(-) (limited to 'src/client') diff --git a/src/client/QXmppIqHandling.cpp b/src/client/QXmppIqHandling.cpp index be164f0f..ddc980fe 100644 --- a/src/client/QXmppIqHandling.cpp +++ b/src/client/QXmppIqHandling.cpp @@ -25,3 +25,16 @@ void QXmpp::Private::sendIqReply(QXmppClient *client, iq.setId(requestId); client->reply(std::move(iq), e2eeMetadata); } + +std::tuple QXmpp::Private::checkIsIqRequest(const QDomElement &el) +{ + if (el.tagName() != QStringLiteral("iq")) { + return { false, {}, {} }; + } + auto queryElement = el.firstChildElement(); + auto iqType = el.attribute(QStringLiteral("type")); + if (iqType != QStringLiteral("get") && iqType != QStringLiteral("set")) { + return { false, {}, {} }; + } + return { true, queryElement.tagName(), queryElement.namespaceURI() }; +} diff --git a/src/client/QXmppIqHandling.h b/src/client/QXmppIqHandling.h index 0782dd89..7535bc30 100644 --- a/src/client/QXmppIqHandling.h +++ b/src/client/QXmppIqHandling.h @@ -22,6 +22,8 @@ namespace Private { const std::optional &e2eeMetadata, QXmppIq &&iq); + QXMPP_EXPORT std::tuple checkIsIqRequest(const QDomElement &el); + template void processHandleIqResult(QXmppClient *client, const QString &requestId, @@ -188,11 +190,7 @@ bool handleIqRequests(const QDomElement &element, QXmppClient *client, Handler handler) { - if (element.tagName() == "iq") { - auto queryElement = element.firstChildElement(); - auto tagName = queryElement.tagName(); - auto xmlns = queryElement.namespaceURI(); - + if (auto [isRequest, tagName, xmlns] = Private::checkIsIqRequest(element); isRequest) { return (Private::handleIqType(handler, client, element, e2eeMetadata, tagName, xmlns) || ...); } return false; -- cgit v1.2.3