Skip to content

db_hooks sensor has no receiver anchor: matches FastAPI Query(), declarations, and prose across a newline #3019

Closed

Description

@squid-protocol

Summary

security_lens.py's db_hooks sensor (THREAT_SIGNATURES #13) is

r"\b(?:execute|query|raw|cursor|execute_sql|executeBatch|query_db)\b\s*\(", re.I

Bare, extremely common English/API words with no receiver anchor, matched case-insensitively,
with \s* before the paren. It claims 240 hits across 76 files of the language-crucible
corpus; the large majority are not database sinks.

What it actually matches

count match what it really is
95 execute( mostly declarations -- fun execute(): Response (okhttp), function execute( (Solidity Governor), public static void execute(QueueableContext) (Apex), zig fn execute(
63 Query( FastAPI's query-parameter helper, and GraphQL Query( -- no database anywhere
46 query( generic; DOM/HTTP/GraphQL query builders
16 raw( raw() string/template helpers
2 CURSOR ( COBOL/SQL cursor declaration, not an execution
1 query\n( \s* spanned a newline -- the verb and the paren are on different lines

That last row is its own bug: \s* lets a sink straddle a line break, which is how a match
landed on the word "raw" inside an English prose comment in tests/extraction/languages/test_kotlin.py.

Because db_hooks also gates security_lens.py's taint tracker (has_global_db) and
galaxyscope.py's API-near-sink correlation, this noise propagates -- see the sibling issue
on threat_sql_injection (~0% inspected precision, driven by Query().

Proposed fix

Require the verb to be invoked on a receiver, which a declaration and a bare helper call
can never satisfy, and keep only unambiguous SQL-specific free functions bare:

r"(?:\.|->)[ \t]*(?:execute|executemany|executescript|executeBatch|executeQuery"
r"|executeUpdate|query|rawQuery|prepareStatement|createStatement)[ \t]*\("
r"|\b(?:execute_sql|query_db|mysqli_query|pg_query|pg_exec|sqlite3_exec|sqlite3_prepare)[ \t]*\("

-> matters: Perl DBI's $sth->execute() and $insert->execute($value, $sortorder) in
bugzilla are genuine sinks, and a \.-only anchor would silently lose every one of them.
[ \t]* replaces \s* so a sink can never span a newline (Engine Rule 14 style bounding).
cursor is dropped entirely -- conn.cursor() is cursor creation, not a query execution.

Measured effect on the corpus

current : 240 hits / 76 files
proposed: 146 hits / 28 files

Kept: .execute( 55, ->query( 29, ->rawQuery( 24, ->execute( 16, sqlite3_exec( 12.
Dropped: bare execute( 95, Query( 63, query( 46, raw( 16, CURSOR ( 2, the newline-spanner.

Golden masters will need a re-bless; sec_tainted_injection may also move where db_hooks
was the gate.

Activity

  1. added
    bug
    appsec
    on Sep 14, 2026
  2. added a commit that references this issue on Sep 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    appsecbug

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions