Skip to content

refactor(appsec): move appsec DBAPI SQLi handling to typed events - #19747

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 7 commits into
mainfrom
florentin.labelle/refactor/dbapi-appsec-contrib
Aug 20, 2026
Merged

refactor(appsec): move appsec DBAPI SQLi handling to typed events#19747
gh-worker-dd-mergequeue-cf854d[bot] merged 7 commits into
mainfrom
florentin.labelle/refactor/dbapi-appsec-contrib

Conversation

@florentinl

@florentinl florentinl commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Description

Move synchronous DBAPI SQL injection RASP handling from the legacy tuple-based common-module hook to the typed contrib event/subscriber API.

  • Emit a typed DbApiEvent from the generic DBAPI cursor only when AppSec has a listener.
  • Move WAF invocation and blocking ownership into an AppSec DBAPI subscriber.
  • Normalize integration span-name prefixes and WAF SQL dialects with typed enums, using the generic dialect for unsupported prefixes.
  • Preserve the existing scope: only synchronous string queries are dispatched. Bytes, adapter-specific query objects, and async adapters remain for follow-up PRs.

Testing

Risks

Low. This changes the internal event boundary and listener ownership without expanding supported query types or adapters. Tests cover listener gating, blocking propagation, disabled tracing, prefix/dialect normalization, and the existing common-module lifecycle.

Additional Notes

No release note: this is an internal behavior-preserving refactor.

@cit-pr-commenter-54b7da

cit-pr-commenter-54b7da Bot commented Aug 18, 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.

@florentinl florentinl added the changelog/no-changelog A changelog entry is not required for this PR. label Aug 18, 2026 — with ChatGPT Codex Connector
@datadog-datadog-prod-us1

datadog-datadog-prod-us1 Bot commented Aug 18, 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: 00ce070 | Docs | View more details | Give us feedback!

@cit-pr-commenter-54b7da

cit-pr-commenter-54b7da Bot commented Aug 18, 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 18, 2026

Copy link
Copy Markdown

Dependency direction analysis

⚠️ Existing dependency direction violations

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

Show existing violations (showing 5 of 252 highest severity)
ddtrace.internal.tracemethods -×-> ddtrace.trace  (internal-core -> product:tracing, score=135)
ddtrace.appsec._contrib.flask -×-> ddtrace.trace  (product:appsec -> product:tracing, score=133)
ddtrace.llmobs._integrations.mcp -×-> ddtrace.trace  (product:llmobs -> product:tracing, score=133)
ddtrace.internal.ci_visibility.api._base -×-> ddtrace.trace  (product:ci_visibility -> product:tracing, score=133)
ddtrace.llmobs._integrations.pydantic_ai -×-> ddtrace.trace  (product:llmobs -> 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 18, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-08-20 09:47:10

Comparing candidate commit 00ce070 in PR branch florentin.labelle/refactor/dbapi-appsec-contrib with baseline commit e155a58 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 [+109.779µs; +119.310µs] or [+26.338%; +28.625%]

scenario:iastaspectssplit-rsplit_aspect

  • 🟥 execution_time [+17.761µs; +22.580µs] or [+12.262%; +15.589%]

@florentinl
florentinl marked this pull request as ready for review August 18, 2026 14:37
@florentinl
florentinl requested review from a team as code owners August 18, 2026 14: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: 78d84067b1

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread ddtrace/appsec/_contrib/dbapi/subscribers.py
@florentinl
florentinl marked this pull request as draft August 18, 2026 14:50
@florentinl
florentinl marked this pull request as ready for review August 18, 2026 15:40
@florentinl
florentinl requested review from christophe-papazian and removed request for avara1986 August 19, 2026 07:48
@florentinl florentinl changed the title refactor(appsec): move DBAPI SQLi handling to typed events refactor(appsec): move appsec DBAPI SQLi handling to typed events Aug 19, 2026

@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.

Reviewed the refactor closely and I'm satisfied it's behavior-preserving: the dropped in_asm_context() guard and report_rasp_skipped(SQLI, False) were unreachable in main (get_rasp_capability() already checks the context), blocking still propagates because BlockingException derives from BaseException and native should_propagate() re-raises those regardless of allow_raise=False, and the dialect table change is a no-op — I checked libddwaf at the pinned 2.0.1: sql_dialect_from_type() maps everything outside mysql/postgresql/sqlite/oracle/doctrine/hsqldb to generic, and sqli_detector.cpp only has distinct tokenizers for pgsql/mysql/sqlite, so mariadb, odbc, vertica and sql were already generic. Async scope and the bytes exclusion are preserved too.

Three comments inline: one hot-path gating regression, one small detection improvement, one test gap.

Comment thread ddtrace/appsec/_listeners.py Outdated
Comment thread ddtrace/appsec/_contrib/dbapi/subscribers.py
Comment thread tests/contrib/dbapi/test_dbapi.py

@emmettbutler emmettbutler left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

great code organization improvement

Comment thread ddtrace/contrib/_events/dbapi.py
Comment thread ddtrace/contrib/dbapi.py Outdated
Comment thread tests/appsec/appsec/test_exploit_prevention.py Outdated
@florentinl
florentinl force-pushed the florentin.labelle/refactor/dbapi-appsec-contrib branch from 6c0aeca to 00ce070 Compare August 20, 2026 09:30
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot merged commit 208239c into main Aug 20, 2026
1166 checks passed
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot deleted the florentin.labelle/refactor/dbapi-appsec-contrib branch August 20, 2026 10:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog/no-changelog A changelog entry is not required for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants