summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <montel@kde.org>2016-10-26 11:10:05 (GMT)
committerMontel Laurent <montel@kde.org>2016-10-26 11:10:05 (GMT)
commit5279f877497353b1b9aa9a457d4ebe4901d84b26 (patch)
treea8cfa09a9793f4f25eb7174290f4f4584d972e74
parentd85cabbe06cce7fdcbd98136c80e12ab84a9497f (diff)
Add new interceptor. Make more secure.
-rw-r--r--messageviewer/src/viewer/webengine/blockexternalresourcesurlinterceptor/blockexternalresourcesurlinterceptor.cpp57
-rw-r--r--messageviewer/src/viewer/webengine/blockexternalresourcesurlinterceptor/blockexternalresourcesurlinterceptor.h38
-rw-r--r--messageviewer/src/viewer/webengine/blockexternalresourcesurlinterceptor/loadexternalreferencesurlinterceptor.cpp73
-rw-r--r--messageviewer/src/viewer/webengine/blockexternalresourcesurlinterceptor/loadexternalreferencesurlinterceptor.h41
-rw-r--r--messageviewer/src/viewer/webengine/loadexternalreferencesurlinterceptor/loadexternalreferencesurlinterceptor.cpp2
-rw-r--r--messageviewer/src/viewer/webengine/mailwebengineview.cpp2
6 files changed, 211 insertions, 2 deletions
diff --git a/messageviewer/src/viewer/webengine/blockexternalresourcesurlinterceptor/blockexternalresourcesurlinterceptor.cpp b/messageviewer/src/viewer/webengine/blockexternalresourcesurlinterceptor/blockexternalresourcesurlinterceptor.cpp
new file mode 100644
index 0000000..08c0387
--- /dev/null
+++ b/messageviewer/src/viewer/webengine/blockexternalresourcesurlinterceptor/blockexternalresourcesurlinterceptor.cpp
@@ -0,0 +1,57 @@
+/*
+ Copyright (C) 2016 Laurent Montel <montel@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "blockexternalresourcesurlinterceptor.h"
+
+#include <QWebEngineUrlRequestInfo>
+#include <QDebug>
+
+using namespace MessageViewer;
+
+BlockExternalResourcesUrlInterceptor::BlockExternalResourcesUrlInterceptor(QObject *parent)
+ : WebEngineViewer::NetworkPluginUrlInterceptorInterface(parent)
+{
+
+}
+
+BlockExternalResourcesUrlInterceptor::~BlockExternalResourcesUrlInterceptor()
+{
+}
+
+bool BlockExternalResourcesUrlInterceptor::interceptRequest(QWebEngineUrlRequestInfo &info)
+{
+ //qDebug()<<" bool BlockExternalResourcesUrlInterceptor::interceptRequest(QWebEngineUrlRequestInfo &info)" << (info.navigationType() == QWebEngineUrlRequestInfo::NavigationTypeFormSubmitted);
+ const QWebEngineUrlRequestInfo::ResourceType type = info.resourceType();
+ if (type == QWebEngineUrlRequestInfo::ResourceTypeMedia ||
+ type == QWebEngineUrlRequestInfo::ResourceTypePing ||
+ type == QWebEngineUrlRequestInfo::ResourceTypePrefetch ||
+ type == QWebEngineUrlRequestInfo::ResourceTypeFavicon ||
+ type == QWebEngineUrlRequestInfo::ResourceTypeXhr ||
+ #if QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)
+ type == QWebEngineUrlRequestInfo::ResourceTypePluginResource ||
+ type == QWebEngineUrlRequestInfo::ResourceTypeCspReport ||
+ #endif
+ type == QWebEngineUrlRequestInfo::ResourceTypeUnknown
+ ) {
+ return true;
+ } else if (info.navigationType() == QWebEngineUrlRequestInfo::NavigationTypeFormSubmitted) {
+
+ }
+ return false;
+}
diff --git a/messageviewer/src/viewer/webengine/blockexternalresourcesurlinterceptor/blockexternalresourcesurlinterceptor.h b/messageviewer/src/viewer/webengine/blockexternalresourcesurlinterceptor/blockexternalresourcesurlinterceptor.h
new file mode 100644
index 0000000..f8e7ef5
--- /dev/null
+++ b/messageviewer/src/viewer/webengine/blockexternalresourcesurlinterceptor/blockexternalresourcesurlinterceptor.h
@@ -0,0 +1,38 @@
+/*
+ Copyright (C) 2016 Laurent Montel <montel@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+#ifndef BLOCKEXTERNALRESOURCESURLINTERCEPTOR_H
+#define BLOCKEXTERNALRESOURCESURLINTERCEPTOR_H
+
+#include <WebEngineViewer/NetworkPluginUrlInterceptorInterface>
+
+namespace MessageViewer
+{
+class BlockExternalResourcesUrlInterceptor : public WebEngineViewer::NetworkPluginUrlInterceptorInterface
+{
+ Q_OBJECT
+public:
+ explicit BlockExternalResourcesUrlInterceptor(QObject *parent = Q_NULLPTR);
+ ~BlockExternalResourcesUrlInterceptor();
+
+ bool interceptRequest(QWebEngineUrlRequestInfo &info) Q_DECL_OVERRIDE;
+ void setAllowExternalContent(bool b);
+ bool allowExternalContent() const;
+};
+}
+#endif // BLOCKEXTERNALRESOURCESURLINTERCEPTOR_H
diff --git a/messageviewer/src/viewer/webengine/blockexternalresourcesurlinterceptor/loadexternalreferencesurlinterceptor.cpp b/messageviewer/src/viewer/webengine/blockexternalresourcesurlinterceptor/loadexternalreferencesurlinterceptor.cpp
new file mode 100644
index 0000000..2757a8a
--- /dev/null
+++ b/messageviewer/src/viewer/webengine/blockexternalresourcesurlinterceptor/loadexternalreferencesurlinterceptor.cpp
@@ -0,0 +1,73 @@
+/*
+ Copyright (C) 2016 Laurent Montel <montel@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "loadexternalreferencesurlinterceptor.h"
+
+#include <QWebEngineUrlRequestInfo>
+
+using namespace MessageViewer;
+
+class MessageViewer::LoadExternalReferencesUrlInterceptorPrivate
+{
+public:
+ LoadExternalReferencesUrlInterceptorPrivate()
+ : mAllowLoadExternalReference(false)
+ {
+
+ }
+ bool mAllowLoadExternalReference;
+};
+
+LoadExternalReferencesUrlInterceptor::LoadExternalReferencesUrlInterceptor(QObject *parent)
+ : WebEngineViewer::NetworkPluginUrlInterceptorInterface(parent),
+ d(new LoadExternalReferencesUrlInterceptorPrivate)
+{
+
+}
+
+LoadExternalReferencesUrlInterceptor::~LoadExternalReferencesUrlInterceptor()
+{
+ delete d;
+}
+
+bool LoadExternalReferencesUrlInterceptor::interceptRequest(QWebEngineUrlRequestInfo &info)
+{
+ if (d->mAllowLoadExternalReference) {
+ return false;
+ } else {
+ if (info.resourceType() == QWebEngineUrlRequestInfo::ResourceTypeImage
+ && !info.requestUrl().isLocalFile()
+ && (info.requestUrl().scheme() != QLatin1String("cid"))) {
+ return true;
+ } else if (info.resourceType() == QWebEngineUrlRequestInfo::ResourceTypeMedia) {
+ return true;
+ }
+ }
+ return false;
+}
+
+void LoadExternalReferencesUrlInterceptor::setAllowExternalContent(bool b)
+{
+ d->mAllowLoadExternalReference = b;
+}
+
+bool LoadExternalReferencesUrlInterceptor::allowExternalContent() const
+{
+ return d->mAllowLoadExternalReference;
+}
diff --git a/messageviewer/src/viewer/webengine/blockexternalresourcesurlinterceptor/loadexternalreferencesurlinterceptor.h b/messageviewer/src/viewer/webengine/blockexternalresourcesurlinterceptor/loadexternalreferencesurlinterceptor.h
new file mode 100644
index 0000000..5b60225
--- /dev/null
+++ b/messageviewer/src/viewer/webengine/blockexternalresourcesurlinterceptor/loadexternalreferencesurlinterceptor.h
@@ -0,0 +1,41 @@
+/*
+ Copyright (C) 2016 Laurent Montel <montel@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+#ifndef LOADEXTERNALREFERENCESURLINTERCEPTOR_H
+#define LOADEXTERNALREFERENCESURLINTERCEPTOR_H
+
+#include <WebEngineViewer/NetworkPluginUrlInterceptorInterface>
+
+namespace MessageViewer
+{
+class LoadExternalReferencesUrlInterceptorPrivate;
+class LoadExternalReferencesUrlInterceptor : public WebEngineViewer::NetworkPluginUrlInterceptorInterface
+{
+ Q_OBJECT
+public:
+ explicit LoadExternalReferencesUrlInterceptor(QObject *parent = Q_NULLPTR);
+ ~LoadExternalReferencesUrlInterceptor();
+
+ bool interceptRequest(QWebEngineUrlRequestInfo &info) Q_DECL_OVERRIDE;
+ void setAllowExternalContent(bool b);
+ bool allowExternalContent() const;
+private:
+ LoadExternalReferencesUrlInterceptorPrivate *const d;
+};
+}
+#endif // LOADEXTERNALREFERENCESURLINTERCEPTOR_H
diff --git a/messageviewer/src/viewer/webengine/loadexternalreferencesurlinterceptor/loadexternalreferencesurlinterceptor.cpp b/messageviewer/src/viewer/webengine/loadexternalreferencesurlinterceptor/loadexternalreferencesurlinterceptor.cpp
index 2757a8a..c0004d1 100644
--- a/messageviewer/src/viewer/webengine/loadexternalreferencesurlinterceptor/loadexternalreferencesurlinterceptor.cpp
+++ b/messageviewer/src/viewer/webengine/loadexternalreferencesurlinterceptor/loadexternalreferencesurlinterceptor.cpp
@@ -55,8 +55,6 @@ bool LoadExternalReferencesUrlInterceptor::interceptRequest(QWebEngineUrlRequest
&& !info.requestUrl().isLocalFile()
&& (info.requestUrl().scheme() != QLatin1String("cid"))) {
return true;
- } else if (info.resourceType() == QWebEngineUrlRequestInfo::ResourceTypeMedia) {
- return true;
}
}
return false;
diff --git a/messageviewer/src/viewer/webengine/mailwebengineview.cpp b/messageviewer/src/viewer/webengine/mailwebengineview.cpp
index 2b63e87..7673e84 100644
--- a/messageviewer/src/viewer/webengine/mailwebengineview.cpp
+++ b/messageviewer/src/viewer/webengine/mailwebengineview.cpp
@@ -23,6 +23,7 @@
#include "mailwebenginescript.h"
#include "messageviewer/messageviewersettings.h"
#include "loadexternalreferencesurlinterceptor/loadexternalreferencesurlinterceptor.h"
+#include "blockexternalresourcesurlinterceptor/blockexternalresourcesurlinterceptor.h"
#include "cidreferencesurlinterceptor/cidreferencesurlinterceptor.h"
#include <WebEngineViewer/InterceptorManager>
#include <WebEngineViewer/WebEngineManageScript>
@@ -95,6 +96,7 @@ MailWebEngineView::MailWebEngineView(KActionCollection *ac, QWidget *parent)
d->mNetworkAccessManager->addInterceptor(d->mExternalReference);
MessageViewer::CidReferencesUrlInterceptor *cidReference = new MessageViewer::CidReferencesUrlInterceptor(this);
d->mNetworkAccessManager->addInterceptor(cidReference);
+ d->mNetworkAccessManager->addInterceptor(new MessageViewer::BlockExternalResourcesUrlInterceptor(this));
setFocusPolicy(Qt::WheelFocus);
connect(d->mPageEngine, &MailWebEnginePage::urlClicked, this, &MailWebEngineView::openUrl);
#if QT_VERSION >= 0x050700