Merge pull request #3294 from thelounge/xpaw/fix-3293

Verify reverse DNS when looking up hostnames for webirc
This commit is contained in:
Pavel Djundik 2019-07-12 11:50:50 +03:00 committed by GitHub
commit 820a67802d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -744,11 +744,23 @@ function performAuthentication(data) {
}
function reverseDnsLookup(ip, callback) {
dns.reverse(ip, (err, hostnames) => {
if (!err && hostnames.length) {
return callback(hostnames[0]);
dns.reverse(ip, (reverseErr, hostnames) => {
if (reverseErr || hostnames.length < 1) {
return callback(ip);
}
callback(ip);
dns.resolve(hostnames[0], net.isIP(ip) === 6 ? "AAAA" : "A", (resolveErr, resolvedIps) => {
if (resolveErr || resolvedIps.length < 1) {
return callback(ip);
}
for (const resolvedIp of resolvedIps) {
if (ip === resolvedIp) {
return callback(hostnames[0]);
}
}
return callback(ip);
});
});
}