|
| 1 | +/** |
| 2 | + * Provides classes modeling security-relevant aspects of `clickhouse-driver` and `aioch` PyPI packages. |
| 3 | + * See |
| 4 | + * - https://pypi.org/project/clickhouse-driver/ |
| 5 | + * - https://pypi.org/project/aioch/ |
| 6 | + * - https://clickhouse-driver.readthedocs.io/en/latest/ |
| 7 | + */ |
| 8 | + |
| 9 | +private import python |
| 10 | +private import semmle.python.Concepts |
| 11 | +private import semmle.python.ApiGraphs |
| 12 | +private import semmle.python.frameworks.PEP249 |
| 13 | + |
| 14 | +/** |
| 15 | + * Provides models for `clickhouse-driver` and `aioch` PyPI packages. |
| 16 | + * See |
| 17 | + * - https://pypi.org/project/clickhouse-driver/ |
| 18 | + * - https://pypi.org/project/aioch/ |
| 19 | + * - https://clickhouse-driver.readthedocs.io/en/latest/ |
| 20 | + */ |
| 21 | +module ClickHouseDriver { |
| 22 | + /** Gets a reference to the `clickhouse_driver` module. */ |
| 23 | + API::Node clickhouse_driver() { result = API::moduleImport("clickhouse_driver") } |
| 24 | + |
| 25 | + /** Gets a reference to the `aioch` module. This module allows to make async db queries. */ |
| 26 | + API::Node aioch() { result = API::moduleImport("aioch") } |
| 27 | + |
| 28 | + /** |
| 29 | + * `clickhouse_driver` implements PEP249, |
| 30 | + * providing ways to execute SQL statements against a database. |
| 31 | + */ |
| 32 | + class ClickHouseDriverPEP249 extends PEP249ModuleApiNode { |
| 33 | + ClickHouseDriverPEP249() { this = clickhouse_driver() } |
| 34 | + } |
| 35 | + |
| 36 | + module Client { |
| 37 | + /** Gets a reference to a Client call. */ |
| 38 | + private DataFlow::Node client_ref() { |
| 39 | + result = clickhouse_driver().getMember("Client").getAUse() |
| 40 | + or |
| 41 | + result = aioch().getMember("Client").getAUse() |
| 42 | + } |
| 43 | + |
| 44 | + /** A direct instantiation of `clickhouse_driver.Client`. */ |
| 45 | + private class ClientInstantiation extends DataFlow::CallCfgNode { |
| 46 | + ClientInstantiation() { this.getFunction() = client_ref() } |
| 47 | + } |
| 48 | + |
| 49 | + /** Gets a reference to an instance of `clickhouse_driver.Client`. */ |
| 50 | + private DataFlow::LocalSourceNode instance(DataFlow::TypeTracker t) { |
| 51 | + t.start() and |
| 52 | + result instanceof ClientInstantiation |
| 53 | + or |
| 54 | + exists(DataFlow::TypeTracker t2 | result = instance(t2).track(t2, t)) |
| 55 | + } |
| 56 | + |
| 57 | + /** Gets a reference to an instance of `clickhouse_driver.Client`. */ |
| 58 | + DataFlow::Node instance() { instance(DataFlow::TypeTracker::end()).flowsTo(result) } |
| 59 | + } |
| 60 | + |
| 61 | + /** clickhouse_driver.Client execute methods */ |
| 62 | + private string execute_function() { |
| 63 | + result in ["execute_with_progress", "execute", "execute_iter"] |
| 64 | + } |
| 65 | + |
| 66 | + /** Gets a reference to the `clickhouse_driver.Client.execute` method */ |
| 67 | + private DataFlow::LocalSourceNode clickhouse_execute(DataFlow::TypeTracker t) { |
| 68 | + t.startInAttr(execute_function()) and |
| 69 | + result = Client::instance() |
| 70 | + or |
| 71 | + exists(DataFlow::TypeTracker t2 | result = clickhouse_execute(t2).track(t2, t)) |
| 72 | + } |
| 73 | + |
| 74 | + /** Gets a reference to the `clickhouse_driver.Client.execute` method */ |
| 75 | + DataFlow::Node clickhouse_execute() { |
| 76 | + clickhouse_execute(DataFlow::TypeTracker::end()).flowsTo(result) |
| 77 | + } |
| 78 | + |
| 79 | + /** A call to the `clickhouse_driver.Client.execute` method */ |
| 80 | + private class ExecuteCall extends SqlExecution::Range, DataFlow::CallCfgNode { |
| 81 | + ExecuteCall() { this.getFunction() = clickhouse_execute() } |
| 82 | + |
| 83 | + override DataFlow::Node getSql() { result.asCfgNode() = node.getArg(0) } |
| 84 | + } |
| 85 | +} |
0 commit comments