fix(appsec): normalize DBAPI queries for SQLi RASP - #19934
Draft
florentinl wants to merge 1 commit into
Draft
Conversation
Codeowners resolved asResolved from the full PR diff against |
Circular import analysis
|
Dependency direction analysis
|
Contributor
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR is stacked on #19918. Review the normalization commit
eedae00c1b; the parent commit contains the async-driver DBAPI event coverage from that PR.Normalize database queries once at the traced cursor boundary before using them as span resources or publishing the typed
dbapi.queryevent. This lets SQL injection detection and blocking inspect:strandbytesqueries;SQLandComposed;The original query object is still passed to the database adapter. Adapter-specific rendering uses the adapter's supported API and fails open: if rendering raises, tracing continues with the original resource and the driver call is unaffected. Event publication is skipped when there are no listeners.
Testing
scripts/lint checksscripts/lint typing -- ddtrace/contrib/_events/dbapi.py ddtrace/contrib/dbapi.py ddtrace/contrib/dbapi_async.py ddtrace/contrib/internal/aiomysql/patch.py ddtrace/contrib/internal/aiopg/connection.py ddtrace/contrib/internal/asyncpg/patch.py ddtrace/contrib/internal/psycopg/cursor.py ddtrace/contrib/internal/psycopg/patch.pyRisks
The main risk is adapter-specific rendering changing query handling. The rendered value is used only for the span resource and typed security event; the adapter always receives the original object. Rendering failures are logged at debug level and do not affect application execution.
Additional Notes
florentin.labelle/appsec/async-dbapi-sqli