Skip to content

Commit 6a81987

Browse files
committed
Python: Rename and add docs
1 parent 6d850b2 commit 6a81987

File tree

4 files changed

+110
-80
lines changed

4 files changed

+110
-80
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ private import experimental.semmle.python.frameworks.Fabric
88
private import experimental.semmle.python.frameworks.Flask
99
private import experimental.semmle.python.frameworks.Invoke
1010
private import experimental.semmle.python.frameworks.MySQLdb
11-
private import experimental.semmle.python.frameworks.Mysql
11+
private import experimental.semmle.python.frameworks.MysqlConnectorPython
1212
private import experimental.semmle.python.frameworks.Stdlib
1313
private import experimental.semmle.python.frameworks.Yaml
Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,38 @@
1+
/**
2+
* Provides classes modeling security-relevant aspects of the `MySQLdb` PyPI package.
3+
* See
4+
* - https://mysqlclient.readthedocs.io/index.html
5+
* - https://pypi.org/project/MySQL-python/
6+
*/
7+
18
private import python
29
private import experimental.dataflow.DataFlow
310
private import experimental.dataflow.RemoteFlowSources
411
private import experimental.semmle.python.Concepts
512
private import PEP249
613

7-
// ---------------------------------------------------------------------------
8-
// MySQLdb
9-
// ---------------------------------------------------------------------------
10-
/** Gets a reference to the `MySQLdb` module. */
11-
private DataFlow::Node moduleMySQLdb(DataFlow::TypeTracker t) {
12-
t.start() and
13-
result = DataFlow::importNode("MySQLdb")
14-
or
15-
exists(DataFlow::TypeTracker t2 | result = moduleMySQLdb(t2).track(t2, t))
16-
}
14+
/**
15+
* Provides models for the `MySQLdb` PyPI package.
16+
* See
17+
* - https://mysqlclient.readthedocs.io/index.html
18+
* - https://pypi.org/project/MySQL-python/
19+
*/
20+
module MySQLdb {
21+
// ---------------------------------------------------------------------------
22+
// MySQLdb
23+
// ---------------------------------------------------------------------------
24+
/** Gets a reference to the `MySQLdb` module. */
25+
private DataFlow::Node moduleMySQLdb(DataFlow::TypeTracker t) {
26+
t.start() and
27+
result = DataFlow::importNode("MySQLdb")
28+
or
29+
exists(DataFlow::TypeTracker t2 | result = moduleMySQLdb(t2).track(t2, t))
30+
}
1731

18-
/** Gets a reference to the `MySQLdb` module. */
19-
DataFlow::Node moduleMySQLdb() { result = moduleMySQLdb(DataFlow::TypeTracker::end()) }
32+
/** Gets a reference to the `MySQLdb` module. */
33+
DataFlow::Node moduleMySQLdb() { result = moduleMySQLdb(DataFlow::TypeTracker::end()) }
2034

21-
class MySQLdb extends PEP249Module {
22-
MySQLdb() { this = moduleMySQLdb() }
35+
class MySQLdb extends PEP249Module {
36+
MySQLdb() { this = moduleMySQLdb() }
37+
}
2338
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/**
2+
* Provides classes modeling security-relevant aspects of the `mysql-connector-python` package.
3+
* See https://dev.mysql.com/doc/dev/connector-python/.
4+
*/
5+
6+
private import python
7+
private import experimental.dataflow.DataFlow
8+
private import experimental.dataflow.RemoteFlowSources
9+
private import experimental.semmle.python.Concepts
10+
private import PEP249
11+
12+
/**
13+
* Provides models for the `mysql-connector-python` package.
14+
* See https://dev.mysql.com/doc/dev/connector-python/.
15+
*/
16+
module MysqlConnectorPython {
17+
// ---------------------------------------------------------------------------
18+
// mysql
19+
// ---------------------------------------------------------------------------
20+
/** Gets a reference to the `mysql` module. */
21+
private DataFlow::Node mysql(DataFlow::TypeTracker t) {
22+
t.start() and
23+
result = DataFlow::importNode("mysql")
24+
or
25+
exists(DataFlow::TypeTracker t2 | result = mysql(t2).track(t2, t))
26+
}
27+
28+
/** Gets a reference to the `mysql` module. */
29+
DataFlow::Node mysql() { result = mysql(DataFlow::TypeTracker::end()) }
30+
31+
/**
32+
* Gets a reference to the attribute `attr_name` of the `mysql` module.
33+
* WARNING: Only holds for a few predefined attributes.
34+
*/
35+
private DataFlow::Node mysql_attr(DataFlow::TypeTracker t, string attr_name) {
36+
attr_name in ["connector"] and
37+
(
38+
t.start() and
39+
result = DataFlow::importNode("mysql" + "." + attr_name)
40+
or
41+
t.startInAttr(attr_name) and
42+
result = mysql()
43+
)
44+
or
45+
// Due to bad performance when using normal setup with `mysql_attr(t2, attr_name).track(t2, t)`
46+
// we have inlined that code and forced a join
47+
exists(DataFlow::TypeTracker t2 |
48+
exists(DataFlow::StepSummary summary |
49+
mysql_attr_first_join(t2, attr_name, result, summary) and
50+
t = t2.append(summary)
51+
)
52+
)
53+
}
54+
55+
pragma[nomagic]
56+
private predicate mysql_attr_first_join(
57+
DataFlow::TypeTracker t2, string attr_name, DataFlow::Node res, DataFlow::StepSummary summary
58+
) {
59+
DataFlow::StepSummary::step(mysql_attr(t2, attr_name), res, summary)
60+
}
61+
62+
/**
63+
* Gets a reference to the attribute `attr_name` of the `mysql` module.
64+
* WARNING: Only holds for a few predefined attributes.
65+
*/
66+
private DataFlow::Node mysql_attr(string attr_name) {
67+
result = mysql_attr(DataFlow::TypeTracker::end(), attr_name)
68+
}
69+
70+
/** Provides models for the `mysql` module. */
71+
module mysql {
72+
/**
73+
* The mysql.connector module
74+
* See https://dev.mysql.com/doc/connector-python/en/connector-python-example-connecting.html
75+
*/
76+
class MysqlConnector extends PEP249Module {
77+
MysqlConnector() { this = mysql_attr("connector") }
78+
}
79+
}
80+
}

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

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

0 commit comments

Comments
 (0)