Skip to content

Commit 0f06ceb

Browse files
fanquakeTom Trevethan
authored andcommitted
Merge bitcoin/bitcoin#33395: net: do not apply whitelist permissions to onion inbounds
f563ce90818d486d2a199439d2f6ba39cd106352 net: Do not apply whitelist permission to onion inbounds (Martin Zumsande) Pull request description: Tor inbound connections do not reveal the peer's actual network address. Do not apply whitelist permissions to them since address-based matching is ineffective. ACKs for top commit: darosior: ACK f563ce90818d486d2a199439d2f6ba39cd106352 furszy: ACK f563ce90818d486d2a199439d2f6ba39cd106352 vasild: ACK f563ce90818d486d2a199439d2f6ba39cd106352 Tree-SHA512: 49ae70e382fc2f78b7073553fe649a6843a41214b2986ea7f77e285d02b7bd00fe0320a1b71d1aaca08713808fb14af058f0b1f19f19adb3a77b97cb9d3449ce
1 parent 53a5bd0 commit 0f06ceb

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/net.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -569,9 +569,9 @@ void CNode::CloseSocketDisconnect()
569569
}
570570
}
571571

572-
void CConnman::AddWhitelistPermissionFlags(NetPermissionFlags& flags, const CNetAddr &addr) const {
572+
void CConnman::AddWhitelistPermissionFlags(NetPermissionFlags& flags, std::optional<CNetAddr> addr) const {
573573
for (const auto& subnet : vWhitelistedRange) {
574-
if (subnet.m_subnet.Match(addr)) NetPermissions::AddFlag(flags, subnet.m_flags);
574+
if (addr.has_value() && subnet.m_subnet.Match(addr.value())) NetPermissions::AddFlag(flags, subnet.m_flags);
575575
}
576576
}
577577

@@ -1179,7 +1179,10 @@ void CConnman::CreateNodeFromAcceptedSocket(std::unique_ptr<Sock>&& sock,
11791179
int nInbound = 0;
11801180
int nMaxInbound = nMaxConnections - m_max_outbound;
11811181

1182-
AddWhitelistPermissionFlags(permissionFlags, addr);
1182+
const bool inbound_onion = std::find(m_onion_binds.begin(), m_onion_binds.end(), addr_bind) != m_onion_binds.end();
1183+
// Tor inbound connections do not reveal the peer's actual network address.
1184+
// Therefore do not apply address-based whitelist permissions to them.
1185+
AddWhitelistPermissionFlags(permissionFlags, inbound_onion ? std::optional<CNetAddr>{} : addr);
11831186
if (NetPermissions::HasFlag(permissionFlags, NetPermissionFlags::Implicit)) {
11841187
NetPermissions::ClearFlag(permissionFlags, NetPermissionFlags::Implicit);
11851188
if (gArgs.GetBoolArg("-whitelistforcerelay", DEFAULT_WHITELISTFORCERELAY)) NetPermissions::AddFlag(permissionFlags, NetPermissionFlags::ForceRelay);
@@ -1243,7 +1246,6 @@ void CConnman::CreateNodeFromAcceptedSocket(std::unique_ptr<Sock>&& sock,
12431246
nodeServices = static_cast<ServiceFlags>(nodeServices | NODE_BLOOM);
12441247
}
12451248

1246-
const bool inbound_onion = std::find(m_onion_binds.begin(), m_onion_binds.end(), addr_bind) != m_onion_binds.end();
12471249
CNode* pnode = new CNode(id,
12481250
nodeServices,
12491251
std::move(sock),

src/net.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1077,7 +1077,7 @@ class CConnman
10771077

10781078
bool AttemptToEvictConnection();
10791079
CNode* ConnectNode(CAddress addrConnect, const char *pszDest, bool fCountFailure, ConnectionType conn_type);
1080-
void AddWhitelistPermissionFlags(NetPermissionFlags& flags, const CNetAddr &addr) const;
1080+
void AddWhitelistPermissionFlags(NetPermissionFlags& flags, std::optional<CNetAddr> addr) const;
10811081

10821082
void DeleteNode(CNode* pnode);
10831083

0 commit comments

Comments
 (0)