Skip to content

Commit 470e3eb

Browse files
committed
[python] ClickHouseDriver.qll: add support for subclasses
1 parent 2efa0ad commit 470e3eb

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
from clickhouse_driver import connect
44
from aioch import Client as aiochClient
55

6+
class MyClient(Client):
7+
def dummy(self):
8+
return None
9+
610
def show_user(request, username):
711

812
# BAD -- async library 'aioch'
@@ -25,4 +29,7 @@ def show_user(request, username):
2529
cursor = conn.cursor()
2630
cursor.execute("SELECT * FROM users WHERE username = '%s'" % username)
2731

32+
# BAD -- MyClient is a subclass of Client
33+
MyClient('localhost').execute("SELECT * FROM users WHERE username = '%s'" % username)
34+
2835
urlpatterns = [url(r'^users/(?P<username>[^/]+)$', show_user)]

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ second dict-like argument.
4747
In the fifth case, there is example of PEP249 interface usage.
4848
</p>
4949

50+
<p>
51+
In the sixth case, there is custom Class usge which is a subclass of default Client.
52+
</p>
53+
5054
<sample src="ClickHouseSQLInjection.py" />
5155
</example>
5256

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ module ClickHouseDriver {
3636
module Client {
3737
/** Gets a reference to a Client call. */
3838
private DataFlow::Node client_ref() {
39-
result = clickhouse_driver().getMember("Client").getAUse()
39+
result = clickhouse_driver().getMember("Client").getASubclass*().getAUse()
4040
or
41-
result = aioch().getMember("Client").getAUse()
41+
result = aioch().getMember("Client").getASubclass*().getAUse()
4242
}
4343

4444
/** A direct instantiation of `clickhouse_driver.Client`. */

0 commit comments

Comments
 (0)