Skip to content

fix: resolve false negative in asyncpg-sqli rule by migrating to taint mode - #4014

Open
anannayamustcode wants to merge 1 commit into
semgrep:developfrom
anannayamustcode:fix/asyncpg-sqli-false-negative-3027
Open

fix: resolve false negative in asyncpg-sqli rule by migrating to taint mode#4014
anannayamustcode wants to merge 1 commit into
semgrep:developfrom
anannayamustcode:fix/asyncpg-sqli-false-negative-3027

Conversation

@anannayamustcode

@anannayamustcode anannayamustcode commented Jul 23, 2026

Copy link
Copy Markdown

Summary

Fixes #3027 - the asyncpg-sqli rule missed SQL injection when the tainted query was reassigned to another variable before reaching the sink.

Root Cause

The rule used AST pattern-inside matching, which requires the exact tainted variable name to appear in the sink call. When an intermediate assignment like sql_query_copy = sql_query was 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.

  • Sources: String concatenation (+), +=, .format(), % formatting, f-strings
  • Sinks: asyncpg methods (fetch, execute, cursor, etc.) on connection objects
  • All false-positive exclusions preserved (literal-only concatenation, empty .format(), empty %)

Changes

Testing

All existing tests pass (semgrep --test). The new bad12 case is now correctly detected.

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

CLAassistant commented Jul 23, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


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.

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.

A false negative (miss) in asyncpg-sqli ruleset

2 participants