Reject HTTP incomming connections quicker if host does not match.

Issue #1072
This commit is contained in:
Craig Drummond
2017-08-20 14:07:49 +01:00
committed by Craig Drummond
parent dad279102d
commit c2c02b559b
2 changed files with 21 additions and 18 deletions

View File

@@ -227,9 +227,25 @@ void HttpSocket::handleNewConnection()
{
DBUG;
while (hasPendingConnections()) {
QTcpSocket *s = nextPendingConnection();
connect(s, SIGNAL(readyRead()), this, SLOT(readClient()));
connect(s, SIGNAL(disconnected()), this, SLOT(discardClient()));
QTcpSocket *socket = nextPendingConnection();
static const QLatin1String constIpV6Prefix("::ffff:");
QString peer=socket->peerAddress().toString();
QString ifaceAddress=serverAddress().toString();
const bool hostOk=peer==ifaceAddress || peer==mpdAddr || peer==(constIpV6Prefix+mpdAddr) ||
peer==QLatin1String("127.0.0.1") || peer==(constIpV6Prefix+QLatin1String("127.0.0.1"));
DBUG << "peer:" << peer << "mpd:" << mpdAddr << "iface:" << ifaceAddress << "ok:" << hostOk;
if (!hostOk) {
sendErrorResponse(socket, 400);
socket->close();
DBUG << "Not from valid host";
return;
}
connect(socket, SIGNAL(readyRead()), this, SLOT(readClient()));
connect(socket, SIGNAL(disconnected()), this, SLOT(discardClient()));
}
}
@@ -253,21 +269,6 @@ void HttpSocket::readClient()
return;
}
static const QLatin1String constIpV6Prefix("::ffff:");
QString peer=socket->peerAddress().toString();
QString ifaceAddress=serverAddress().toString();
bool hostOk=peer==ifaceAddress || peer==mpdAddr || peer==(constIpV6Prefix+mpdAddr) ||
peer==QLatin1String("127.0.0.1") || peer==(constIpV6Prefix+QLatin1String("127.0.0.1"));
DBUG << "peer:" << peer << "mpd:" << mpdAddr << "iface:" << ifaceAddress << "ok:" << hostOk;
if (!hostOk) {
sendErrorResponse(socket, 400);
socket->close();
DBUG << "Not from valid host";
return;
}
QUrl url(QUrl::fromEncoded(tokens[1]));
QUrlQuery q(url);
bool ok=false;