aboutsummaryrefslogtreecommitdiff
path: root/src/common/util.cpp
diff options
context:
space:
mode:
authortobtoht <tob@featherwallet.org>2023-05-12 12:39:00 +0200
committertobtoht <tob@featherwallet.org>2023-05-25 18:06:34 +0200
commit8dc4abdafec7985319ba2fd2294ca8f0916d9cea (patch)
tree566abe8f4fa2044b6f50f6be8a00265a2aadb8d1 /src/common/util.cpp
parentMerge pull request #8846 (diff)
downloadmonero-8dc4abdafec7985319ba2fd2294ca8f0916d9cea.tar.xz
common: do not use DNS to determine if address is local
Co-authored-by: j-berman <justinberman@protonmail.com>
Diffstat (limited to '')
-rw-r--r--src/common/util.cpp35
1 files changed, 15 insertions, 20 deletions
diff --git a/src/common/util.cpp b/src/common/util.cpp
index f0de73a06..4b5e2adb8 100644
--- a/src/common/util.cpp
+++ b/src/common/util.cpp
@@ -882,13 +882,6 @@ std::string get_nix_version_display_string()
bool is_local_address(const std::string &address)
{
- // always assume Tor/I2P addresses to be untrusted by default
- if (is_privacy_preserving_network(address))
- {
- MDEBUG("Address '" << address << "' is Tor/I2P, non local");
- return false;
- }
-
// extract host
epee::net_utils::http::url_content u_c;
if (!epee::net_utils::parse_url(address, u_c))
@@ -902,20 +895,22 @@ std::string get_nix_version_display_string()
return false;
}
- // resolve to IP
- boost::asio::io_service io_service;
- boost::asio::ip::tcp::resolver resolver(io_service);
- boost::asio::ip::tcp::resolver::query query(u_c.host, "");
- boost::asio::ip::tcp::resolver::iterator i = resolver.resolve(query);
- while (i != boost::asio::ip::tcp::resolver::iterator())
+ if (u_c.host == "localhost" || boost::ends_with(u_c.host, ".localhost")) { // RFC 6761 (6.3)
+ MDEBUG("Address '" << address << "' is local");
+ return true;
+ }
+
+ boost::system::error_code ec;
+ const auto parsed_ip = boost::asio::ip::address::from_string(u_c.host, ec);
+ if (ec) {
+ MDEBUG("Failed to parse '" << address << "' as IP address: " << ec.message() << ". Considering it not local");
+ return false;
+ }
+
+ if (parsed_ip.is_loopback())
{
- const boost::asio::ip::tcp::endpoint &ep = *i;
- if (ep.address().is_loopback())
- {
- MDEBUG("Address '" << address << "' is local");
- return true;
- }
- ++i;
+ MDEBUG("Address '" << address << "' is local");
+ return true;
}
MDEBUG("Address '" << address << "' is not local");