Skip to content

Commit c06c53f

Browse files
authored
chore(iast): rename native classes and methods (#14497)
This PR is part of the ongoing [IAST context refactor](#14466), and focuses on improving the **naming clarity** of internal structures and functions used within the IAST subsystem. ### 🔄 What’s changed? * Renamed several classes and functions to more accurately reflect their role in the taint tracking lifecycle. * Renamed TaintRangeMapType → TaintedObjectMapType. Consumers of this map retrieve a tainted object first, and then access the ranges inside it. This rename clarifies that the value is the tainted object as a whole, not just range metadata. * Renamed get_taint_map → get_tainted_object_map * Replaced previously confusing or ambiguous terms with consistent, descriptive alternatives (e.g., `contexts_array` → `request_context_slots`, `ApplicationContext` -> `TaintEngineContext`, etc.). ### 🧠 Why? The current naming was either overly generic or misleading, making the IAST implementation harder to understand and maintain. This refactor aligns terminology with: ``` Application Request ├── start_request_context() │ ├── Acquire slot from request_context_slots (max 2) │ ├── Get a new request_context_slots │ │ └── Initialize TaintedObjectMap (e.g., empty dict keyed by id(obj)) │ └── Register context into ApplicationContext.context_slots[n] │ ├── Propagation phase │ ├── get_tainted_object_map() → Retrieve current TaintedObjectMap from TaintEngineContext.request_context_slots │ ├── Check if object is tainted via id(obj) in map │ └── If needed, update/add TaintRanges to TaintedObject in TaintedObjectMap │ └── finish_request_context() ├── Clear TaintedObjectMap (remove all taint metadata for the request) └── Release slot in TaintEngineContext.request_context_slots (allow new request to reuse) ``` ## Checklist - [x] PR author has checked that all the criteria below are met - The PR description includes an overview of the change - The PR description articulates the motivation for the change - The change includes tests OR the PR description describes a testing strategy - The PR description notes risks associated with the change, if any - Newly-added code is easy to change - The change follows the [library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) - The change includes or references documentation updates if necessary - Backport labels are set (if [applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)) ## Reviewer Checklist - [x] Reviewer has checked that all the criteria below are met - Title is accurate - All changes are related to the pull request's stated goal - Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes - Testing strategy adequately addresses listed risks - Newly-added code is easy to change - Release note makes sense to a user of the library - If necessary, author has 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)
1 parent c66daf2 commit c06c53f

23 files changed

+326
-257
lines changed

ddtrace/appsec/_iast/_taint_tracking/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from ddtrace.appsec._iast._taint_tracking._native.aspects_ospath import _aspect_ospathsplitdrive # noqa: F401
1919
from ddtrace.appsec._iast._taint_tracking._native.aspects_ospath import _aspect_ospathsplitext # noqa: F401
2020
from ddtrace.appsec._iast._taint_tracking._native.aspects_ospath import _aspect_ospathsplitroot # noqa: F401
21-
from ddtrace.appsec._iast._taint_tracking._native.context import get_taint_map # noqa: F401
21+
from ddtrace.appsec._iast._taint_tracking._native.context import is_in_taint_map # noqa: F401
2222
from ddtrace.appsec._iast._taint_tracking._native.initializer import active_map_addreses_size # noqa: F401
2323
from ddtrace.appsec._iast._taint_tracking._native.initializer import debug_taint_map # noqa: F401
2424
from ddtrace.appsec._iast._taint_tracking._native.initializer import num_objects_tainted # noqa: F401
@@ -73,7 +73,7 @@
7373
"debug_taint_map",
7474
"get_range_by_hash",
7575
"get_ranges",
76-
"get_taint_map",
76+
"is_in_taint_map",
7777
"is_tainted",
7878
"new_pyobject_id",
7979
"num_objects_tainted",

ddtrace/appsec/_iast/_taint_tracking/_context.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1+
from ddtrace.appsec._iast._taint_tracking._native.context import finish_request_context
2+
from ddtrace.appsec._iast._taint_tracking._native.context import start_request_context
13
from ddtrace.appsec._iast._taint_tracking._native.initializer import create_context # noqa: F401
24
from ddtrace.appsec._iast._taint_tracking._native.initializer import reset_context # noqa: F401
35
from ddtrace.appsec._iast._taint_tracking._native.initializer import reset_contexts # noqa: F401
46

57

68
__all__ = [
9+
"start_request_context",
10+
"finish_request_context",
711
"create_context",
812
"reset_context",
913
"reset_contexts",

ddtrace/appsec/_iast/_taint_tracking/_taint_objects_base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from ddtrace.appsec._iast._logs import iast_propagation_error_log
77
from ddtrace.appsec._iast._taint_tracking import OriginType
88
from ddtrace.appsec._iast._taint_tracking import get_ranges
9-
from ddtrace.appsec._iast._taint_tracking import get_taint_map
9+
from ddtrace.appsec._iast._taint_tracking import is_in_taint_map
1010
from ddtrace.appsec._iast._taint_tracking import is_tainted
1111
from ddtrace.appsec._iast._taint_tracking import origin_to_str
1212
from ddtrace.appsec._iast._taint_tracking import set_ranges
@@ -149,7 +149,7 @@ def is_pyobject_tainted_new(pyobject: Any) -> bool:
149149
return False
150150

151151
try:
152-
return get_taint_map(pyobject)
152+
return is_in_taint_map(pyobject)
153153
except ValueError as e:
154154
iast_propagation_error_log(f"Checking tainted object error: {e}")
155155
return False

ddtrace/appsec/_iast/_taint_tracking/aspects/aspect_index.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ index_aspect(PyObject* result_o,
1717
const PyObject* candidate_text,
1818
PyObject* idx,
1919
const TaintRangeRefs& ranges,
20-
const TaintRangeMapTypePtr& tx_map)
20+
const TaintedObjectMapTypePtr& tx_map)
2121
{
2222
TaintRangeRefs ranges_to_set;
2323

ddtrace/appsec/_iast/_taint_tracking/aspects/aspect_index.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ index_aspect(PyObject* result_o,
66
const PyObject* candidate_text,
77
PyObject* idx,
88
const TaintRangeRefs& ranges,
9-
const TaintRangeMapTypePtr& tx_taint_map);
9+
const TaintedObjectMapTypePtr& tx_taint_map);
1010
PyObject*
1111
api_index_aspect(PyObject* self, PyObject* const* args, Py_ssize_t nargs);

ddtrace/appsec/_iast/_taint_tracking/aspects/aspect_join.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ aspect_join_str(PyObject* sep,
77
PyObject* result,
88
PyObject* iterable_str,
99
size_t len_iterable,
10-
const TaintRangeMapTypePtr& tx_taint_map)
10+
const TaintedObjectMapTypePtr& tx_taint_map)
1111
{
1212
// This is the special case for unicode str and unicode iterable_str.
1313
// The iterable elements string will be split into 1 char-length strings.
@@ -60,7 +60,7 @@ aspect_join_str(PyObject* sep,
6060
}
6161

6262
PyObject*
63-
aspect_join(PyObject* sep, PyObject* result, PyObject* iterable_elements, const TaintRangeMapTypePtr& tx_taint_map)
63+
aspect_join(PyObject* sep, PyObject* result, PyObject* iterable_elements, const TaintedObjectMapTypePtr& tx_taint_map)
6464
{
6565
const size_t& len_sep = get_pyobject_size(sep);
6666

ddtrace/appsec/_iast/_taint_tracking/aspects/aspect_operator_add.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ PyObject*
1515
add_aspect(PyObject* result_o,
1616
PyObject* candidate_text,
1717
PyObject* text_to_add,
18-
const TaintRangeMapTypePtr& tx_taint_map)
18+
const TaintedObjectMapTypePtr& tx_taint_map)
1919
{
2020
const size_t len_candidate_text{ get_pyobject_size(candidate_text) };
2121
const size_t len_text_to_add{ get_pyobject_size(text_to_add) };

ddtrace/appsec/_iast/_taint_tracking/aspects/aspect_split.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ static std::optional<py::object>
66
handle_potential_re_split(const py::tuple& args,
77
const py::tuple& sliced_args,
88
const py::kwargs& kwargs,
9-
const TaintRangeMapTypePtr& tx_map)
9+
const TaintedObjectMapTypePtr& tx_map)
1010
{
1111
const py::module re = py::module::import("re");
1212
const py::object re_pattern_type = re.attr("Pattern");

ddtrace/appsec/_iast/_taint_tracking/aspects/aspect_str.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ static void
55
set_lengthupdated_ranges(PyObject* result,
66
Py_ssize_t result_len,
77
const TaintRangeRefs& ranges,
8-
const TaintRangeMapTypePtr& tx_map)
8+
const TaintedObjectMapTypePtr& tx_map)
99
{
1010
if (!tx_map || tx_map->empty()) {
1111
return;

ddtrace/appsec/_iast/_taint_tracking/aspects/helpers.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ bool
299299
set_ranges_on_splitted(const py::object& source_str,
300300
const TaintRangeRefs& source_ranges,
301301
const py::list& split_result,
302-
const TaintRangeMapTypePtr& tx_map,
302+
const TaintedObjectMapTypePtr& tx_map,
303303
bool include_separator)
304304
{
305305
RANGE_START offset = 0;

0 commit comments

Comments
 (0)