|
| 1 | +rules: |
| 2 | + # ── SQL Injection ────────────────────────────────────────────────── |
| 3 | + - id: sec.injection.sql |
| 4 | + description: > |
| 5 | + User-controlled input concatenated or interpolated into a SQL query string |
| 6 | + instead of using parameterized queries / prepared statements. |
| 7 | + Sinks: cursor.execute(f"..."), db.Query(fmt.Sprintf(...)), connection.query(str), |
| 8 | + ActiveRecord.where("... #{...}"), sqlx::query(format!(...)), SqlCommand(str). |
| 9 | + Sanitizers: parameterized queries (?/$1 placeholders), ORM filters, sqlx::query! macro. |
| 10 | + scope: "**/*.{py,js,ts,rb,go,rs,java,kt,cs,php,scala}" |
| 11 | + severity: error |
| 12 | + category: security |
| 13 | + tags: [injection, sql-injection, owasp-a03, cwe-89] |
| 14 | + source: diffscope-builtin |
| 15 | + |
| 16 | + - id: sec.injection.sql.nosql |
| 17 | + description: > |
| 18 | + NoSQL injection via unsanitized input in MongoDB/DynamoDB/Elasticsearch queries. |
| 19 | + Check for $where, $regex, $gt/$lt operators built from user input, |
| 20 | + or JSON query objects constructed from request parameters. |
| 21 | + scope: "**/*.{py,js,ts,rb,go,java}" |
| 22 | + severity: error |
| 23 | + category: security |
| 24 | + tags: [injection, nosql-injection, owasp-a03, cwe-943] |
| 25 | + source: diffscope-builtin |
| 26 | + |
| 27 | + # ── Command Injection ────────────────────────────────────────────── |
| 28 | + - id: sec.injection.command |
| 29 | + description: > |
| 30 | + User-controlled input passed to OS command execution functions. |
| 31 | + Sinks: os.system(), subprocess.Popen(shell=True), exec.Command("sh","-c",str), |
| 32 | + child_process.exec(str), Runtime.exec(str), system(str), Process.spawn(str). |
| 33 | + Sanitizers: argument arrays (not shell strings), shlex.quote(), allowlist validation. |
| 34 | + Flag shell=True with non-literal command strings. |
| 35 | + scope: "**/*.{py,js,ts,rb,go,rs,java,kt,cs,php,bash,sh}" |
| 36 | + severity: error |
| 37 | + category: security |
| 38 | + tags: [injection, command-injection, owasp-a03, cwe-78] |
| 39 | + source: diffscope-builtin |
| 40 | + |
| 41 | + # ── XSS (Cross-Site Scripting) ───────────────────────────────────── |
| 42 | + - id: sec.injection.xss |
| 43 | + description: > |
| 44 | + User-controlled content rendered as HTML without output encoding. |
| 45 | + Sinks: innerHTML, outerHTML, document.write(), dangerouslySetInnerHTML, |
| 46 | + raw(), .html_safe, mark_safe(), Markup(), bypassSecurityTrust*(). |
| 47 | + Safe alternatives: textContent, createElement, framework auto-escaping. |
| 48 | + Check template files for unescaped output: {{! }}, |safe, -%>, <%==. |
| 49 | + scope: "**/*.{js,jsx,ts,tsx,html,erb,ejs,hbs,vue,svelte,py,rb,php,java}" |
| 50 | + severity: error |
| 51 | + category: security |
| 52 | + tags: [injection, xss, owasp-a03, cwe-79] |
| 53 | + source: diffscope-builtin |
| 54 | +
|
| 55 | + # ── Template Injection (SSTI) ────────────────────────────────────── |
| 56 | + - id: sec.injection.template |
| 57 | + description: > |
| 58 | + Server-side template injection via user input in template strings. |
| 59 | + Sinks: Jinja2 Template(user_input), Flask render_template_string(user_input), |
| 60 | + Mako Template(user_input), ERB.new(user_input), Razor @Html.Raw(user_input). |
| 61 | + Check for user input flowing into template compilation (not just rendering). |
| 62 | + scope: "**/*.{py,rb,js,ts,java,cs,go}" |
| 63 | + severity: error |
| 64 | + category: security |
| 65 | + tags: [injection, ssti, template-injection, owasp-a03, cwe-1336] |
| 66 | + source: diffscope-builtin |
| 67 | +
|
| 68 | + # ── LDAP Injection ───────────────────────────────────────────────── |
| 69 | + - id: sec.injection.ldap |
| 70 | + description: > |
| 71 | + User input interpolated into LDAP search filters without escaping. |
| 72 | + Sinks: DirContext.search(), InitialDirContext.search(), LdapContext methods. |
| 73 | + Sanitizers: LDAP filter encoding, allowlist validation of search terms. |
| 74 | + scope: "**/*.{java,kt,cs,py,php}" |
| 75 | + severity: error |
| 76 | + category: security |
| 77 | + tags: [injection, ldap-injection, owasp-a03, cwe-90] |
| 78 | + source: diffscope-builtin |
| 79 | +
|
| 80 | + # ── Log Injection ────────────────────────────────────────────────── |
| 81 | + - id: sec.injection.log |
| 82 | + description: > |
| 83 | + User-controlled data written to logs without sanitization, enabling |
| 84 | + log forging or ANSI escape sequence injection. |
| 85 | + Check for request parameters, headers, or user input in log statements |
| 86 | + without newline/control character stripping. |
| 87 | + scope: "**/*.{py,js,ts,rb,go,rs,java,kt,cs}" |
| 88 | + severity: warning |
| 89 | + category: security |
| 90 | + tags: [injection, log-injection, owasp-a09, cwe-117] |
| 91 | + source: diffscope-builtin |
| 92 | +
|
| 93 | + # ── Path Traversal ───────────────────────────────────────────────── |
| 94 | + - id: sec.injection.path-traversal |
| 95 | + description: > |
| 96 | + User input used to construct file paths without validation, allowing |
| 97 | + directory traversal via ../ sequences or absolute paths. |
| 98 | + Sinks: open(user_path), fs.readFile(user_path), File.new(user_path), |
| 99 | + std::fs::read(user_path), os.Open(user_path). |
| 100 | + Sanitizers: path canonicalization + prefix check, basename extraction. |
| 101 | + scope: "**/*.{py,js,ts,rb,go,rs,java,kt,cs,php}" |
| 102 | + severity: error |
| 103 | + category: security |
| 104 | + tags: [injection, path-traversal, owasp-a01, cwe-22] |
| 105 | + source: diffscope-builtin |
| 106 | +
|
| 107 | + # ── Code Injection ───────────────────────────────────────────────── |
| 108 | + - id: sec.injection.code |
| 109 | + description: > |
| 110 | + User input passed to code evaluation functions. |
| 111 | + Sinks: eval(), exec(), Function(str), setTimeout(str), setInterval(str), |
| 112 | + compile(), __import__(), importlib with user strings. |
| 113 | + Almost never safe with user input — flag unconditionally. |
| 114 | + scope: "**/*.{py,js,ts,rb,php}" |
| 115 | + severity: error |
| 116 | + category: security |
| 117 | + tags: [injection, code-injection, owasp-a03, cwe-94] |
| 118 | + source: diffscope-builtin |
0 commit comments