This repository was archived by the owner on Jan 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 128
Expand file tree
/
Copy pathPgx.qll
More file actions
159 lines (143 loc) · 3.78 KB
/
Pgx.qll
File metadata and controls
159 lines (143 loc) · 3.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/**
* Provides predicates and class for working with sql injection sinks
* from the `github.com/jackc/pgx` and `github.com/jackc/pgconn` packages.
*/
import go
module Pgx {
/** Gets the package name for Jackc. */
string pgx3PackagePath() { result = "github.com/jackc/pgx" }
string pgxStdlibPackagePath() { result = package(["github.com/jackc/pgx"], "stdlib") }
string pgxPackagePath() {
result = package(["github.com/jackc/pgx"], "") and result != pgx3PackagePath()
}
string pgxAnyPackagePath() { result = package(["github.com/jackc/pgx"], "") }
string pgxPoolPackagePath() { result = package(["github.com/jackc/pgx"], "pgxpool") }
string pgconnPackagePath() { result = package(["github.com/jackc/pgconn"], "") }
predicate batchQueries(string pkg, string tp, string m, int arg) {
pkg = pgxAnyPackagePath() and
tp = "Batch" and
(m = "Queue" and arg = 0)
}
predicate stdlibQueries(string pkg, string tp, string m, int arg) {
pkg = pgxStdlibPackagePath() and
tp = "Conn" and
(
m = "Prepare" and arg = 0
or
m = "PrepareContext" and arg = 1
or
m = "Exec" and arg = 0
or
m = "ExecContext" and arg = 1
or
m = "Query" and arg = 0
or
m = "QueryContext" and arg = 1
)
}
predicate v3Queries(string pkg, string tp, string m, int arg) {
pkg = pgx3PackagePath() and
tp = ["Tx", "Conn", "ConnPool", "ReplicationConn"] and
(
m = "Exec" and arg = 0
or
m = "ExecEx" and arg = 1
or
m = "Prepare" and arg = 1
or
m = "PrepareEx" and arg = 2
or
m = "Query" and arg = 0
or
m = "QueryEx" and arg = 1
or
m = "QueryRow" and arg = 0
or
m = "QueryRowEx" and arg = 1
)
}
predicate v4Queries(string pkg, string tp, string m, int arg) {
pkg = pgxPackagePath() and
tp = ["Conn", "Tx"] and
(
m = "Prepare" and arg = 2
or
m = "Exec" and arg = 1
or
m = "Query" and arg = 1
or
m = "QueryRow" and arg = 1
or
m = "QueryFunc" and arg = 1
)
}
predicate pgxpoolConnPoolQueries(string pkg, string tp, string m, int arg) {
pkg = pgxPoolPackagePath() and
tp = ["Conn", "Pool"] and
(
m = "Exec" and arg = 1
or
m = "Query" and arg = 1
or
m = "QueryRow" and arg = 1
or
m = "QueryFunc" and arg = 1
)
}
predicate pgxpoolTxQueries(string pkg, string tp, string m, int arg) {
pkg = pgxPoolPackagePath() and
tp = ["Tx"] and
(
m = "Exec" and arg = 1
or
m = "Query" and arg = 1
or
m = "QueryRow" and arg = 1
or
m = "QueryFunc" and arg = 1
or
m = "Prepare" and arg = 2
)
}
predicate pgconnQueries(string pkg, string tp, string m, int arg) {
pkg = pgconnPackagePath() and
tp = "PgConn" and
(
m = "Exec" and arg = 1
or
m = "ExecParams" and arg = 1
or
m = "CopyTo" and arg = 2
or
m = "CopyFrom" and arg = 2
or
m = "Prepare" and arg = 2
)
}
predicate pgxQueries(string pkg, string tp, string m, int arg) {
pgconnQueries(pkg, tp, m, arg)
or
pgxpoolTxQueries(pkg, tp, m, arg)
or
pgxpoolConnPoolQueries(pkg, tp, m, arg)
or
v3Queries(pkg, tp, m, arg)
or
v4Queries(pkg, tp, m, arg)
or
stdlibQueries(pkg, tp, m, arg)
or
batchQueries(pkg, tp, m, arg)
}
/** A model for sinks of github.com/jackc/pgx. */
class QueryString extends DataFlow::Node {
// class QueryString extends SQL::QueryString {
QueryString() {
exists(Method meth, string pkg, string tp, string m, int arg |
pgxQueries(pkg, tp, m, arg) and
meth.hasQualifiedName(pkg, tp, m) and
this = meth.getACall().getArgument(arg)
)
}
}
}