test: avoid non-loopback network traffic from node_init_tests/init_test
What changed, and why it matters
This is a test-hardening change, not a fix for an exploitable vulnerability in live Bitcoin Core. The patch stops automated tests from accidentally sending real network traffic (router NAT-PMP packets and DNS queries) to non-localhost destinations. It does not change how normal node software behaves when users run it.
No urgent action required. Treat as routine test hygiene. Reviewers may want to confirm that all test entry points inherit BasicTestingSetup and that no other test paths still enable UPnP/NATPMP or DNS seeding by default.
Security signals we found
Network egress from test harnesses can leak test activity, trigger IDS, or interact with local routers/DNS resolvers
NATPMP and DNSSEED are disabled only inside test setup code via ForceSetArg
No change to production defaults or consensus/network code
Commit title and message describe the change as test-only hardening
Evidence from the diff
The commit modifies BasicTestingSetup to force -dnsseed=0 and -natpmp=0 for C++ unit tests, mirroring the existing natpmp=0 setting in the Python functional-test framework. The goal is to prevent AppInitMain/StartMapPort/ThreadMapPort from creating outbound sockets during tests such as node_init_tests/init_test. The change is defensive test isolation; it does not alter mainnet/regtest node defaults or fix a code-level bug that an attacker could trigger remotely.
Changed components
src/test/util/setup_common.cpptest/functional/test_framework/util.pyInspect captured patch +5 / −1
diff --git a/src/test/util/setup_common.cpp b/src/test/util/setup_common.cpp
index 39c691c3..349d7cbd 100644
--- a/src/test/util/setup_common.cpp
+++ b/src/test/util/setup_common.cpp
@@ -199,6 +199,10 @@ BasicTestingSetup::BasicTestingSetup(const ChainType chainType, TestOpts opts)
m_args.ForceSetArg("-datadir", fs::PathToString(m_path_root));
gArgs.ForceSetArg("-datadir", fs::PathToString(m_path_root));
+ // Avoid non-loopback network traffic during tests.
+ gArgs.ForceSetArg("-dnsseed", "0"); // DNS queries are usually forwarded to upstream DNS servers.
+ gArgs.ForceSetArg("-natpmp", "0"); // NATPMP sends packets to the router.
+
SelectParams(chainType);
InitLogging(*m_node.args);
AppInitParameterInteraction(*m_node.args);
diff --git a/test/functional/test_framework/util.py b/test/functional/test_framework/util.py
index 3e7e6dd9..4918a7f4 100644
--- a/test/functional/test_framework/util.py
+++ b/test/functional/test_framework/util.py
@@ -576,7 +576,7 @@ def write_config(config_path, *, n, chain, extra_config="", disable_autoconnect=
# in tests.
f.write("peertimeout=999999999\n")
f.write("printtoconsole=0\n")
- f.write("natpmp=0\n")
+ f.write("natpmp=0\n") # Avoid non-loopback network traffic during tests.
f.write("shrinkdebugfile=0\n")
# To improve SQLite wallet performance so that the tests don't timeout, use -unsafesqlitesync
f.write("unsafesqlitesync=1\n")
Why this scored 23/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.