|
| 1 | +/** |
| 2 | + * Provides modeling for mysql2, a Ruby library (gem) for interacting with MySql databases. |
| 3 | + */ |
| 4 | + |
| 5 | +private import codeql.ruby.ApiGraphs |
| 6 | +private import codeql.ruby.dataflow.FlowSummary |
| 7 | +private import codeql.ruby.Concepts |
| 8 | + |
| 9 | +/** |
| 10 | + * Provides modeling for mysql2, a Ruby library (gem) for interacting with MySql databases. |
| 11 | + */ |
| 12 | +module Mysql2 { |
| 13 | + /** |
| 14 | + * Flow summary for `Mysql2::Client.new()`. |
| 15 | + */ |
| 16 | + private class SqlSummary extends SummarizedCallable { |
| 17 | + SqlSummary() { this = "Mysql2::Client.new()" } |
| 18 | + |
| 19 | + override MethodCall getACall() { result = any(Mysql2Connection c).asExpr().getExpr() } |
| 20 | + |
| 21 | + override predicate propagatesFlowExt(string input, string output, boolean preservesValue) { |
| 22 | + input = "Argument[0]" and output = "ReturnValue" and preservesValue = false |
| 23 | + } |
| 24 | + } |
| 25 | + |
| 26 | + /** A call to Mysql2::Client.new() is used to establish a connection to a MySql database. */ |
| 27 | + private class Mysql2Connection extends DataFlow::CallNode { |
| 28 | + Mysql2Connection() { |
| 29 | + this = API::getTopLevelMember("Mysql2").getMember("Client").getAnInstantiation() |
| 30 | + } |
| 31 | + } |
| 32 | + |
| 33 | + /** A call that executes SQL statements against a MySQL database. */ |
| 34 | + private class Mysql2Execution extends SqlExecution::Range, DataFlow::CallNode { |
| 35 | + private DataFlow::Node query; |
| 36 | + |
| 37 | + Mysql2Execution() { |
| 38 | + exists(Mysql2Connection mysql2Connection | |
| 39 | + this = mysql2Connection.getAMethodCall("query") and query = this.getArgument(0) |
| 40 | + or |
| 41 | + exists(DataFlow::CallNode prepareCall | |
| 42 | + prepareCall = mysql2Connection.getAMethodCall("prepare") and |
| 43 | + query = prepareCall.getArgument(0) and |
| 44 | + this = prepareCall.getAMethodCall("execute") |
| 45 | + ) |
| 46 | + ) |
| 47 | + } |
| 48 | + |
| 49 | + override DataFlow::Node getSql() { result = query } |
| 50 | + } |
| 51 | + |
| 52 | + /** |
| 53 | + * A call to `Mysql2::Client.escape`, considered as a sanitizer for SQL statements. |
| 54 | + */ |
| 55 | + private class Mysql2EscapeSanitization extends SqlSanitization::Range { |
| 56 | + Mysql2EscapeSanitization() { |
| 57 | + this = API::getTopLevelMember("Mysql2").getMember("Client").getAMethodCall("escape") |
| 58 | + } |
| 59 | + } |
| 60 | + |
| 61 | + /** |
| 62 | + * Flow summary for `Mysql2::Client.escape()`. |
| 63 | + */ |
| 64 | + private class EscapeSummary extends SummarizedCallable { |
| 65 | + EscapeSummary() { this = "Mysql2::Client.escape()" } |
| 66 | + |
| 67 | + override MethodCall getACall() { result = any(Mysql2EscapeSanitization c).asExpr().getExpr() } |
| 68 | + |
| 69 | + override predicate propagatesFlowExt(string input, string output, boolean preservesValue) { |
| 70 | + input = "Argument[0]" and output = "ReturnValue" and preservesValue = false |
| 71 | + } |
| 72 | + } |
| 73 | +} |
0 commit comments