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

Commit 3c4a1b9

Browse files
committed
Add test for Go-restful
1 parent b96546b commit 3c4a1b9

File tree

10 files changed

+196
-1
lines changed

10 files changed

+196
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ private module GoRestfulHttp {
242242
private class GoRestfulSourceMethod extends Method {
243243
GoRestfulSourceMethod() {
244244
this
245-
.hasQualifiedName("github.com/emicklei/go-restful", "Request",
245+
.hasQualifiedName(package("github.com/emicklei/go-restful", ""), "Request",
246246
["QueryParameters", "QueryParameter", "BodyParameter", "HeaderParameter",
247247
"PathParameter", "PathParameters"])
248248
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module gorestfultest
2+
3+
go 1.14
4+
5+
require (
6+
github.com/emicklei/go-restful/v3 v3.2.0
7+
github.com/json-iterator/go v1.1.10 // indirect
8+
)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
| gorestful.go:9:15:9:47 | index expression | gorestful.go:9:15:9:44 | call to QueryParameters : slice type | gorestful.go:9:15:9:47 | index expression | This command depends on $@. | gorestful.go:9:15:9:44 | call to QueryParameters | a user-provided value |
2+
| gorestful.go:10:15:10:43 | call to QueryParameter | gorestful.go:10:15:10:43 | call to QueryParameter | gorestful.go:10:15:10:43 | call to QueryParameter | This command depends on $@. | gorestful.go:10:15:10:43 | call to QueryParameter | a user-provided value |
3+
| gorestful.go:12:15:12:17 | val | gorestful.go:11:12:11:39 | call to BodyParameter : tuple type | gorestful.go:12:15:12:17 | val | This command depends on $@. | gorestful.go:11:12:11:39 | call to BodyParameter | a user-provided value |
4+
| gorestful.go:13:15:13:44 | call to HeaderParameter | gorestful.go:13:15:13:44 | call to HeaderParameter | gorestful.go:13:15:13:44 | call to HeaderParameter | This command depends on $@. | gorestful.go:13:15:13:44 | call to HeaderParameter | a user-provided value |
5+
| gorestful.go:14:15:14:42 | call to PathParameter | gorestful.go:14:15:14:42 | call to PathParameter | gorestful.go:14:15:14:42 | call to PathParameter | This command depends on $@. | gorestful.go:14:15:14:42 | call to PathParameter | a user-provided value |
6+
| gorestful.go:15:15:15:45 | index expression | gorestful.go:15:15:15:38 | call to PathParameters : map type | gorestful.go:15:15:15:45 | index expression | This command depends on $@. | gorestful.go:15:15:15:38 | call to PathParameters | a user-provided value |
7+
| gorestful_v2.go:9:15:9:47 | index expression | gorestful_v2.go:9:15:9:44 | call to QueryParameters : slice type | gorestful_v2.go:9:15:9:47 | index expression | This command depends on $@. | gorestful_v2.go:9:15:9:44 | call to QueryParameters | a user-provided value |
8+
| gorestful_v2.go:10:15:10:43 | call to QueryParameter | gorestful_v2.go:10:15:10:43 | call to QueryParameter | gorestful_v2.go:10:15:10:43 | call to QueryParameter | This command depends on $@. | gorestful_v2.go:10:15:10:43 | call to QueryParameter | a user-provided value |
9+
| gorestful_v2.go:12:15:12:17 | val | gorestful_v2.go:11:12:11:39 | call to BodyParameter : tuple type | gorestful_v2.go:12:15:12:17 | val | This command depends on $@. | gorestful_v2.go:11:12:11:39 | call to BodyParameter | a user-provided value |
10+
| gorestful_v2.go:13:15:13:44 | call to HeaderParameter | gorestful_v2.go:13:15:13:44 | call to HeaderParameter | gorestful_v2.go:13:15:13:44 | call to HeaderParameter | This command depends on $@. | gorestful_v2.go:13:15:13:44 | call to HeaderParameter | a user-provided value |
11+
| gorestful_v2.go:14:15:14:42 | call to PathParameter | gorestful_v2.go:14:15:14:42 | call to PathParameter | gorestful_v2.go:14:15:14:42 | call to PathParameter | This command depends on $@. | gorestful_v2.go:14:15:14:42 | call to PathParameter | a user-provided value |
12+
| gorestful_v2.go:15:15:15:45 | index expression | gorestful_v2.go:15:15:15:38 | call to PathParameters : map type | gorestful_v2.go:15:15:15:45 | index expression | This command depends on $@. | gorestful_v2.go:15:15:15:38 | call to PathParameters | a user-provided value |
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package gorestfultest
2+
3+
import (
4+
restful "github.com/emicklei/go-restful/v3"
5+
"os/exec"
6+
)
7+
8+
func requestHandler(request *restful.Request, response *restful.Response) {
9+
exec.Command(request.QueryParameters("xyz")[0]) // BAD
10+
exec.Command(request.QueryParameter("xyz")) // BAD
11+
val, _ := request.BodyParameter("xyz")
12+
exec.Command(val) // BAD
13+
exec.Command(request.HeaderParameter("xyz")) // BAD
14+
exec.Command(request.PathParameter("xyz")) // BAD
15+
exec.Command(request.PathParameters()["xyz"]) // BAD
16+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import go
2+
import semmle.go.security.CommandInjection
3+
4+
from CommandInjection::Configuration cfg, DataFlow::PathNode source, DataFlow::PathNode sink
5+
where cfg.hasFlowPath(source, sink)
6+
select sink.getNode(), source, sink, "This command depends on $@.", source.getNode(),
7+
"a user-provided value"
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package gorestfultest
2+
3+
import (
4+
restful "github.com/emicklei/go-restful"
5+
"os/exec"
6+
)
7+
8+
func requestHandlerV2(request *restful.Request, response *restful.Response) {
9+
exec.Command(request.QueryParameters("xyz")[0]) // BAD
10+
exec.Command(request.QueryParameter("xyz")) // BAD
11+
val, _ := request.BodyParameter("xyz")
12+
exec.Command(val) // BAD
13+
exec.Command(request.HeaderParameter("xyz")) // BAD
14+
exec.Command(request.PathParameter("xyz")) // BAD
15+
exec.Command(request.PathParameters()["xyz"]) // BAD
16+
}

ql/test/library-tests/semmle/go/frameworks/HTTP/Gorestful/vendor/github.com/emicklei/go-restful/LICENSE

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

ql/test/library-tests/semmle/go/frameworks/HTTP/Gorestful/vendor/github.com/emicklei/go-restful/stub.go

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

ql/test/library-tests/semmle/go/frameworks/HTTP/Gorestful/vendor/github.com/emicklei/go-restful/v3/stub.go

Lines changed: 54 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# github.com/emicklei/go-restful/v3 v3.2.0
2+
## explicit
3+
github.com/emicklei/go-restful/v3
4+
# github.com/json-iterator/go v1.1.10
5+
## explicit
6+
github.com/json-iterator/go

0 commit comments

Comments
 (0)