UNPKG

mcp-server-semgrep

Version:

MCP Server for Semgrep Integration - static code analysis with AI

96 lines (95 loc) 3.06 kB
rules: - id: asyncpg-sqli languages: - python message: >- Detected string concatenation with a non-literal variable in a asyncpg Python SQL statement. This could lead to SQL injection if the variable is user-controlled and not properly sanitized. In order to prevent SQL injection, use parameterized queries or prepared statements instead. You can create parameterized queries like so: 'conn.fetch("SELECT $1 FROM table", value)'. You can also create prepared statements with 'Connection.prepare': 'stmt = conn.prepare("SELECT $1 FROM table"); await stmt.fetch(user_value)' metadata: references: - https://github.com/MagicStack/asyncpg - https://magicstack.github.io/asyncpg/current/ category: security cwe: - "CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')" technology: - asyncpg owasp: - A01:2017 - Injection - A03:2021 - Injection cwe2022-top25: true cwe2021-top25: true subcategory: - audit likelihood: LOW impact: HIGH confidence: LOW patterns: - pattern-either: - patterns: - pattern: $CONN.$METHOD(...,$QUERY,...) - pattern-either: - pattern-inside: | $QUERY = $X + $Y ... - pattern-inside: | $QUERY += $X ... - pattern-inside: | $QUERY = '...'.format(...) ... - pattern-inside: | $QUERY = '...' % (...) ... - pattern-inside: | $QUERY = f'...{$USERINPUT}...' ... - pattern-not-inside: | $QUERY += "..." ... - pattern-not-inside: | $QUERY = "..." + "..." ... - pattern-not-inside: | $QUERY = '...'.format() ... - pattern-not-inside: | $QUERY = '...' % () ... - pattern: $CONN.$METHOD(..., $X + $Y, ...) - pattern: $CONN.$METHOD(..., $Y.format(...), ...) - pattern: $CONN.$METHOD(..., '...'.format(...), ...) - pattern: $CONN.$METHOD(..., '...' % (...), ...) - pattern: $CONN.$METHOD(..., f'...{$USERINPUT}...', ...) - pattern-either: - pattern-inside: | $CONN = await asyncpg.connect(...) ... - pattern-inside: | async with asyncpg.create_pool(...) as $CONN: ... - pattern-inside: | async with $POOL.acquire(...) as $CONN: ... - pattern-inside: | $CONN = await $POOL.acquire(...) ... - pattern-inside: | def $FUNCNAME(..., $CONN: Connection, ...): ... - pattern-inside: | def $FUNCNAME(..., $CONN: asyncpg.Connection, ...): ... - pattern-not: $CONN.$METHOD(..., "..." + "...", ...) - pattern-not: $CONN.$METHOD(..., '...'.format(), ...) - pattern-not: $CONN.$METHOD(..., '...'%(), ...) - metavariable-regex: metavariable: $METHOD regex: ^(fetch|fetchrow|fetchval|execute|executemany|prepare|cursor|copyfromquery)$ severity: WARNING