Repository navigation
fix: Guard mnauth by local masternode service #4974
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
base: develop
Are you sure you want to change the base?
Changes from all commits
7a83064
68bf217
d71d09e
8a256b5
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 | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -21,9 +21,22 @@ | |||||||||||||||||||||||||||||||||||||||
| void CMNAuth::PushMNAUTH(CNode& peer, CConnman& connman, const CActiveMasternodeManager& mn_activeman) | ||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||
| CMNAuth mnauth; | ||||||||||||||||||||||||||||||||||||||||
| if (mn_activeman.GetProTxHash().IsNull()) { | ||||||||||||||||||||||||||||||||||||||||
| const uint256 pro_tx_hash{mn_activeman.GetProTxHash()}; | ||||||||||||||||||||||||||||||||||||||||
| if (pro_tx_hash.IsNull()) { | ||||||||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| if (peer.IsInboundConn()) { | ||||||||||||||||||||||||||||||||||||||||
| const CService expected_service{mn_activeman.GetService()}; | ||||||||||||||||||||||||||||||||||||||||
| const CService connected_service{static_cast<const CService&>(peer.addrBind)}; | ||||||||||||||||||||||||||||||||||||||||
| if (expected_service.GetPort() != connected_service.GetPort() || | ||||||||||||||||||||||||||||||||||||||||
| expected_service.GetNetwork() != peer.ConnectedThroughNetwork()) { | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+29
to
+32
Collaborator
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. 🔴 Blocking: An unregistered same-port listener reveals the masternode identity, while a port-translated registered service withholds it The port check lets an unrelated listener disclose the ProTx hash and rejects legitimate traffic that reached the registered public endpoint through a port-translating router. source:
Comment on lines
+31
to
+32
Collaborator
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. 🔴 Blocking: A public IPv4 masternode stops authenticating when its forwarder rewrites peer addresses to loopback Peers reaching the correct public endpoint lose MNAUTH even when the forwarder preserves the destination port. For non-onion connections, source: |
||||||||||||||||||||||||||||||||||||||||
| LogPrint(BCLog::NET_NETCONN, /* Continued */ | ||||||||||||||||||||||||||||||||||||||||
| "CMNAuth::%s -- Not sending MNAUTH on unexpected local service, expected=%s, connected=%s, " | ||||||||||||||||||||||||||||||||||||||||
| "peer=%d\n", | ||||||||||||||||||||||||||||||||||||||||
| __func__, expected_service.ToStringAddrPort(), connected_service.ToStringAddrPort(), peer.GetId()); | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+29
to
+36
Collaborator
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. 💬 Nitpick: Redundant
💡 Suggested change
Suggested change
source: ['claude'] |
||||||||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+28
to
+39
Collaborator
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. 🟡 Suggestion: Same-port multi-bind IPv4 listeners are still indistinguishable; For non-onion inbound peers,
This is not a regression — strict address equality would re-break the NAT case the PR is designed to fix, and the consensus-critical privacy concern (onion deanonymization) is correctly handled because source: ['claude', 'codex'] 🤖 Fix this with AI agents |
||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| const auto receivedMNAuthChallenge = peer.GetReceivedMNAuthChallenge(); | ||||||||||||||||||||||||||||||||||||||||
| if (receivedMNAuthChallenge.IsNull()) { | ||||||||||||||||||||||||||||||||||||||||
|
|
@@ -41,7 +54,7 @@ void CMNAuth::PushMNAUTH(CNode& peer, CConnman& connman, const CActiveMasternode | |||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| const uint256 signHash{::SerializeHash(std::make_tuple(mn_activeman.GetPubKey(), receivedMNAuthChallenge, peer.IsInboundConn(), nOurNodeVersion))}; | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| mnauth.proRegTxHash = mn_activeman.GetProTxHash(); | ||||||||||||||||||||||||||||||||||||||||
| mnauth.proRegTxHash = pro_tx_hash; | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| // all clients uses basic BLS | ||||||||||||||||||||||||||||||||||||||||
| mnauth.sig = mn_activeman.Sign(signHash); | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| #!/usr/bin/env python3 | ||
| # Copyright (c) 2026 The Dash Core developers | ||
| # Distributed under the MIT software license, see the accompanying | ||
| # file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
|
||
| """ | ||
| Test that a masternode sends MNAUTH only to inbound peers that reached it on its registered | ||
| service: the local port must match and the connection must not come from another network class. | ||
| """ | ||
|
|
||
| import platform | ||
|
|
||
| from test_framework.test_framework import ( | ||
| DashTestFramework, | ||
| MasternodeInfo, | ||
| ) | ||
| from test_framework.util import ( | ||
| assert_equal, | ||
| force_finish_mnsync, | ||
| p2p_port, | ||
| ) | ||
|
|
||
|
|
||
| class P2PMNAUTHTest(DashTestFramework): | ||
|
Collaborator
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. I merged 2 functional tests to one file; p2p_mnauth.py tests now both scenarios |
||
| def add_options(self, parser): | ||
| self.add_wallet_options(parser) | ||
|
|
||
| def set_test_params(self): | ||
| # Keep every bind of the masternode visible here instead of the implicit bind=127.0.0.1 | ||
| self.bind_to_localhost_only = False | ||
| self.mn_port = p2p_port(2) | ||
| self.alt_port = p2p_port(10) | ||
| # Only Linux routes all of 127.0.0.0/8 to the loopback interface by default | ||
| self.has_loopback_aliases = platform.system() == "Linux" | ||
|
|
||
| self.mn_args = [f"-externalip=127.0.0.1:{self.mn_port}"] | ||
| binds = [f"-bind=127.0.0.1:{self.mn_port}", f"-bind=127.0.0.1:{self.alt_port}"] | ||
| if self.has_loopback_aliases: | ||
| binds.append(f"-bind=127.0.0.2:{self.mn_port}") | ||
| self.set_dash_test_params(3, 1, extra_args=[[], [], self.mn_args + binds]) | ||
|
|
||
| def probe(self, addr, *, expect_mnauth): | ||
| transport = 'v2' if self.options.v2transport else 'v1' | ||
| self.log.info(f"Probe {addr} over {transport}, expect {'MNAUTH' if expect_mnauth else 'no MNAUTH'}") | ||
| if expect_mnauth: | ||
| connector_log = f"Masternode probe successful for {self.mn.proTxHash}" | ||
| mn_log = "Sending MNAUTH" | ||
| else: | ||
| connector_log = "connection is a masternode probe but first received message is not MNAUTH" | ||
| mn_log = "Not sending MNAUTH on unexpected local service" | ||
| with self.mn_node.assert_debug_log([mn_log]), self.connector.assert_debug_log([connector_log]): | ||
| assert_equal(self.connector.masternode("connect", addr, self.options.v2transport), "successfully connected") | ||
|
|
||
| def wait_for_ready(self): | ||
| self.wait_until(lambda: self.mn_node.masternode("status")["state"] == "READY") | ||
| assert_equal(self.mn_node.masternode("status")["service"], f"127.0.0.1:{self.mn_port}") | ||
|
|
||
| def run_test(self): | ||
| self.mn: MasternodeInfo = self.mninfo[0] | ||
| self.mn_node = self.mn.get_node(self) | ||
| self.connector = self.nodes[1] | ||
| assert_equal(self.mn.nodePort, self.mn_port) | ||
|
|
||
| self.wait_for_ready() | ||
| self.probe(f"127.0.0.1:{self.mn_port}", expect_mnauth=True) | ||
| self.probe(f"127.0.0.1:{self.alt_port}", expect_mnauth=False) | ||
| if self.has_loopback_aliases: | ||
| # NAT-style: the bind address differs from the advertised one, the port matches | ||
| self.probe(f"127.0.0.2:{self.mn_port}", expect_mnauth=True) | ||
|
|
||
| self.log.info("Tag the registered port as an onion listener: port matches, only the network differs") | ||
| self.stop_node(self.mn.nodeIdx) | ||
| self.start_node(self.mn.nodeIdx, extra_args=[f"-masternodeblsprivkey={self.mn.keyOperator}", | ||
| f"-bind=127.0.0.1:{self.mn_port}=onion"] + self.mn_args) | ||
| force_finish_mnsync(self.mn_node) | ||
| self.wait_for_ready() | ||
| self.probe(f"127.0.0.1:{self.mn_port}", expect_mnauth=False) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| P2PMNAUTHTest().main() | ||
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.
Preserve authentication through source-rewriting IPv4 forwarders.
If a publicly registered IPv4 service receives a forwarded connection from
127.0.0.1, both ports can match, butConnectedThroughNetwork()returnsNET_UNROUTABLE. Line 32 then suppresses MNAUTH because the registered service returnsNET_IPV4. These classification results follow from the checked implementations. (raw.githubusercontent.com)This breaks authentication for every inbound connection through that forwarder. The loopback test misses this case because its registered service is also unroutable. Compare non-onion address families without using routability as the discriminator. Preserve the onion override and port check, and add a public-service/local-forwarder regression case.