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

Commit bb2d5ea

Browse files
Ricter Zsmowton
authored andcommitted
add some sinks in commonly-used SQL libraries
1 parent b9e6111 commit bb2d5ea

File tree

5 files changed

+104
-0
lines changed

5 files changed

+104
-0
lines changed

ql/src/go.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,7 @@ import semmle.go.frameworks.SystemCommandExecutors
3737
import semmle.go.frameworks.Testing
3838
import semmle.go.frameworks.WebSocket
3939
import semmle.go.frameworks.XPath
40+
import semmle.go.frameworks.thirdpartlib.HTTP
41+
import semmle.go.frameworks.thirdpartlib.SQL
42+
import semmle.go.frameworks.thirdpartlib.Encoding
4043
import semmle.go.security.FlowSources

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,3 +231,4 @@ private module StdlibHttp {
231231
}
232232
}
233233
}
234+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* Provides classes modeling security-relevant aspects of the third-part libraries.
3+
*/
4+
5+
import go
6+
7+
module ThirdPartEncodingJson {
8+
/** Provides models of some functions in the `github.com/json-iterator/go` package. */
9+
class JsoniterUnmarshalingFunction extends TaintTracking::FunctionModel, UnmarshalingFunction::Range {
10+
11+
JsoniterUnmarshalingFunction() {
12+
this.hasQualifiedName("github.com/json-iterator/go", "Unmarshal")
13+
}
14+
15+
override DataFlow::FunctionInput getAnInput() { result.isParameter(0) }
16+
override DataFlow::FunctionOutput getOutput() { result.isParameter(1) }
17+
18+
override string getFormat() { result = "JSON" }
19+
20+
override predicate hasTaintFlow(DataFlow::FunctionInput inp, DataFlow::FunctionOutput outp) {
21+
inp = getAnInput() and outp = getOutput()
22+
}
23+
}
24+
}
25+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* Provides classes for working with HTTP-related concepts such as requests and responses.
3+
*/
4+
5+
import go
6+
7+
module ThirdPartHttpLib {
8+
/**
9+
* Source from go-resultful
10+
* Document: https://github.com/emicklei/go-restful
11+
*/
12+
class GoRestfulSource extends DataFlow::Node, UntrustedFlowSource::Range {
13+
GoRestfulSource() {
14+
exists(
15+
Method meth, string name |
16+
meth.hasQualifiedName("github.com/emicklei/go-restful", "Request", name) and
17+
asExpr() = meth.getACall().asExpr() and
18+
(
19+
name = "QueryParameters" or name = "QueryParameter" or
20+
name = "BodyParamater" or name = "HeaderParameter" or
21+
name = "PathParameter" or name = "PathParameters"
22+
)
23+
)
24+
}
25+
}
26+
}
27+
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* Provides classes for working with SQL-related concepts such as queries.
3+
*/
4+
5+
import go
6+
7+
module ThirdPartSQL {
8+
9+
/** Sinks of github.com/jinzhu/gorm */
10+
class GormSink extends DataFlow::Node, SQL::QueryString::Range {
11+
GormSink() {
12+
exists(
13+
Method meth, string name |
14+
meth.hasQualifiedName("github.com/jinzhu/gorm", "DB", name) and
15+
asExpr() = meth.getACall().getArgument(0).asExpr() and
16+
(
17+
name = "Where" or name = "Raw" or name = "Order" or name = "Not" or name = "Or" or
18+
name = "Select" or name = "Table" or name = "Group" or name = "Having" or name = "Joins"
19+
)
20+
)
21+
}
22+
}
23+
24+
/** Sinks of github.com/jmoiron/sqlx */
25+
class SqlxSink extends DataFlow::Node, SQL::QueryString::Range {
26+
SqlxSink() {
27+
exists(
28+
Method meth, string name, int n |
29+
(
30+
meth.hasQualifiedName("github.com/jmoiron/sqlx", "DB", name) or
31+
meth.hasQualifiedName("github.com/jmoiron/sqlx", "Tx", name)
32+
) and this = meth.getACall().getArgument(n) |
33+
(
34+
(name = "Select" or name = "Get") and n = 1
35+
)
36+
or
37+
(
38+
(
39+
name = "MustExec" or name = "Queryx" or
40+
name = "NamedExec" or name = "NamedQuery"
41+
)
42+
and n = 0
43+
)
44+
)
45+
}
46+
}
47+
48+
}

0 commit comments

Comments
 (0)