BaseEngine.get_dependent_results_from_database() hangs permanently in unbounded polling loop when prerequisite events fail
Summary
BaseEngine.get_dependent_results_from_database() in nettacker/core/lib/base.py contains an unbounded while True: loop without a timeout or retry limit. When a multi-step scan module (e.g. subdomain_scan, waf_scan, log4j_cve_2021_44228, or geoserver_cve_2024_36401) executes and an earlier prerequisite step fails to store its temporary event, subsequent dependent steps poll the database indefinitely every 100ms. This permanently locks worker threads and deadlocks the entire scan process.
Current Behavior
When a module step specifies dependent_on_temp_event:
BaseEngine.run()callsself.get_dependent_results_from_database(target, module_name, scan_id, event_names).- In
get_dependent_results_from_database, the code loops:for event_name in event_names.split(","): while True: event = find_temp_events(target, module_name, scan_id, event_name) if event: events.append(json.loads(event)["response"]["conditions_results"]) break time.sleep(0.1) - If the prerequisite step failed (e.g. network timeout, connection reset, HTTP 403/429/500, Cloudflare block, or condition mismatch),
find_temp_events()never finds the event and continuously returns[]. - The worker thread loops forever in
while True: ... time.sleep(0.1). - In
nettacker/core/module.py,wait_for_threads_to_finish(active_threads, maximum=None)waits for all threads to terminate. Because the worker thread never exits, the entire Nettacker scan hangs permanently and never produces a report.
Expected Behavior
get_dependent_results_from_database() should poll with a bounded timeout (e.g. timeout = 10.0 seconds or using options.get("timeout", 10.0)). If the expected event does not appear in the database before the timeout expires:
- A warning should be logged indicating the timeout for
event_name. - The loop should exit and return an empty list
[]. - Downstream in
find_and_replace_dependent_values()(base.py:61), the code already contains a guard (if not dependent_on_temp_event: return sub_step) designed to handle empty dependencies. - The step should fail or proceed without substitution gracefully rather than hanging the entire application.
Root Cause
get_dependent_results_from_database() assumes that prerequisite steps will always succeed and insert their event into temp_events. In reality, network failures and target errors frequently prevent temporary events from being generated. The lack of an escape condition or timeout in the while True: loop causes an unrecoverable busy-wait deadlock.
Steps to Reproduce
- Run a scan with a multi-step module relying on
dependent_on_temp_event, such assubdomain_scan:poetry run nettacker -i example.com -m subdomain_scan - Simulate a failure or network block on the initial CSRF retrieval step (
https://dnsdumpster.com/). - Notice that Step 2 enters
get_dependent_results_from_databasewaiting fordnsdumpster_csrf_token. - The process hangs indefinitely and never completes or generates output.
Minimal Python verification:
from nettacker.core.lib.base import BaseEngine
engine = BaseEngine()
# Will loop indefinitely in while True:
engine.get_dependent_results_from_database("target", "subdomain_scan", "scan_123", "non_existent_event")
Proposed Solution
Add a timeout parameter to get_dependent_results_from_database in nettacker/core/lib/base.py:
def get_dependent_results_from_database(
self, target, module_name, scan_id, event_names, timeout=10.0
):
events = []
for event_name in event_names.split(","):
start_time = time.time()
while True:
event = find_temp_events(target, module_name, scan_id, event_name)
if event:
events.append(json.loads(event)["response"]["conditions_results"])
break
if time.time() - start_time >= timeout:
log.warn(
f"Timeout waiting for dependent temporary event '{event_name}' in module '{module_name}'"
)
break
time.sleep(0.1)
return events
Testing
Add a unit test in tests/unit/core/lib/test_base.py:
- Test
get_dependent_results_from_databasewhenfind_temp_eventsreturns[]. - Assert that the method times out cleanly and returns
[]within the configured timeout instead of hanging.
Additional Context
- Affected File:
nettacker/core/lib/base.py:49-58 - Affected Modules:
subdomain_scan,waf_scan,geoserver_cve_2024_36401_vuln, andlog4j_cve_2021_44228_vuln.
Hi! I'd like to take this up. I already have a clear fix in mind for the polling timeout in BaseEngine and will include unit tests. Please assign it to me. Thank you!
Hi! I noticed that @himanchalkaushale has already expressed interest in working on the timeout fix. I wouldn't want to duplicate their work.
Would it be useful for me to contribute alongside them, perhaps by investigating edge cases involving multiple dependencies and timeout behavior, and by writing additional regression tests? I'd be happy to coordinate with them and focus on whatever complementary work would be most helpful to the project.
Thanks!