Skip to content

Commit f7ed8d1

Browse files
fix(asm): remove import and dependency to avoid circular import [backport 2.4] (#7943)
backport of #7923 to 2.4 ## Checklist - [x] Change(s) are motivated and described in the PR description. - [x] Testing strategy is described if automated tests are not included in the PR. - [x] Risk is outlined (performance impact, potential for breakage, maintainability, etc). - [x] Change is maintainable (easy to change, telemetry, documentation). - [x] [Library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) are followed. If no release note is required, add label `changelog/no-changelog`. - [x] Documentation is included (in-code, generated user docs, [public corp docs](https://github.com/DataDog/documentation/)). - [x] Backport labels are set (if [applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)) ## Reviewer Checklist - [ ] Title is accurate. - [ ] No unnecessary changes are introduced. - [ ] Description motivates each change. - [ ] Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes unless absolutely necessary. - [ ] Testing strategy adequately addresses listed risk(s). - [ ] Change is maintainable (easy to change, telemetry, documentation). - [ ] Release note makes sense to a user of the library. - [ ] Reviewer has explicitly acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment. - [ ] Backport labels are set in a manner that is consistent with the [release branch maintenance policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting) - [ ] If this PR touches code that signs or publishes builds or packages, or handles credentials of any kind, I've requested a review from `@DataDog/security-design-and-guidance`. - [ ] This PR doesn't touch any of that.
1 parent a254b7a commit f7ed8d1

File tree

3 files changed

+28
-12
lines changed

3 files changed

+28
-12
lines changed

ddtrace/appsec/_iast/_patches/json_tainting.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
from .._patch import set_module_unpatched
66
from .._patch import try_unwrap
77
from .._patch import try_wrap_function_wrapper
8-
from .._taint_utils import LazyTaintDict
9-
from .._taint_utils import LazyTaintList
10-
from .._taint_utils import taint_structure
118

129

1310
log = get_logger(__name__)
@@ -42,6 +39,8 @@ def patch():
4239

4340

4441
def wrapped_loads(wrapped, instance, args, kwargs):
42+
from .._taint_utils import taint_structure
43+
4544
obj = wrapped(*args, **kwargs)
4645
if asm_config._iast_enabled:
4746
try:
@@ -70,6 +69,9 @@ def wrapped_loads(wrapped, instance, args, kwargs):
7069

7170

7271
def patched_json_encoder_default(original_func, instance, args, kwargs):
72+
from .._taint_utils import LazyTaintDict
73+
from .._taint_utils import LazyTaintList
74+
7375
if isinstance(args[0], (LazyTaintList, LazyTaintDict)):
7476
return args[0]._obj
7577

ddtrace/appsec/_iast/_taint_utils.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#!/usr/bin/env python3
22
from collections import abc
3-
import dataclasses
43
from typing import Any
54
from typing import List
65
from typing import Optional
@@ -19,15 +18,26 @@
1918
# Non Lazy Tainting
2019

2120

22-
@dataclasses.dataclass
21+
# don't use dataclass that can create circular import problems here
22+
# @dataclasses.dataclass
2323
class _DeepTaintCommand:
24-
pre: bool
25-
source_key: str
26-
obj: Any
27-
store_struct: Union[list, dict]
28-
key: Optional[List[str]] = None
29-
struct: Optional[Union[list, dict]] = None
30-
is_key: bool = False
24+
def __init__(
25+
self,
26+
pre: bool,
27+
source_key: str,
28+
obj: Any,
29+
store_struct: Union[list, dict],
30+
key: Optional[List[str]] = None,
31+
struct: Optional[Union[list, dict]] = None,
32+
is_key: bool = False,
33+
):
34+
self.pre = pre
35+
self.source_key = source_key
36+
self.obj = obj
37+
self.store_struct = store_struct
38+
self.key = key
39+
self.struct = struct
40+
self.is_key = is_key
3141

3242
def store(self, value):
3343
if isinstance(self.store_struct, list):
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
fixes:
3+
- |
4+
ASM: This fix resolves an issue where IAST could cause circular dependency at startup.

0 commit comments

Comments
 (0)