Skip to content

Commit ceb5b4c

Browse files
committed
Python: No longer use models-as-data CSV interface
1 parent 9d8b93e commit ceb5b4c

File tree

5 files changed

+39
-54
lines changed

5 files changed

+39
-54
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
extensions:
2+
- addsTo:
3+
pack: codeql/python-all
4+
extensible: sinkModel
5+
data:
6+
# `Connection`s and `ConnectionPool`s provide some methods that execute SQL.
7+
- ['asyncpg.~Connection', 'Member[copy_from_query,execute,fetch,fetchrow,fetchval].Argument[0,query:]', 'sql-injection']
8+
- ['asyncpg.~Connection', 'Member[executemany].Argument[0,command:]', 'sql-injection']
9+
# A model of `Connection` and `ConnectionPool`, which provide some methods that access the file system.
10+
- ['asyncpg.~Connection', 'Member[copy_from_query,copy_from_table].Argument[output:]', 'path-injection']
11+
- ['asyncpg.~Connection', 'Member[copy_to_table].Argument[source:]', 'path-injection']
12+
# the `PreparedStatement` class in `asyncpg`.
13+
- ['asyncpg.Connection', 'Member[prepare].Argument[0,query:]', 'sql-injection']
14+
15+
- addsTo:
16+
pack: codeql/python-all
17+
extensible: typeModel
18+
data:
19+
# a `ConnectionPool` that is created when the result of `asyncpg.create_pool()` is awaited.
20+
- ['asyncpg.Connection', 'asyncpg.ConnectionPool', 'Member[acquire].ReturnValue.Awaited']
21+
# a `Connection` that is created when
22+
# * - the result of `asyncpg.connect()` is awaited.
23+
# * - the result of calling `acquire` on a `ConnectionPool` is awaited.
24+
- ['asyncpg.Connection', 'asyncpg', 'Member[connect].ReturnValue.Awaited']
25+
- ['asyncpg.Connection', 'asyncpg', 'Member[connection].Member[connect].ReturnValue.Awaited']
26+
- ['asyncpg.ConnectionPool', 'asyncpg', 'Member[create_pool].ReturnValue.Awaited']
27+
# Creating an internal `~Connection` type that contains both `Connection` and `ConnectionPool`.
28+
- ['asyncpg.~Connection', 'asyncpg.Connection', '']
29+
- ['asyncpg.~Connection', 'asyncpg.ConnectionPool', '']

python/ql/lib/semmle/python/frameworks/Asyncpg.qll

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -11,43 +11,6 @@ private import semmle.python.frameworks.data.ModelsAsData
1111

1212
/** Provides models for the `asyncpg` PyPI package. */
1313
private module Asyncpg {
14-
class AsyncpgModel extends ModelInput::TypeModelCsv {
15-
override predicate row(string row) {
16-
// type1;type2;path
17-
row =
18-
[
19-
// a `ConnectionPool` that is created when the result of `asyncpg.create_pool()` is awaited.
20-
"asyncpg.ConnectionPool;asyncpg;Member[create_pool].ReturnValue.Awaited",
21-
// a `Connection` that is created when
22-
// * - the result of `asyncpg.connect()` is awaited.
23-
// * - the result of calling `acquire` on a `ConnectionPool` is awaited.
24-
"asyncpg.Connection;asyncpg;Member[connect].ReturnValue.Awaited",
25-
"asyncpg.Connection;asyncpg;Member[connection].Member[connect].ReturnValue.Awaited",
26-
"asyncpg.Connection;asyncpg.ConnectionPool;Member[acquire].ReturnValue.Awaited",
27-
// Creating an internal `~Connection` type that contains both `Connection` and `ConnectionPool`.
28-
"asyncpg.~Connection;asyncpg.Connection;", //
29-
"asyncpg.~Connection;asyncpg.ConnectionPool;"
30-
]
31-
}
32-
}
33-
34-
class AsyncpgSink extends ModelInput::SinkModelCsv {
35-
// type;path;kind
36-
override predicate row(string row) {
37-
row =
38-
[
39-
// `Connection`s and `ConnectionPool`s provide some methods that execute SQL.
40-
"asyncpg.~Connection;Member[copy_from_query,execute,fetch,fetchrow,fetchval].Argument[0,query:];sql-injection",
41-
"asyncpg.~Connection;Member[executemany].Argument[0,command:];sql-injection",
42-
// A model of `Connection` and `ConnectionPool`, which provide some methods that access the file system.
43-
"asyncpg.~Connection;Member[copy_from_query,copy_from_table].Argument[output:];path-injection",
44-
"asyncpg.~Connection;Member[copy_to_table].Argument[source:];path-injection",
45-
// the `PreparedStatement` class in `asyncpg`.
46-
"asyncpg.Connection;Member[prepare].Argument[0,query:];sql-injection",
47-
]
48-
}
49-
}
50-
5114
/**
5215
* Provides models of the `Cursor` class in `asyncpg`.
5316
* `Cursor`s are created

python/ql/test/library-tests/frameworks/data/warnings.expected

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
| CSV type row should have 3 columns but has 1: test.TooFewColumns |
2-
| CSV type row should have 3 columns but has 6: test.TooManyColumns;;Member[Foo].Instance;too;many;columns |
31
| Invalid argument '0-1' in token 'Argument[0-1]' in access path: Method[foo].Argument[0-1] |
42
| Invalid argument '*' in token 'Argument[*]' in access path: Method[foo].Argument[*] |
53
| Invalid token 'Argument' is missing its arguments, in access path: Method[foo].Argument |
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
extensions:
2+
- addsTo:
3+
pack: codeql/python-all
4+
extensible: typeModel
5+
data:
6+
- ['test.X', 'test.Y', 'Method[foo].Arg[0]']
7+
- ['test.X', 'test.Y', 'Method[foo].Argument[0-1]']
8+
- ['test.X', 'test.Y', 'Method[foo].Argument[*]']
9+
- ['test.X', 'test.Y', 'Method[foo].Argument']
10+
- ['test.X', 'test.Y', 'Method[foo].Member']

python/ql/test/library-tests/frameworks/data/warnings.ql

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,6 @@ import python
22
import semmle.python.frameworks.data.internal.ApiGraphModels as ApiGraphModels
33
import semmle.python.frameworks.data.ModelsAsData
44

5-
private class InvalidTypeModel extends ModelInput::TypeModelCsv {
6-
override predicate row(string row) {
7-
row =
8-
[
9-
"test.TooManyColumns;;Member[Foo].Instance;too;many;columns", //
10-
"test.TooFewColumns", //
11-
"test.X;test.Y;Method[foo].Arg[0]", //
12-
"test.X;test.Y;Method[foo].Argument[0-1]", //
13-
"test.X;test.Y;Method[foo].Argument[*]", //
14-
"test.X;test.Y;Method[foo].Argument", //
15-
"test.X;test.Y;Method[foo].Member", //
16-
]
17-
}
18-
}
19-
205
class IsTesting extends ApiGraphModels::TestAllModels {
216
IsTesting() { this = this }
227
}

0 commit comments

Comments
 (0)