Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not allow to add loopback/multicast/broadcast ips to split tunnel #871

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions client/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@
#include "containers/containers_defs.h"
#include "logger.h"

namespace {

// true if invalid address or ip matches either of localhost/multicast/broadcast
bool isIpAddressReserved(const QString &ipStr)
{
QHostAddress ip(ipStr);

return ip.isLoopback() || ip.isMulticast() || ip.isBroadcast();
}

}

const char Settings::cloudFlareNs1[] = "1.1.1.1";
const char Settings::cloudFlareNs2[] = "1.0.0.1";

Expand Down Expand Up @@ -272,6 +284,11 @@ bool Settings::addVpnSite(RouteMode mode, const QString &site, const QString &ip
if (sites.contains(site) && ip.isEmpty())
return false;

if (isIpAddressReserved(site))
{
return false;
}

sites.insert(site, ip);
setVpnSites(mode, sites);
return true;
Expand All @@ -284,6 +301,11 @@ void Settings::addVpnSites(RouteMode mode, const QMap<QString, QString> &sites)
const QString &site = i.key();
const QString &ip = i.value();

if (isIpAddressReserved(site))
{
continue;
}

if (allSites.contains(site) && allSites.value(site) == ip)
continue;

Expand Down
21 changes: 17 additions & 4 deletions client/ui/controllers/sitesController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ void SitesController::addSite(QString hostname)
}

const auto &processSite = [this](const QString &hostname, const QString &ip) {
m_sitesModel->addSite(hostname, ip);
bool isAdded = m_sitesModel->addSite(hostname, ip);

if (!isAdded)
{
return false;
}

if (!ip.isEmpty()) {
QMetaObject::invokeMethod(m_vpnConnection.get(), "addRoutes", Qt::QueuedConnection,
Expand All @@ -45,6 +50,8 @@ void SitesController::addSite(QString hostname)
Q_ARG(QStringList, QStringList() << hostname));
}
QMetaObject::invokeMethod(m_vpnConnection.get(), "flushDns", Qt::QueuedConnection);

return true;
};

const auto &resolveCallback = [this, processSite](const QHostInfo &hostInfo) {
Expand All @@ -57,14 +64,20 @@ void SitesController::addSite(QString hostname)
}
};

bool isSiteAdded = false;
if (NetworkUtilities::ipAddressWithSubnetRegExp().exactMatch(hostname)) {
processSite(hostname, "");
isSiteAdded = processSite(hostname, "");
} else {
processSite(hostname, "");
isSiteAdded = processSite(hostname, "");
QHostInfo::lookupHost(hostname, this, resolveCallback);
}

emit finished(tr("New site added: %1").arg(hostname));
if (isSiteAdded) {
emit finished(tr("New site added: %1").arg(hostname));
} else
{
emit finished(tr("Invalid address or ip matches either of localhost/multicast/broadcast: %1").arg(hostname));
}
}

void SitesController::removeSite(int index)
Expand Down
Loading