Skip to content
This repository was archived by the owner on Jan 5, 2023. It is now read-only.

Commit 6f0bfbf

Browse files
committed
Add taint-tracking to database/sql package in the SQL module
1 parent 55a8e24 commit 6f0bfbf

File tree

2 files changed

+120
-0
lines changed

2 files changed

+120
-0
lines changed

ql/src/semmle/go/frameworks/SQL.qll

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,48 @@ import go
66

77
/** Provides classes for working with SQL-related APIs. */
88
module SQL {
9+
private class FunctionModels extends TaintTracking::FunctionModel {
10+
FunctionInput inp;
11+
FunctionOutput outp;
12+
13+
FunctionModels() {
14+
// signature: func Named(name string, value interface{}) NamedArg
15+
hasQualifiedName("database/sql", "Named") and
16+
(inp.isParameter(_) and outp.isResult())
17+
}
18+
19+
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
20+
input = inp and output = outp
21+
}
22+
}
23+
24+
private class MethodModels extends TaintTracking::FunctionModel, Method {
25+
FunctionInput inp;
26+
FunctionOutput outp;
27+
28+
MethodModels() {
29+
// signature: func (*NullString).Scan(value interface{}) error
30+
this.hasQualifiedName("database/sql", "NullString", "Scan") and
31+
(inp.isParameter(0) and outp.isReceiver())
32+
or
33+
// signature: func (*Row).Scan(dest ...interface{}) error
34+
this.hasQualifiedName("database/sql", "Row", "Scan") and
35+
(inp.isReceiver() and outp.isParameter(_))
36+
or
37+
// signature: func (*Rows).Scan(dest ...interface{}) error
38+
this.hasQualifiedName("database/sql", "Rows", "Scan") and
39+
(inp.isReceiver() and outp.isParameter(_))
40+
or
41+
// signature: func (Scanner).Scan(src interface{}) error
42+
this.implements("database/sql", "Scanner", "Scan") and
43+
(inp.isParameter(0) and outp.isReceiver())
44+
}
45+
46+
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
47+
input = inp and output = outp
48+
}
49+
}
50+
951
/**
1052
* A data-flow node whose string value is interpreted as (part of) a SQL query.
1153
*

ql/test/library-tests/semmle/go/frameworks/StdlibTaintFlow/DatabaseSql.go

Lines changed: 78 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)