Skip to content

feat(iast): enable Code Security on Python 3.15 - #19698

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 6 commits into
mainfrom
avara1986/iast-python-315-support
Aug 25, 2026
Merged

feat(iast): enable Code Security on Python 3.15#19698
gh-worker-dd-mergequeue-cf854d[bot] merged 6 commits into
mainfrom
avara1986/iast-python-315-support

Conversation

@avara1986

@avara1986 avara1986 commented Aug 14, 2026

Copy link
Copy Markdown
Member

Description

Part of the Python 3.15 integration parity effort (parent tracker: #17809).

Closes #17843

APPSEC-69649

This PR enables IAST (Code Security) on Python 3.15.

There was no upstream blocker to bump. IAST's native extensions were never version-gated —
setup.py adds _iast._ast.iastpatch and _iast._taint_tracking._native under a platform-only
guard — so the only thing disabling Code Security on 3.15 was the runtime tuple in
ASMConfig._iast_supported. This widens it from < (3, 15, 0) to < (3, 16, 0) and corrects the
adjacent comment, which already said "3.6 to 3.13" while the code allowed 3.14.

Validating that gate surfaced two real bugs, both fixed here (see Bugs found below). The
eval() one matters: without it, turning IAST on for 3.15 would raise NameError inside customer
application code.

Changes

  • ddtrace/internal/settings/asm.py — widen _iast_supported to 3.15, fix the stale comment, add
    an AIDEV-NOTE recording that this is the only version gate and that the native extensions have
    no build-time gate.
  • ddtrace/appsec/_iast/taint_sinks/code_injection.py — add _resolve_caller_frame() so the
    code-injection aspect walks past wrapt's wrapper frame when locating the caller of eval().
  • tests/appsec/iast/aspects/test_slice_aspect_fixtures.py — accept CPython 3.15's reworded slice
    TypeError.
  • Two release notes (features for 3.15 support, fixes for the eval() bug).

Bugs found during validation

1. eval() raised NameError in application code whenever wrapt's C extension is absent.

_iast_coi resolved its caller with a fixed inspect.currentframe().f_back. That only lands on the
user's frame while wrapt uses its C FunctionWrapper, which creates no Python frame. wrapt ships no
cp315 wheel, so 3.15 falls back to the pure-Python implementation, which does add a frame — the
aspect then passed wrapt's globals/locals to eval(), so a lambda default like
eval("lambda v,fun=fun: not fun(v)") could not see fun.

This is pre-existing, not 3.15-specific. It reproduces on 3.14:

$ WRAPT_DISABLE_EXTENSIONS=1 python repro.py
NameError: name 'fun' is not defined      # before
OK: False                                 # after

2. CPython 3.15 reworded its slice error message, dropping the or None clause
(slice indices must be integers or None or have an __index__ method
slice indices must be integers or have an __index__ method). The aspect raises correctly; only the
test's asserted substring was stale.

Checklist

Adapted — several template items don't apply, because the blocker here was a runtime version check
rather than an upstream package pin:

  • Bumped upstream pin in riotfile.pyN/A, no upstream dependency involved.
  • Lifted max_version cap on the affected venv(s)N/A, the cap was a
    sys.version_info check, not a riot cap.
  • Ran riot generate and committed lockfilesN/A, riotfile.py is unchanged. The
    IAST venvs already use select_pys(), so they pick up 3.15 automatically once it joins
    SUPPORTED_PYTHON_VERSIONS.
  • Ran the suites on 3.15 — see Testing. Note this could not go through
    scripts/run-tests; see the caveat there.
  • Updated supported_versions.jsonN/A, that file tracks per-integration package
    versions and has no IAST row.
  • Release notes added under releasenotes/notes/.

Testing

Built CPython 3.15.0rc1+dev via pyenv install 3.15-dev (matching .python-version and
.gitlab/testrunner.yml), stacked #17849 in a scratch worktree to get past the import ddtrace
blocker, and locally bumped requires-python so pip install -e . would run. Neither of those
local-only edits is in this PR.

Check Result
pip install -e . on 3.15 pass — _native.cpython-315*.so and iastpatch.cpython-315*.so both produced
Native C++ gtest (appsec_iast_native) 186/186 pass
tests/appsec/iast/ 19,625 passed, 0 failed, 59 skipped, 18 xfailed
tests/appsec/iast_tdd_propagation/ 1 passed, 6 skipped (all pre-existing >= (3, 14) skips)
appsec_iast_default on 3.14 (riot) pass
appsec_iast_default on 3.13 (riot) pass

CMake was confirmed to resolve the right interpreter (3.15 headers + libpython3.15.so) rather than
silently picking the system Python.

Notable positives: test_template_string_aspect.py (PEP-750 t-strings, 3.14+) collects and
passes
on 3.15, exercising the PY_VERSION_HEX >= 0x030E0000 branch of
utils/string_utils.cpp; and test_native_taint_range.py's refcount assertions hold under 3.15.

Why raw pytest for the 3.15 leg. AGENTS.md says never to invoke pytest directly, but riot
cannot target 3.15 at all today: riotfile.py:SUPPORTED_PYTHON_VERSIONS and
scripts/gen_gitlab_config.py:ALL_PYTHON_VERSIONS both stop at 3.14, and there are zero 3.15
lockfiles. The env=/pkgs= blocks were replicated by hand from the appsec_iast_default venv.
Both 3.13/3.14 regression runs went through scripts/run-tests as normal. Excluded on 3.15:
test_grpc_iast.py (grpcio has no cp315 wheel).

Risks

Additional Notes

Findings handed to the Python 3.15 migration owners — all outside this PR's scope:

  • PYO3_USE_ABI3_FORWARD_COMPATIBILITY=1 breaks the 3.15 build. It forces limited-API mode,
    which excludes PyContextVar_New/Get/Set, so src/native/contextvar.rs fails with E0425.
    pyo3 0.28 supports 3.15 natively, so the flag is counterproductive there.
  • tests/conftest.py blocks every test on 3.15. The autouse enable_crashtracking fixture
    asserts crashtracking.is_started(), but setup.py drops the crashtracker Rust feature on 3.15,
    so is_available is False and start() returns early. Needs
    yield platform.system() == "Linux" and crashtracking.is_available.
  • pip<25 cannot be satisfied on 3.15. appsec_iast_default pins it to work around IAST
    first-party detection, but pip 24.x fails to import on 3.15 (typing.no_type_check_decorator was
    removed). Resolving the iastpatch.c TODO is a prerequisite for that suite on 3.15.
  • On the chore: wrapping context support for Python 3.15 #17849 branch, ddtrace/internal/coverage/import_instrumentation_py3_12.py imports
    INJECTION_ASSEMBLY, which no longer exists in ddtrace.internal.bytecode_injection. This breaks
    ddtrace's own pytest plugin on all Python versions, not just 3.15.
  • The 3.14 release notes (python-314-f80c8356eaaf8392.yaml, more-314-suites-bf99a7d7ef1b2128.yaml)
    still list IAST as not working on 3.14, which was already inaccurate before this PR. Left
    untouched, since both shipped in v3.16.0rc1.

🤖 Generated with Claude Code

Lifts the IAST version gate in ASMConfig from < 3.15 to < 3.16 so
DD_IAST_ENABLED takes effect on Python 3.15 instead of being silently
ignored. No build change is needed: the IAST native extensions are gated
on platform only, never on Python version.

Validated on Python 3.15.0rc1+dev: both native extensions build for
cp315, the native taint-tracking gtest suite passes 186/186 against real
3.15 headers, and tests/appsec/iast/ is green (19,625 passed). No
regression on 3.13 or 3.14.

Two bugs surfaced during validation and are fixed here:

- The code-injection aspect resolved the wrong caller scope, raising
  NameError in application code that calls eval(). It assumed a fixed
  inspect.currentframe().f_back depth, which only holds while wrapt uses
  its C extension. wrapt has no cp315 wheel, so 3.15 falls back to the
  pure-Python FunctionWrapper, which adds a frame. This is pre-existing
  rather than 3.15-specific: it reproduces on 3.14 with
  WRAPT_DISABLE_EXTENSIONS=1.
- CPython 3.15 dropped the "or None" clause from its slice TypeError,
  so test_slice_aspect_fixtures.py asserted a message that no longer
  exists.

IAST on 3.15 stays unreachable until the tracer wrapping work (#17849)
and the requires-python / riot matrix bumps land, so this is correct but
inert until then.

Closes #17843
APPSEC-69649

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@cit-pr-commenter-54b7da

cit-pr-commenter-54b7da Bot commented Aug 14, 2026

Copy link
Copy Markdown

Circular import analysis

⚠️ Existing circular imports

There are 3 circular imports that already exist on the base branch and have not been changed by this PR.

ddtrace.llmobs -> ddtrace.llmobs._evaluators -> ddtrace.llmobs._evaluators.format -> ddtrace.llmobs._experiment -> ddtrace.llmobs
ddtrace.errortracking._handled_exceptions.bytecode_injector -> ddtrace.errortracking._handled_exceptions.callbacks -> ddtrace.errortracking._handled_exceptions.collector -> ddtrace.errortracking._handled_exceptions.bytecode_reporting -> ddtrace.errortracking._handled_exceptions.bytecode_injector
ddtrace.appsec._asm_request_context -> ddtrace.appsec._iast._iast_request_context_base -> ddtrace.appsec._iast._iast_env -> ddtrace.appsec._iast.reporter -> ddtrace.appsec._exploit_prevention.stack_traces -> ddtrace.appsec._asm_request_context

@cit-pr-commenter-54b7da

cit-pr-commenter-54b7da Bot commented Aug 14, 2026

Copy link
Copy Markdown

Codeowners resolved as

Resolved from the full PR diff against main using the target branch CODEOWNERS file.
CODEOWNERS team requests not listed below are not required by the current file set.

No remaining files require a CODEOWNERS review.

@cit-pr-commenter-54b7da

cit-pr-commenter-54b7da Bot commented Aug 14, 2026

Copy link
Copy Markdown

Dependency direction analysis

⚠️ Existing dependency direction violations

There are 250 dependency direction violations that already exist on the base branch and have not been changed by this PR.

Show existing violations (showing 5 of 250 highest severity)
ddtrace.internal.tracemethods -×-> ddtrace.trace  (internal-core -> product:tracing, score=135)
ddtrace.debugging._exception.replay -×-> ddtrace.trace  (product:debugging -> product:tracing, score=133)
ddtrace.llmobs._integrations.openai -×-> ddtrace.trace  (product:llmobs -> product:tracing, score=133)
ddtrace.internal.ci_visibility.filters -×-> ddtrace.trace  (product:ci_visibility -> product:tracing, score=133)
ddtrace.debugging._debugger -×-> ddtrace.trace  (product:debugging -> product:tracing, score=133)

To see all violations, download the layers-base.json and layers-pr.json artifacts from this CI job and run:

uv run --script scripts/import-analysis/layers.py compare layers-base.json layers-pr.json

@pr-commenter

pr-commenter Bot commented Aug 14, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-08-24 15:06:38

Comparing candidate commit 7509b17 in PR branch avara1986/iast-python-315-support with baseline commit c6197c1 in branch main.

📊 Benchmarking dashboard

Found 0 performance improvements and 2 performance regressions! Performance is the same for 82 metrics, 0 unstable metrics.

Explanation

This is an A/B test comparing a candidate commit's performance against that of a baseline commit. Performance changes are noted in the tables below as:

  • 🟩 = significantly better candidate vs. baseline
  • 🟥 = significantly worse candidate vs. baseline

We compute a confidence interval (CI) over the relative difference of means between metrics from the candidate and baseline commits, considering the baseline as the reference.

If the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD), the change is considered significant.

Feel free to reach out to #apm-benchmarking-platform on Slack if you have any questions.

More details about the CI and significant changes

You can imagine this CI as a range of values that is likely to contain the true difference of means between the candidate and baseline commits.

CIs of the difference of means are often centered around 0%, because often changes are not that big:

---------------------------------(------|---^--------)-------------------------------->
                              -0.6%    0%  0.3%     +1.2%
                                 |          |        |
         lower bound of the CI --'          |        |
sample mean (center of the CI) -------------'        |
         upper bound of the CI ----------------------'

As described above, a change is considered significant if the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD).

For instance, for an execution time metric, this confidence interval indicates a significantly worse performance:

----------------------------------------|---------|---(---------^---------)---------->
                                       0%        1%  1.3%      2.2%      3.1%
                                                  |   |         |         |
       significant impact threshold --------------'   |         |         |
                      lower bound of CI --------------'         |         |
       sample mean (center of the CI) --------------------------'         |
                      upper bound of CI ----------------------------------'

scenario:iastaspectsospath-ospathbasename_aspect

  • 🟥 execution_time [+143.972µs; +149.840µs] or [+35.165%; +36.598%]

scenario:iastaspectssplit-rsplit_aspect

  • 🟥 execution_time [+16.243µs; +21.319µs] or [+11.142%; +14.624%]

@avara1986
avara1986 marked this pull request as ready for review August 24, 2026 09:37
@avara1986
avara1986 requested review from a team as code owners August 24, 2026 09:37
@avara1986
avara1986 requested a review from florentinl August 24, 2026 09:37

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bbe46c7f1f

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread ddtrace/appsec/_iast/taint_sinks/code_injection.py
wrapt's C extension adds no frame of its own, but the pure-Python
FunctionWrapper does, so _resolve_caller_frame had no coverage: CI always
runs with the C extension, where the walk returns on its first iteration.

Add a fixture that evals an expression referencing a caller-local, plus
unit tests for the walk and end-to-end tests that recreate the extra wrapt
frame via types.FunctionType. Recreating the frame instead of using
wrapt.wrappers.FunctionWrapper keeps this correct on wrapt 1.x, where
wrappers.py re-imports the C classes over its own names.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

@christophe-papazian christophe-papazian left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking review. I verified the core claims independently and they hold up: setup.py really does gate the IAST extensions on platform only (the three sys.version_info < (3, 15) gates cover profiling/crashtracker/memalloc), asm.py really was the only runtime gate, and the eval() bug reproduces exactly as described — with the wrapt C extension present wrapt.FunctionWrapper is the C class and adds no frame, with it disabled a wrapt.wrappers frame appears and eval("local_value + 1") raises NameError on every wrapt version I tried (1.17.2 → 2.3.0). So the heuristic targets the right frame and is a genuine no-op on the common path.

One finding worth acting on before merge (the _PURE_PYTHON_WRAPT_AVAILABLE line breaks collection of the whole file on most supported wrapt versions), plus four cheap cleanups inline.

Comment thread tests/appsec/iast/taint_sinks/test_code_injection_inspect_regression.py Outdated
Comment thread ddtrace/appsec/_iast/taint_sinks/code_injection.py Outdated
Comment thread ddtrace/appsec/_iast/taint_sinks/code_injection.py Outdated
Comment thread tests/appsec/iast/aspects/test_slice_aspect_fixtures.py Outdated
Comment thread ddtrace/internal/settings/asm.py Outdated
- Drop the module-level wrapt __module__ probe in the regression tests.
  ObjectProxy declares __module__ as a property, so on the class it is a
  property object, not a str, before wrapt 2.2 — the guard raised
  AttributeError at import time, a collection error for the whole file on
  the ~90 lockfiles pinning wrapt==1.17.x. It was also unnecessary:
  wrapt.wrappers.FunctionWrapper is the pure-Python class on every allowed
  version, so the test now always runs instead of being skipif-guarded.
- Rename _MAX_WRAPPER_FRAMES to _MAX_FRAMES_TO_INSPECT; range(8) inspects
  8 candidates, so at most 7 wrapt frames were ever skipped.
- Re-nest the func_globals assignment so a None caller frame still raises
  into the except and falls back to a native wrapped(*args, **kwargs) eval
  rather than evaluating against ddtrace's own globals with kwargs dropped.
- Assert the slice TypeError with one anchored regex instead of two
  disconnected substrings that accepted arbitrary text between them.
- Correct the AIDEV-NOTE: the bound intentionally leads requires-python.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@datadog-official

datadog-official Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 7509b17 | Docs | View more details | Give us feedback!

avara1986 and others added 2 commits August 24, 2026 16:44
The "left unguarded on purpose" comment justified the except fallback as
avoiding ddtrace's own globals, which is false: for a plain eval(code),
wrapped(*args, **kwargs) and wrapped(code, None, None) both resolve against
_iast_coi's module globals. The fallback's actual merit is re-dispatching
the caller's original arguments, so an explicitly-passed-but-falsy globals
or locals survives the truthiness checks above instead of becoming None.

Also give the slice TypeError assertion a message, so a mismatch prints the
actual text rather than a bare "assert None".

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@avara1986

Copy link
Copy Markdown
Member Author

/merge

@gh-worker-devflow-routing-ef8351

gh-worker-devflow-routing-ef8351 Bot commented Aug 25, 2026

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2026-08-25 06:43:31 UTC ℹ️ Start processing command /merge


2026-08-25 06:43:36 UTC ℹ️ MergeQueue: pull request added to the queue

The expected merge time in main is approximately 1h (p90).


2026-08-25 07:21:57 UTC ℹ️ MergeQueue: This merge request was merged

@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot merged commit 0d9449f into main Aug 25, 2026
652 checks passed
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot deleted the avara1986/iast-python-315-support branch August 25, 2026 07:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[3.15] IAST 3.15

2 participants