Commit e8dc4694 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Fix detect url as scam when we have port in url.

Bug found by Albert
parent 97e64267
Pipeline #70468 passed with stage
in 25 minutes and 34 seconds
......@@ -13,10 +13,10 @@
TestWebEngineScamDetection::TestWebEngineScamDetection(QWidget *parent)
: QWidget(parent)
, mEngineView(new QWebEngineView(this))
, mScamDetectionWebEngine(new MessageViewer::ScamDetectionWebEngine(this))
{
auto hbox = new QHBoxLayout(this);
mEngineView = new QWebEngineView(this);
mScamDetectionWebEngine = new MessageViewer::ScamDetectionWebEngine(this);
connect(mScamDetectionWebEngine, &MessageViewer::ScamDetectionWebEngine::resultScanDetection, this, &TestWebEngineScamDetection::resultScanDetection);
connect(mEngineView, &QWebEngineView::loadFinished, this, &TestWebEngineScamDetection::loadFinished);
hbox->addWidget(mEngineView);
......@@ -129,7 +129,12 @@ void ScamDetectionWebEngineTest::scamtest_data()
"nUse</a>") << false;
QTest::newRow("wierd1") << QStringLiteral("<a href=\"http://www.weezevent.com?c=sys_mail\">http://www.weezevent.com?c=sys_mail</a>") << false;
QTest::newRow("urlwithport") << QStringLiteral("<a href=\"https://example.com:443/blablabla\">https://example.com:443/blablabla</a>") << false;
QTest::newRow("urlwithport-special443") << QStringLiteral("<a href=\"https://example.com:443/blablabla\">https://example.com:443/blablabla</a>") << false;
QTest::newRow("urlwithport-special443-2") << QStringLiteral("<a href=\"http://example.com:443/blablabla\">http://example.com:443/blablabla</a>") << false;
QTest::newRow("urlwithport") << QStringLiteral("<a href=\"https://example.com:465/blablabla\">https://example.com:465/blablabla</a>") << false;
QTest::newRow("urlwithport2") << QStringLiteral("<a href=\"https://example.com:11371/blablabla\">https://example.com:11371/blablabla</a>") << false;
QTest::newRow("urlwithport3") << QStringLiteral("<a href=\"smtps://example.com:465/blablabla\">smtps://example.com:465/blablabla</a>") << false;
QTest::newRow("urlwithport3") << QStringLiteral("<a href=\"imaps://example.com:993/blablabla\">imaps://example.com:993/blablabla</a>") << false;
}
void ScamDetectionWebEngineTest::scamtest()
......
......@@ -28,8 +28,8 @@ Q_SIGNALS:
void resultScanDetection(bool result);
private:
QWebEngineView *mEngineView = nullptr;
MessageViewer::ScamDetectionWebEngine *mScamDetectionWebEngine = nullptr;
QWebEngineView *const mEngineView;
MessageViewer::ScamDetectionWebEngine *const mScamDetectionWebEngine;
};
class ScamDetectionWebEngineTest : public QObject
......
......@@ -165,8 +165,10 @@ void ScamDetectionWebEngine::handleScanPage(const QVariant &result)
}
if (!foundScam) {
QUrl displayUrl = QUrl(mapVariant.value(QStringLiteral("text")).toString());
// qDebug() << " displayUrl "<< displayUrl;
QString text = displayUrl.toDisplayString(QUrl::StripTrailingSlash | QUrl::NormalizePathSegments | QUrl::RemovePort);
// Special case if https + port 443 it will return url without port
QString text = (displayUrl.port() == 443 && displayUrl.scheme() == QLatin1String("https"))
? displayUrl.toDisplayString(QUrl::StripTrailingSlash | QUrl::NormalizePathSegments | QUrl::RemovePort)
: displayUrl.toDisplayString(QUrl::StripTrailingSlash | QUrl::NormalizePathSegments);
if (text.endsWith(QLatin1String("%22"))) {
text.chop(3);
}
......@@ -187,6 +189,8 @@ void ScamDetectionWebEngine::handleScanPage(const QVariant &result)
displayUrl.toDisplayString(QUrl::RemoveQuery | QUrl::StripTrailingSlash | QUrl::NormalizePathSegments);
const QString hrefUrlWithoutQuery =
normalizedHrefUrl.toDisplayString(QUrl::RemoveQuery | QUrl::StripTrailingSlash | QUrl::NormalizePathSegments);
// qDebug() << "displayUrlWithoutQuery " << displayUrlWithoutQuery << " hrefUrlWithoutQuery " << hrefUrlWithoutQuery <<
// " text " << text;
if (qurlqueryequal && (displayUrlWithoutQuery + QLatin1Char('/') != hrefUrlWithoutQuery)) {
d->mDetails += QLatin1String("<li>")
+ i18n("This email contains a link which reads as '%1' in the text, but actually points to '%2'. This is often "
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment