aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortobtoht <tob@featherwallet.org>2023-05-12 12:39:00 +0200
committertobtoht <tob@featherwallet.org>2023-07-03 13:34:39 +0200
commitd9c7cd5a89cd1baa270a097bae1a2eff7bd4b2e9 (patch)
tree03e01adfe900547742797582d963a30f9624dc44 /src
parentMerge pull request #8884 (diff)
downloadmonero-d9c7cd5a89cd1baa270a097bae1a2eff7bd4b2e9.tar.xz
common: do not use DNS to determine if address is local
Co-authored-by: j-berman <justinberman@protonmail.com>
Diffstat (limited to 'src')
-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 c89a85267..b4f3360ef 100644
--- a/src/common/util.cpp
+++ b/src/common/util.cpp
@@ -610,13 +610,6 @@ namespace tools
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))
@@ -630,20 +623,22 @@ namespace tools
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");