What changed, and why it matters
This commit fixes a configuration bug in Bitcoin Core. Previously, if a user told their node to only use one network type (for example, only IPv4) and also manually set an external address on a different network (for example, a Tor onion address), the node would silently ignore the manually configured address. The change makes the node honor the user's explicit -externalip setting even when it belongs to a network otherwise excluded by -onlynet. It is a usability/configuration fix, not a vulnerability that allows attackers to take over nodes or steal funds.
No urgent security action. Treat as a normal bug-fix/configuration improvement. Users relying on -onlynet combined with -externalip should upgrade to obtain the corrected behavior.
Security signals we found
Configuration-behavior fix: explicit user override now honored
No new attack surface: bypass is limited to user-supplied -externalip
No changes to validation, consensus, wallet, or P2P protocol parsing
Evidence from the diff
AddLocal() in src/net.cpp previously rejected any local address whose network was not contained in g_reachable_nets, which is controlled by -onlynet. This caused -externalip addresses on excluded networks to be dropped. The patch adds an add_even_if_unreachable parameter to AddLocal() and sets it to true only in the -externalip handling loop in src/init.cpp. This preserves the -onlynet restriction for auto-discovered addresses while allowing explicitly configured externalip addresses to be advertised. No cryptographic, consensus, or network-attack surface changes are introduced.
Changed components
src/init.cppsrc/net.cppAddLocal()-externalip option handling-onlynet reachability logicInspect captured patch +2 / −2
diff --git a/src/init.cpp b/src/init.cpp
index c53e5ed6..03b9cbf5 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -1808,7 +1808,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
for (const std::string& strAddr : args.GetArgs("-externalip")) {
const std::optional<CService> addrLocal{Lookup(strAddr, GetListenPort(), fNameLookup)};
if (addrLocal.has_value() && addrLocal->IsValid())
- AddLocal(addrLocal.value(), LOCAL_MANUAL);
+ AddLocal(addrLocal.value(), LOCAL_MANUAL, /*add_even_if_unreachable=*/true);
else
return InitError(ResolveErrMsg("externalip", strAddr));
}
diff --git a/src/net.cpp b/src/net.cpp
index c903afc6..ef158180 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -284,7 +284,7 @@ bool AddLocal(const CService& addr_, int nScore, bool add_even_if_unreachable)
if (!fDiscover && nScore < LOCAL_MANUAL)
return false;
- if (!g_reachable_nets.Contains(addr))
+ if (!g_reachable_nets.Contains(addr) && !add_even_if_unreachable)
return false;
if (fLogIPs) {
Why this scored 22/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.