Skip to content

Commit 0ddeb7a

Browse files
authored
Merge pull request github#5950 from RasmusWL/promote-clickhouse
Python: Promote ClickHouse SQL models
2 parents eaa69df + 00af18a commit 0ddeb7a

File tree

19 files changed

+204
-241
lines changed

19 files changed

+204
-241
lines changed

docs/codeql/support/reusables/frameworks.rst

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
C and C++ built-in support
22
================================
33

4-
.. csv-table::
4+
.. csv-table::
55
:header-rows: 1
66
:class: fullWidthTable
77
:widths: auto
@@ -14,7 +14,7 @@ C and C++ built-in support
1414
C# built-in support
1515
================================
1616

17-
.. csv-table::
17+
.. csv-table::
1818
:header-rows: 1
1919
:class: fullWidthTable
2020
:widths: auto
@@ -84,7 +84,7 @@ Go built-in support
8484
Java built-in support
8585
==================================
8686

87-
.. csv-table::
87+
.. csv-table::
8888
:header-rows: 1
8989
:class: fullWidthTable
9090
:widths: auto
@@ -109,7 +109,7 @@ Java built-in support
109109
JavaScript and TypeScript built-in support
110110
=======================================================
111111

112-
.. csv-table::
112+
.. csv-table::
113113
:header-rows: 1
114114
:class: fullWidthTable
115115
:widths: auto
@@ -165,6 +165,8 @@ Python built-in support
165165
invoke, Utility library
166166
multidict, Utility library
167167
yarl, Utility library
168+
aioch, Database
169+
clickhouse-driver, Database
168170
mysql-connector-python, Database
169171
mysql-connector, Database
170172
MySQL-python, Database
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
lgtm,codescanning
2+
* Added model of SQL execution in `clickhouse-driver` and `aioch` PyPI packages, resulting in additional sinks for the SQL Injection query (`py/sql-injection`). This modeling was originally [submitted as a contribution by @japroc](https://github.com/github/codeql/pull/5889).

python/ql/src/experimental/Security/CWE-089/ClickHouseSQLInjection.py

Lines changed: 0 additions & 28 deletions
This file was deleted.

python/ql/src/experimental/Security/CWE-089/ClickHouseSQLInjection.qhelp

Lines changed: 0 additions & 59 deletions
This file was deleted.

python/ql/src/experimental/Security/CWE-089/ClickHouseSQLInjection.ql

Lines changed: 0 additions & 22 deletions
This file was deleted.

python/ql/src/experimental/semmle/python/frameworks/ClickHouseDriver.qll

Lines changed: 0 additions & 85 deletions
This file was deleted.

python/ql/src/semmle/python/Frameworks.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
// If you add modeling of a new framework/library, remember to add it it to the docs in
66
// `docs/codeql/support/reusables/frameworks.rst`
7+
private import semmle.python.frameworks.Aioch
78
private import semmle.python.frameworks.Aiohttp
9+
private import semmle.python.frameworks.ClickhouseDriver
810
private import semmle.python.frameworks.Cryptodome
911
private import semmle.python.frameworks.Cryptography
1012
private import semmle.python.frameworks.Dill
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/**
2+
* Provides classes modeling security-relevant aspects of the `aioch` PyPI package (an
3+
* async-io version of the `clickhouse-driver` PyPI package).
4+
*
5+
* See https://pypi.org/project/aioch/
6+
*/
7+
8+
private import python
9+
private import semmle.python.Concepts
10+
private import semmle.python.ApiGraphs
11+
private import semmle.python.frameworks.PEP249
12+
private import semmle.python.frameworks.ClickhouseDriver
13+
14+
/**
15+
* INTERNAL: Do not use.
16+
*
17+
* Provides models for `aioch` PyPI package (an async-io version of the
18+
* `clickhouse-driver` PyPI package).
19+
*
20+
* See https://pypi.org/project/aioch/
21+
*/
22+
module Aioch {
23+
/** Provides models for `aioch.Client` class and subclasses. */
24+
module Client {
25+
/** Gets a reference to the `aioch.Client` class or any subclass. */
26+
API::Node subclassRef() {
27+
result = API::moduleImport("aioch").getMember("Client").getASubclass*()
28+
}
29+
30+
/** Gets a reference to an instance of `clickhouse_driver.Client` or any subclass. */
31+
API::Node instance() { result = subclassRef().getReturn() }
32+
}
33+
34+
/**
35+
* A call to any of the the execute methods on a `aioch.Client`, which are just async
36+
* versions of the methods in the `clickhouse-driver` PyPI package.
37+
*
38+
* See
39+
* - https://clickhouse-driver.readthedocs.io/en/latest/api.html#clickhouse_driver.Client.execute
40+
* - https://clickhouse-driver.readthedocs.io/en/latest/api.html#clickhouse_driver.Client.execute_iter
41+
* - https://clickhouse-driver.readthedocs.io/en/latest/api.html#clickhouse_driver.Client.execute_with_progress
42+
*/
43+
class ClientExecuteCall extends SqlExecution::Range, DataFlow::CallCfgNode {
44+
ClientExecuteCall() {
45+
exists(string methodName | methodName = ClickhouseDriver::getExecuteMethodName() |
46+
this = Client::instance().getMember(methodName).getACall()
47+
)
48+
}
49+
50+
override DataFlow::Node getSql() { result in [this.getArg(0), this.getArgByName("query")] }
51+
}
52+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/**
2+
* Provides classes modeling security-relevant aspects of the `clickhouse-driver` PyPI package.
3+
* See
4+
* - https://pypi.org/project/clickhouse-driver/
5+
* - https://clickhouse-driver.readthedocs.io/en/latest/
6+
*/
7+
8+
private import python
9+
private import semmle.python.Concepts
10+
private import semmle.python.ApiGraphs
11+
private import semmle.python.frameworks.PEP249
12+
13+
/**
14+
* INTERNAL: Do not use.
15+
*
16+
* Provides models for `clickhouse-driver` PyPI package (imported as `clickhouse_driver`).
17+
* See
18+
* - https://pypi.org/project/clickhouse-driver/
19+
* - https://clickhouse-driver.readthedocs.io/en/latest/
20+
*/
21+
module ClickhouseDriver {
22+
/**
23+
* `clickhouse_driver` implements PEP249,
24+
* providing ways to execute SQL statements against a database.
25+
*/
26+
class ClickHouseDriverPEP249 extends PEP249ModuleApiNode {
27+
ClickHouseDriverPEP249() { this = API::moduleImport("clickhouse_driver") }
28+
}
29+
30+
/** Provides models for `clickhouse_driver.Client` class and subclasses. */
31+
module Client {
32+
/** Gets a reference to the `clickhouse_driver.Client` class or any subclass. */
33+
API::Node subclassRef() {
34+
exists(API::Node classRef |
35+
// canonical definition
36+
classRef = API::moduleImport("clickhouse_driver").getMember("client").getMember("Client")
37+
or
38+
// commonly used alias
39+
classRef = API::moduleImport("clickhouse_driver").getMember("Client")
40+
|
41+
result = classRef.getASubclass*()
42+
)
43+
}
44+
45+
/** Gets a reference to an instance of `clickhouse_driver.Client` or any subclass. */
46+
API::Node instance() { result = subclassRef().getReturn() }
47+
}
48+
49+
/** `clickhouse_driver.Client` execute method names */
50+
string getExecuteMethodName() { result in ["execute_with_progress", "execute", "execute_iter"] }
51+
52+
/**
53+
* A call to any of the the execute methods on a `clickhouse_driver.Client` method
54+
*
55+
* See
56+
* - https://clickhouse-driver.readthedocs.io/en/latest/api.html#clickhouse_driver.Client.execute
57+
* - https://clickhouse-driver.readthedocs.io/en/latest/api.html#clickhouse_driver.Client.execute_iter
58+
* - https://clickhouse-driver.readthedocs.io/en/latest/api.html#clickhouse_driver.Client.execute_with_progress
59+
*/
60+
class ClientExecuteCall extends SqlExecution::Range, DataFlow::CallCfgNode {
61+
ClientExecuteCall() { this = Client::instance().getMember(getExecuteMethodName()).getACall() }
62+
63+
override DataFlow::Node getSql() { result in [this.getArg(0), this.getArgByName("query")] }
64+
}
65+
}

python/ql/test/experimental/semmle/python/frameworks/clickhouse-driver/ClickHouseDriver.expected

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)