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

Commit b96546b

Browse files
committed
Improve style of library models
1 parent bb2d5ea commit b96546b

File tree

7 files changed

+72
-103
lines changed

7 files changed

+72
-103
lines changed

ql/src/go.qll

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import semmle.go.dataflow.GlobalValueNumbering
2626
import semmle.go.dataflow.SSA
2727
import semmle.go.dataflow.TaintTracking
2828
import semmle.go.frameworks.Email
29+
import semmle.go.frameworks.Encoding
2930
import semmle.go.frameworks.Glog
3031
import semmle.go.frameworks.HTTP
3132
import semmle.go.frameworks.Macaron
@@ -37,7 +38,4 @@ import semmle.go.frameworks.SystemCommandExecutors
3738
import semmle.go.frameworks.Testing
3839
import semmle.go.frameworks.WebSocket
3940
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
4341
import semmle.go.security.FlowSources
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* Provides classes modelling taint propagation through the `json-iterator` package.
3+
*/
4+
5+
import go
6+
7+
/** Models json-iterator's Unmarshal function, propagating taint from the JSON input to the decoded object. */
8+
private class JsonIteratorUnmarshalFunction extends TaintTracking::FunctionModel,
9+
UnmarshalingFunction::Range {
10+
JsonIteratorUnmarshalFunction() {
11+
this.hasQualifiedName("github.com/json-iterator/go", "Unmarshal")
12+
}
13+
14+
override DataFlow::FunctionInput getAnInput() { result.isParameter(0) }
15+
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+
}

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,3 +232,26 @@ private module StdlibHttp {
232232
}
233233
}
234234

235+
/**
236+
* Provides models of the go-restful library (https://github.com/emicklei/go-restful).
237+
*/
238+
private module GoRestfulHttp {
239+
/**
240+
* A model for methods defined on go-restful's `Request` object that may return user-controlled data.
241+
*/
242+
private class GoRestfulSourceMethod extends Method {
243+
GoRestfulSourceMethod() {
244+
this
245+
.hasQualifiedName("github.com/emicklei/go-restful", "Request",
246+
["QueryParameters", "QueryParameter", "BodyParameter", "HeaderParameter",
247+
"PathParameter", "PathParameters"])
248+
}
249+
}
250+
251+
/**
252+
* A model of go-restful's `Request` object as a source of user-controlled data.
253+
*/
254+
private class GoRestfulSource extends UntrustedFlowSource::Range {
255+
GoRestfulSource() { this = any(GoRestfulSourceMethod g).getACall() }
256+
}
257+
}

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,4 +160,29 @@ module SQL {
160160
}
161161
}
162162
}
163+
164+
/** A model for sinks of github.com/jinzhu/gorm. */
165+
private class GormSink extends SQL::QueryString::Range {
166+
GormSink() {
167+
exists(Method meth, string name |
168+
meth.hasQualifiedName("github.com/jinzhu/gorm", "DB", name) and
169+
this = meth.getACall().getArgument(0) and
170+
name in ["Where", "Raw", "Order", "Not", "Or", "Select", "Table", "Group", "Having", "Joins"]
171+
)
172+
}
173+
}
174+
175+
/** A model for sinks of github.com/jmoiron/sqlx. */
176+
private class SqlxSink extends SQL::QueryString::Range {
177+
SqlxSink() {
178+
exists(Method meth, string name, int n |
179+
meth.hasQualifiedName("github.com/jmoiron/sqlx", ["DB", "Tx"], name) and
180+
this = meth.getACall().getArgument(n)
181+
|
182+
name = ["Select", "Get"] and n = 1
183+
or
184+
name = ["MustExec", "Queryx", "NamedExec", "NamedQuery"] and n = 0
185+
)
186+
}
187+
}
163188
}

ql/src/semmle/go/frameworks/thirdpartlib/Encoding.qll

Lines changed: 0 additions & 25 deletions
This file was deleted.

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

Lines changed: 0 additions & 27 deletions
This file was deleted.

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

Lines changed: 0 additions & 48 deletions
This file was deleted.

0 commit comments

Comments
 (0)