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
3
2
4
3
import ctypes
5
4
import os
17
16
from ddtrace .appsec ._asm_request_context import get_blocked
18
17
from ddtrace .appsec ._constants import EXPLOIT_PREVENTION
19
18
from 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
23
19
import ddtrace .contrib .internal .subprocess .patch as subprocess_patch
24
20
from ddtrace .internal import core
25
21
from ddtrace .internal ._exceptions import BlockingException
29
25
from ddtrace .settings .asm import config as asm_config
30
26
31
27
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
+
32
36
log = get_logger (__name__ )
33
37
_DD_ORIGINAL_ATTRIBUTES : Dict [Any , Any ] = {}
34
38
@@ -42,6 +46,16 @@ def patch_common_modules():
42
46
global _is_patched
43
47
if _is_patched :
44
48
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
+
45
59
try_wrap_function_wrapper ("builtins" , "open" , wrapped_open_CFDDB7ABBA9081B6 )
46
60
try_wrap_function_wrapper ("urllib.request" , "OpenerDirector.open" , wrapped_open_ED4CF71136E15EBF )
47
61
try_wrap_function_wrapper ("_io" , "BytesIO.read" , wrapped_read_F3E51D71B4EC16EF )
@@ -52,6 +66,9 @@ def patch_common_modules():
52
66
subprocess_patch .add_lst_callback (_RASP_POPEN , popen_FD233052260D8B4D )
53
67
core .on ("asm.block.dbapi.execute" , execute_4C9BAC8E228EB347 )
54
68
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
+
55
72
_set_metric_iast_instrumented_sink (VULN_PATH_TRAVERSAL )
56
73
_is_patched = True
57
74
0 commit comments