1- # This module must not import other modules inconditionnaly that
2- # require iast, ddwaf or any native optional module.
1+ # This module must not import other modules unconditionally that require iast
32
43import ctypes
54import os
1716from ddtrace .appsec ._asm_request_context import get_blocked
1817from ddtrace .appsec ._constants import EXPLOIT_PREVENTION
1918from ddtrace .appsec ._constants import WAF_ACTIONS
20- from ddtrace .appsec ._iast ._iast_request_context import is_iast_request_enabled
21- from ddtrace .appsec ._iast ._metrics import _set_metric_iast_instrumented_sink
22- from ddtrace .appsec ._iast .constants import VULN_PATH_TRAVERSAL
2319import ddtrace .contrib .internal .subprocess .patch as subprocess_patch
2420from ddtrace .internal import core
2521from ddtrace .internal ._exceptions import BlockingException
2925from ddtrace .settings .asm import config as asm_config
3026
3127
28+ if asm_config ._iast_enabled :
29+ from ddtrace .appsec ._iast ._iast_request_context import is_iast_request_enabled
30+ else :
31+
32+ def is_iast_request_enabled () -> bool :
33+ return False
34+
35+
3236log = get_logger (__name__ )
3337_DD_ORIGINAL_ATTRIBUTES : Dict [Any , Any ] = {}
3438
@@ -42,6 +46,16 @@ def patch_common_modules():
4246 global _is_patched
4347 if _is_patched :
4448 return
49+ # for testing purposes, we need to update is_iast_request_enabled
50+ if asm_config ._iast_enabled :
51+ global is_iast_request_enabled
52+ from ddtrace .appsec ._iast ._iast_request_context import is_iast_request_enabled
53+ else :
54+ global is_iast_request_enabled
55+
56+ def is_iast_request_enabled () -> bool :
57+ return False
58+
4559 try_wrap_function_wrapper ("builtins" , "open" , wrapped_open_CFDDB7ABBA9081B6 )
4660 try_wrap_function_wrapper ("urllib.request" , "OpenerDirector.open" , wrapped_open_ED4CF71136E15EBF )
4761 try_wrap_function_wrapper ("_io" , "BytesIO.read" , wrapped_read_F3E51D71B4EC16EF )
@@ -52,6 +66,9 @@ def patch_common_modules():
5266 subprocess_patch .add_lst_callback (_RASP_POPEN , popen_FD233052260D8B4D )
5367 core .on ("asm.block.dbapi.execute" , execute_4C9BAC8E228EB347 )
5468 if asm_config ._iast_enabled :
69+ from ddtrace .appsec ._iast ._metrics import _set_metric_iast_instrumented_sink
70+ from ddtrace .appsec ._iast .constants import VULN_PATH_TRAVERSAL
71+
5572 _set_metric_iast_instrumented_sink (VULN_PATH_TRAVERSAL )
5673 _is_patched = True
5774
0 commit comments