UNPKG

mcp-server-semgrep

Version:

MCP Server for Semgrep Integration - static code analysis with AI

64 lines (63 loc) 1.72 kB
rules: - id: ruby-pg-sqli mode: taint pattern-propagators: - pattern: $X << $Y from: $Y to: $X pattern-sources: - pattern-either: - pattern: | params - pattern: | cookies pattern-sinks: - patterns: - pattern-either: - pattern-inside: | $CON = PG.connect(...) ... - pattern-inside: | $CON = PG::Connection.open(...) ... - pattern-inside: | $CON = PG::Connection.new(...) ... - pattern-either: - pattern: | $CON.$METHOD($X,...) - pattern: | $CON.$METHOD $X, ... - focus-metavariable: $X - metavariable-regex: metavariable: $METHOD regex: ^(exec|exec_params)$ languages: - ruby message: >- Detected string concatenation with a non-literal variable in a pg Ruby 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 use parameterized queries like so: `conn.exec_params('SELECT $1 AS a, $2 AS b, $3 AS c', [1, 2, nil])` And you can use prepared statements with `exec_prepared`. metadata: cwe: - "CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')" owasp: - A01:2017 - Injection - A03:2021 - Injection references: - https://www.rubydoc.info/gems/pg/PG/Connection category: security technology: - rails cwe2022-top25: true cwe2021-top25: true subcategory: - vuln likelihood: HIGH impact: MEDIUM confidence: MEDIUM severity: WARNING