Skip to content

Commit 8744f15

Browse files
committed
New tests
1 parent 374b13e commit 8744f15

File tree

17 files changed

+352
-35
lines changed

17 files changed

+352
-35
lines changed

go/ql/lib/semmle/go/security/TaintedPathCustomizations.qll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ module TaintedPath {
104104
this = m.getACall().getResult()
105105
) and
106106
not exists(CallExpr f |
107-
f.getTarget().hasQualifiedName(package("github.com/gorilla/mux", ""), "SkipClean") and
107+
f.getTarget()
108+
.(Method)
109+
.hasQualifiedName(package("github.com/gorilla/mux", ""), "Router", "SkipClean") and
108110
f.getArgument(0).getBoolValue() = true
109111
)
110112
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// GOOD: Sanitized by Gorilla's cleaner
2+
package main
3+
4+
import (
5+
"io/ioutil"
6+
"net/http"
7+
"path/filepath"
8+
9+
"github.com/gorilla/mux"
10+
)
11+
12+
func GorillaHandler(w http.ResponseWriter, r *http.Request) {
13+
not_tainted_path := mux.Vars(r)["id"]
14+
data, _ := ioutil.ReadFile(filepath.Join("/home/user/", not_tainted_path))
15+
w.Write(data)
16+
}
17+
18+
func main() {
19+
var router = mux.NewRouter()
20+
router.SkipClean(false)
21+
router.HandleFunc("/{category}", GorillaHandler)
22+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
edges
2+
nodes
3+
subpaths
4+
#select
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
query: Security/CWE-022/TaintedPath.ql
2+
postprocess: TestUtilities/PrettyPrintModels.ql
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// GOOD: Sanitized by Gorilla's cleaner
2+
package main
3+
4+
import (
5+
"io/ioutil"
6+
"net/http"
7+
"path/filepath"
8+
9+
"github.com/gorilla/mux"
10+
)
11+
12+
func GorillaHandler(w http.ResponseWriter, r *http.Request) {
13+
not_tainted_path := mux.Vars(r)["id"]
14+
data, _ := ioutil.ReadFile(filepath.Join("/home/user/", not_tainted_path))
15+
w.Write(data)
16+
}
17+
18+
func main() {
19+
var router = mux.NewRouter()
20+
router.SkipClean(true)
21+
router.HandleFunc("/{category}", GorillaHandler)
22+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
edges
2+
| MuxClean.go:13:22:13:32 | call to Vars | MuxClean.go:14:58:14:73 | not_tainted_path | provenance | Src:MaD:524 |
3+
| MuxClean.go:14:58:14:73 | not_tainted_path | MuxClean.go:14:29:14:74 | call to Join | provenance | FunctionModel Sink:MaD:854 |
4+
nodes
5+
| MuxClean.go:13:22:13:32 | call to Vars | semmle.label | call to Vars |
6+
| MuxClean.go:14:29:14:74 | call to Join | semmle.label | call to Join |
7+
| MuxClean.go:14:58:14:73 | not_tainted_path | semmle.label | not_tainted_path |
8+
subpaths
9+
#select
10+
| MuxClean.go:14:29:14:74 | call to Join | MuxClean.go:13:22:13:32 | call to Vars | MuxClean.go:14:29:14:74 | call to Join | This path depends on a $@. | MuxClean.go:13:22:13:32 | call to Vars | user-provided value |

0 commit comments

Comments
 (0)