1616from aikido_zen .helpers .logging import logger
1717from aikido_zen .helpers .get_clean_stacktrace import get_clean_stacktrace
1818from aikido_zen .helpers .blocking_enabled import is_blocking_enabled
19- from aikido_zen .helpers .is_protection_forced_off_cached import (
20- is_protection_forced_off_cached ,
19+ from aikido_zen .helpers .should_skip_attack_scan import (
20+ should_skip_attack_scan ,
2121)
2222from aikido_zen .thread .thread_cache import get_cache
2323from .sql_injection .context_contains_sql_injection import context_contains_sql_injection
@@ -37,25 +37,12 @@ def run_vulnerability_scan(kind, op, args):
3737 raises error if blocking is enabled, communicates it with connection_manager
3838 """
3939 context = get_current_context ()
40-
41- if is_protection_forced_off_cached (context ):
40+ if should_skip_attack_scan (context ) and kind != "ssrf" :
41+ # Make a special exception for SSRF:
42+ # For stored ssrf we don't want to check bypassed IPs or protection forced off.
4243 return
4344
4445 comms = comm .get_comms ()
45- thread_cache = get_cache ()
46- if not context and kind != "ssrf" :
47- # Make a special exception for SSRF, which checks itself if context is set.
48- # This is because some scans/tests for SSRF do not require a context to be set.
49- return
50-
51- if not thread_cache and kind != "ssrf" :
52- # Make a special exception for SSRF, which checks itself if thread cache is set.
53- # This is because some scans/tests for SSRF do not require a thread cache to be set.
54- return
55- if thread_cache and context :
56- if thread_cache .is_bypassed_ip (context .remote_address ):
57- # This IP is on the bypass list, not scanning
58- return
5946
6047 error_type = AikidoException # Default error
6148 error_args = tuple ()
@@ -87,6 +74,7 @@ def run_vulnerability_scan(kind, op, args):
8774 injection_results = inspect_getaddrinfo_result (dns_results , hostname , port )
8875 error_type = AikidoSSRF
8976
77+ thread_cache = get_cache ()
9078 if thread_cache and port > 0 :
9179 thread_cache .hostnames .add (hostname , port )
9280 else :
@@ -101,7 +89,10 @@ def run_vulnerability_scan(kind, op, args):
10189
10290 blocked = is_blocking_enabled ()
10391 operation = injection_results ["operation" ]
104- thread_cache .stats .on_detected_attack (blocked , operation )
92+
93+ thread_cache = get_cache ()
94+ if thread_cache :
95+ thread_cache .stats .on_detected_attack (blocked , operation )
10596
10697 stack = get_clean_stacktrace ()
10798
0 commit comments