|
12 | 12 | #include "qjsonarray.h" |
13 | 13 | #include "version.h" |
14 | 14 |
|
15 | | -#ifdef Q_OS_LINUX |
| 15 | +#if defined(Q_OS_LINUX) || defined(Q_OS_MACOS) |
16 | 16 | static bool isValidIpOrCidr(const QString &value) { |
17 | 17 | static const QRegularExpression re( |
18 | 18 | QStringLiteral(R"(^(\d{1,3}\.){3}\d{1,3}(/\d{1,2})?$)")); |
@@ -414,28 +414,40 @@ bool KillSwitch::enableKillSwitch(const QJsonObject &configStr, int vpnAdapterIn |
414 | 414 | MacOSFirewall::setAnchorEnabled(QStringLiteral("000.allowLoopback"), true); |
415 | 415 | MacOSFirewall::setAnchorEnabled(QStringLiteral("100.blockAll"), blockAll); |
416 | 416 | MacOSFirewall::setAnchorEnabled(QStringLiteral("110.allowNets"), allowNets); |
417 | | - MacOSFirewall::setAnchorTable(QStringLiteral("110.allowNets"), allowNets, QStringLiteral("allownets"), allownets); |
| 417 | + MacOSFirewall::setAnchorTable(QStringLiteral("110.allowNets"), allowNets, QStringLiteral("allownets"), filterIpList(allownets)); |
418 | 418 |
|
419 | 419 | MacOSFirewall::setAnchorEnabled(QStringLiteral("120.blockNets"), blockNets); |
420 | | - MacOSFirewall::setAnchorTable(QStringLiteral("120.blockNets"), blockNets, QStringLiteral("blocknets"), blocknets); |
| 420 | + MacOSFirewall::setAnchorTable(QStringLiteral("120.blockNets"), blockNets, QStringLiteral("blocknets"), filterIpList(blocknets)); |
421 | 421 | MacOSFirewall::setAnchorEnabled(QStringLiteral("200.allowVPN"), true); |
422 | 422 | MacOSFirewall::setAnchorEnabled(QStringLiteral("250.blockIPv6"), true); |
423 | 423 | MacOSFirewall::setAnchorEnabled(QStringLiteral("290.allowDHCP"), true); |
424 | 424 | MacOSFirewall::setAnchorEnabled(QStringLiteral("300.allowLAN"), true); |
425 | 425 |
|
426 | 426 | QStringList dnsServers; |
427 | | - dnsServers.append(configStr.value(amnezia::configKey::dns1).toString()); |
| 427 | + const QString dns1 = configStr.value(amnezia::configKey::dns1).toString(); |
| 428 | + if (isValidIpOrCidr(dns1)) |
| 429 | + dnsServers.append(dns1); |
| 430 | + else if (!dns1.isEmpty()) |
| 431 | + qWarning() << "IPC: rejected invalid dns1:" << dns1; |
428 | 432 |
|
429 | 433 | // We don't use secondary DNS if primary DNS is AmneziaDNS |
430 | | - if (!configStr.value(amnezia::configKey::dns1).toString().contains(amnezia::protocols::dns::amneziaDnsIp)) { |
431 | | - dnsServers.append(configStr.value(amnezia::configKey::dns2).toString()); |
| 434 | + if (!dns1.contains(amnezia::protocols::dns::amneziaDnsIp)) { |
| 435 | + const QString dns2 = configStr.value(amnezia::configKey::dns2).toString(); |
| 436 | + if (isValidIpOrCidr(dns2)) |
| 437 | + dnsServers.append(dns2); |
| 438 | + else if (!dns2.isEmpty()) |
| 439 | + qWarning() << "IPC: rejected invalid dns2:" << dns2; |
432 | 440 | } |
433 | | - |
| 441 | + |
434 | 442 | for (auto dns : configStr.value(amnezia::configKey::allowedDnsServers).toArray()) { |
435 | 443 | if (!dns.isString()) { |
436 | 444 | break; |
437 | 445 | } |
438 | | - dnsServers.append(dns.toString()); |
| 446 | + const QString dnsStr = dns.toString(); |
| 447 | + if (isValidIpOrCidr(dnsStr)) |
| 448 | + dnsServers.append(dnsStr); |
| 449 | + else if (!dnsStr.isEmpty()) |
| 450 | + qWarning() << "IPC: rejected invalid allowedDnsServer:" << dnsStr; |
439 | 451 | } |
440 | 452 |
|
441 | 453 | MacOSFirewall::setAnchorEnabled(QStringLiteral("310.blockDNS"), true); |
|
0 commit comments