-
Notifications
You must be signed in to change notification settings - Fork 38k
net: do not apply whitelist permissions to onion inbounds #33395
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -574,9 +574,9 @@ void CNode::CloseSocketDisconnect() | |||||
m_i2p_sam_session.reset(); | ||||||
} | ||||||
|
||||||
void CConnman::AddWhitelistPermissionFlags(NetPermissionFlags& flags, const CNetAddr &addr, const std::vector<NetWhitelistPermissions>& ranges) const { | ||||||
void CConnman::AddWhitelistPermissionFlags(NetPermissionFlags& flags, std::optional<CNetAddr> addr, const std::vector<NetWhitelistPermissions>& ranges) const { | ||||||
for (const auto& subnet : ranges) { | ||||||
if (subnet.m_subnet.Match(addr)) { | ||||||
if (addr.has_value() && subnet.m_subnet.Match(addr.value())) { | ||||||
NetPermissions::AddFlag(flags, subnet.m_flags); | ||||||
} | ||||||
} | ||||||
|
@@ -1768,7 +1768,11 @@ void CConnman::CreateNodeFromAcceptedSocket(std::unique_ptr<Sock>&& sock, | |||||
{ | ||||||
int nInbound = 0; | ||||||
|
||||||
AddWhitelistPermissionFlags(permission_flags, addr, vWhitelistedRangeIncoming); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Previously void CConnman::AddWhitelistPermissionFlags(NetPermissionFlags& flags, const CNetAddr &addr, const std::vector<NetWhitelistPermissions>& ranges) const {
for (const auto& subnet : ranges) {
if (subnet.m_subnet.Match(addr)) {
NetPermissions::AddFlag(flags, subnet.m_flags);
}
}
if (NetPermissions::HasFlag(flags, NetPermissionFlags::Implicit)) {
NetPermissions::ClearFlag(flags, NetPermissionFlags::Implicit);
if (whitelist_forcerelay) NetPermissions::AddFlag(flags, NetPermissionFlags::ForceRelay);
if (whitelist_relay) NetPermissions::AddFlag(flags, NetPermissionFlags::Relay);
NetPermissions::AddFlag(flags, NetPermissionFlags::Mempool);
NetPermissions::AddFlag(flags, NetPermissionFlags::NoBan);
}
} there would be a match in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done with latest push, the section will now no longer be omitted (in the specific case of onion inbounds, I think it's not possible to have other prior implicit permissions here so it also won't actually be executed, but I agree it's a cleaner approach). |
||||||
const bool inbound_onion = std::find(m_onion_binds.begin(), m_onion_binds.end(), addr_bind) != m_onion_binds.end(); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit, this is just moving code around without modifying it, feel free to ignore; can be written shorter as:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. think I'll leave this for a refactoring PR that can apply this more systematically. |
||||||
|
||||||
// Tor inbound connections do not reveal the peer's actual network address. | ||||||
// Therefore do not apply address-based whitelist permissions to them. | ||||||
AddWhitelistPermissionFlags(permission_flags, inbound_onion ? std::optional<CNetAddr>{} : addr, vWhitelistedRangeIncoming); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nano nit:
Suggested change
but it is a non-blocking comment. |
||||||
|
||||||
{ | ||||||
LOCK(m_nodes_mutex); | ||||||
|
@@ -1823,7 +1827,6 @@ void CConnman::CreateNodeFromAcceptedSocket(std::unique_ptr<Sock>&& sock, | |||||
NodeId id = GetNewNodeId(); | ||||||
uint64_t nonce = GetDeterministicRandomizer(RANDOMIZER_ID_LOCALHOSTNONCE).Write(id).Finalize(); | ||||||
|
||||||
const bool inbound_onion = std::find(m_onion_binds.begin(), m_onion_binds.end(), addr_bind) != m_onion_binds.end(); | ||||||
// The V2Transport transparently falls back to V1 behavior when an incoming V1 connection is | ||||||
// detected, so use it whenever we signal NODE_P2P_V2. | ||||||
ServiceFlags local_services = GetLocalServices(); | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nano nit for later:
could skip the loop when
addr == std::nullopt