UNPKG

mcp-server-semgrep

Version:

MCP Server for Semgrep Integration - static code analysis with AI

62 lines (61 loc) 1.9 kB
rules: - id: pyramid-sqlalchemy-sql-injection message: >- Distinct, Having, Group_by, Order_by, and Filter in SQLAlchemy can cause sql injections if the developer inputs raw SQL into the before-mentioned clauses. This pattern captures relevant cases in which the developer inputs raw SQL into the distinct, having, group_by, order_by or filter clauses and injects user-input into the raw SQL with any function besides "bindparams". Use bindParams to securely bind user-input to SQL statements. languages: - python severity: ERROR metadata: category: security cwe: - "CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')" owasp: - A01:2017 - Injection - A03:2021 - Injection references: - https://docs.sqlalchemy.org/en/14/tutorial/data_select.html#tutorial-selecting-data technology: - pyramid cwe2022-top25: true cwe2021-top25: true subcategory: - vuln likelihood: MEDIUM impact: HIGH confidence: MEDIUM mode: taint pattern-sources: - patterns: - pattern-inside: | from pyramid.view import view_config ... @view_config( ... ) def $VIEW($REQ): ... - pattern: $REQ.$ANYTHING - pattern-not: $REQ.dbsession pattern-sinks: - patterns: - pattern-inside: | $QUERY = $REQ.dbsession.query(...) ... - pattern-either: - pattern: | $QUERY.$SQLFUNC("...".$FORMATFUNC(..., $SINK, ...)) - pattern: | $QUERY.join(...).$SQLFUNC("...".$FORMATFUNC(..., $SINK, ...)) - pattern: $SINK - metavariable-regex: metavariable: $SQLFUNC regex: (group_by|order_by|distinct|having|filter) - metavariable-regex: metavariable: $FORMATFUNC regex: (?!bindparams) fix-regex: regex: format replacement: bindparams