Skip to content

Commit 0538595

Browse files
committed
Move Scan methods to QL classes
1 parent 5435c19 commit 0538595

File tree

2 files changed

+85
-5
lines changed

2 files changed

+85
-5
lines changed

go/ql/lib/ext/github.com.mastermind.squirrel.model.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,3 @@ extensions:
8181
- ["group:squirrel", "UpdateBuilder", True, "Suffix", "", "", "Argument[0]", "sql-injection", "manual"]
8282
- ["group:squirrel", "UpdateBuilder", True, "Table", "", "", "Argument[0]", "sql-injection", "manual"]
8383
# UpdateBuilder.Where has to be modeled in QL to avoid FPs when a non-string argument is used
84-
- addsTo:
85-
pack: codeql/go-all
86-
extensible: summaryModel
87-
data:
88-
- ["group:squirrel", "RowScanner", True, "Scan", "", "", "Argument[receiver]", "Argument[0]", "taint", "manual"]
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/**
2+
* Provides classes modeling security-relevant aspects of the `squirrel` ORM package.
3+
*/
4+
5+
import go
6+
7+
/**
8+
* Provides classes modeling security-relevant aspects of the `squirrel` ORM package.
9+
*/
10+
module Squirrel {
11+
private string packagePath() {
12+
result =
13+
package([
14+
"github.com/Masterminds/squirrel",
15+
"github.com/lann/squirrel",
16+
"gopkg.in/Masterminds/squirrel",
17+
], "")
18+
}
19+
20+
private class RowScan extends TaintTracking::FunctionModel, Method {
21+
FunctionInput inp;
22+
FunctionOutput outp;
23+
24+
RowScan() {
25+
// signature: func (rs *RowScanner) Scan(dest ...interface{}) error
26+
this.hasQualifiedName(packagePath(), "Row", "Scan") and
27+
inp.isReceiver() and
28+
outp.isParameter(_)
29+
}
30+
31+
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
32+
input = inp and output = outp
33+
}
34+
}
35+
36+
private class RowScannerScan extends TaintTracking::FunctionModel, Method {
37+
FunctionInput inp;
38+
FunctionOutput outp;
39+
40+
RowScannerScan() {
41+
// signature: func (rs *RowScanner) Scan(dest ...interface{}) error
42+
this.hasQualifiedName(packagePath(), "RowScanner", "Scan") and
43+
inp.isReceiver() and
44+
outp.isParameter(_)
45+
}
46+
47+
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
48+
input = inp and output = outp
49+
}
50+
}
51+
52+
private class BuilderScan extends TaintTracking::FunctionModel, Method {
53+
FunctionInput inp;
54+
FunctionOutput outp;
55+
56+
BuilderScan() {
57+
// signature: func (rs *InsertBuilder) Scan(dest ...interface{}) error
58+
this.hasQualifiedName(packagePath(),
59+
["DeleteBuilder", "InsertBuilder", "SelectBuilder", "UpdateBuilder"], "Scan") and
60+
inp.isReceiver() and
61+
outp.isParameter(_)
62+
}
63+
64+
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
65+
input = inp and output = outp
66+
}
67+
}
68+
69+
private class BuilderScanContext extends TaintTracking::FunctionModel, Method {
70+
FunctionInput inp;
71+
FunctionOutput outp;
72+
73+
BuilderScanContext() {
74+
// signature: func (rs *InsertBuilder) Scan(dest ...interface{}) error
75+
this.hasQualifiedName(packagePath(),
76+
["DeleteBuilder", "InsertBuilder", "SelectBuilder", "UpdateBuilder"], "ScanContext") and
77+
inp.isReceiver() and
78+
exists(int i | i > 0 | outp.isParameter(i))
79+
}
80+
81+
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
82+
input = inp and output = outp
83+
}
84+
}
85+
}

0 commit comments

Comments
 (0)