Skip to content

Commit 9c036b7

Browse files
fix(iast): avoid early and potentially unneeded iast import [backport 1.18] (#6794)
Backport 2cbaf87 from #6791 to 1.18. ## 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 - [x] Title is accurate. - [x] No unnecessary changes are introduced. - [x] Description motivates each change. - [x] Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes unless absolutely necessary. - [x] Testing strategy adequately addresses listed risk(s). - [x] Change is maintainable (easy to change, telemetry, documentation). - [x] Release note makes sense to a user of the library. - [x] Reviewer has explicitly acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment. - [x] 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) Co-authored-by: Alberto Vara <[email protected]>
1 parent d3eadbf commit 9c036b7

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

ddtrace/appsec/iast/_taint_utils.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#!/usr/bin/env python3
22
from collections import abc
33

4-
from ddtrace.appsec.iast._taint_tracking import is_pyobject_tainted
5-
from ddtrace.appsec.iast._taint_tracking import taint_pyobject
64
from ddtrace.internal.logger import get_logger
75

86

@@ -32,6 +30,9 @@ def __init__(self, original_list, origins=(0, 0), override_pyobject_tainted=Fals
3230
def _taint(self, value):
3331
if value:
3432
if isinstance(value, (str, bytes, bytearray)):
33+
from ddtrace.appsec.iast._taint_tracking import is_pyobject_tainted
34+
from ddtrace.appsec.iast._taint_tracking import taint_pyobject
35+
3536
if not is_pyobject_tainted(value) or self._override_pyobject_tainted:
3637
try:
3738
# TODO: migrate this part to shift ranges instead of creating a new one
@@ -200,6 +201,9 @@ def _taint(self, value, key, origin=None):
200201
origin = self._origin_value
201202
if value:
202203
if isinstance(value, (str, bytes, bytearray)):
204+
from ddtrace.appsec.iast._taint_tracking import is_pyobject_tainted
205+
from ddtrace.appsec.iast._taint_tracking import taint_pyobject
206+
203207
if not is_pyobject_tainted(value) or self._override_pyobject_tainted:
204208
try:
205209
# TODO: migrate this part to shift ranges instead of creating a new one
@@ -375,6 +379,8 @@ def supported_dbapi_integration(integration_name):
375379

376380
def check_tainted_args(args, kwargs, tracer, integration_name, method):
377381
if supported_dbapi_integration(integration_name) and method.__name__ == "execute":
382+
from ddtrace.appsec.iast._taint_tracking import is_pyobject_tainted
383+
378384
return len(args) and args[0] and is_pyobject_tainted(args[0])
379385

380386
return False
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fixes:
2+
- |
3+
ASM: avoid potentially unneeded import of the IAST native module if setup doesn't build extensions correctly.

0 commit comments

Comments
 (0)