fix: resolve false negative in asyncpg-sqli rule by migrating to taint mode - #4014
Open
anannayamustcode wants to merge 1 commit into
Open
Conversation
…t mode Fixes semgrep#3027 The asyncpg-sqli rule failed to detect SQL injection when a tainted query was assigned to an intermediate variable (e.g. sql_query_copy = sql_query). This migrates the rule from AST pattern matching to mode: taint, which enables Semgrep's built-in data-flow tracking to follow taint through variable assignments. All existing test cases pass unchanged. Added a new test case (bad12) reproducing the exact scenario from semgrep#3027.
|
anannayamustcode seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
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.
Summary
Fixes #3027 - the
asyncpg-sqlirule missed SQL injection when the tainted query was reassigned to another variable before reaching the sink.Root Cause
The rule used AST
pattern-insidematching, which requires the exact tainted variable name to appear in the sink call. When an intermediate assignment likesql_query_copy = sql_querywas introduced, the rule lost track.Fix
Migrated the rule to
mode: taint, which enables Semgrep's built-in data-flow analysis to automatically track taint through variable assignments.+),+=,.format(),%formatting, f-stringsfetch,execute,cursor, etc.) on connection objects.format(), empty%)Changes
python/lang/security/audit/sqli/asyncpg-sqli.yaml- migrated to taint modepython/lang/security/audit/sqli/asyncpg-sqli.py- addedbad12test case from A false negative (miss) in asyncpg-sqli ruleset #3027Testing
All existing tests pass (
semgrep --test). The newbad12case is now correctly detected.