mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
Update go path sanitizers and sinks
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
---
|
||||
category: minorAnalysis
|
||||
---
|
||||
* Remove model`CreateTemp` function, from the `os` package, as a path-injection sink due to proper sanitization by Go. Add check for `os.PathSeparator` in sanitizers for path-injection query.
|
||||
@@ -28,7 +28,6 @@ extensions:
|
||||
- ["os", "", False, "ReadDir", "", "", "Argument[0]", "path-injection", "manual"]
|
||||
- ["os", "", False, "ReadFile", "", "", "Argument[0]", "path-injection", "manual"]
|
||||
- ["os", "", False, "MkdirTemp", "", "", "Argument[0..1]", "path-injection", "manual"]
|
||||
- ["os", "", False, "CreateTemp", "", "", "Argument[0..1]", "path-injection", "manual"]
|
||||
- ["os", "", False, "WriteFile", "", "", "Argument[0]", "path-injection", "manual"]
|
||||
# command-injection
|
||||
- ["os", "", False, "StartProcess", "", "", "Argument[0]", "command-injection", "manual"]
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
#select
|
||||
| TaintedPath.go:17:29:17:40 | tainted_path | TaintedPath.go:14:18:14:22 | selection of URL | TaintedPath.go:17:29:17:40 | tainted_path | This path depends on a $@. | TaintedPath.go:14:18:14:22 | selection of URL | user-provided value |
|
||||
| TaintedPath.go:21:28:21:69 | call to Join | TaintedPath.go:14:18:14:22 | selection of URL | TaintedPath.go:21:28:21:69 | call to Join | This path depends on a $@. | TaintedPath.go:14:18:14:22 | selection of URL | user-provided value |
|
||||
| TaintedPath.go:68:28:68:57 | call to Clean | TaintedPath.go:14:18:14:22 | selection of URL | TaintedPath.go:68:28:68:57 | call to Clean | This path depends on a $@. | TaintedPath.go:14:18:14:22 | selection of URL | user-provided value |
|
||||
| TaintedPath.go:69:28:69:57 | call to Clean | TaintedPath.go:14:18:14:22 | selection of URL | TaintedPath.go:69:28:69:57 | call to Clean | This path depends on a $@. | TaintedPath.go:14:18:14:22 | selection of URL | user-provided value |
|
||||
edges
|
||||
| TaintedPath.go:14:18:14:22 | selection of URL | TaintedPath.go:14:18:14:30 | call to Query | provenance | Src:MaD:2 MaD:3 |
|
||||
| TaintedPath.go:14:18:14:30 | call to Query | TaintedPath.go:17:29:17:40 | tainted_path | provenance | Sink:MaD:1 |
|
||||
| TaintedPath.go:14:18:14:30 | call to Query | TaintedPath.go:21:57:21:68 | tainted_path | provenance | |
|
||||
| TaintedPath.go:14:18:14:30 | call to Query | TaintedPath.go:68:39:68:56 | ...+... | provenance | |
|
||||
| TaintedPath.go:14:18:14:30 | call to Query | TaintedPath.go:69:39:69:56 | ...+... | provenance | |
|
||||
| TaintedPath.go:21:57:21:68 | tainted_path | TaintedPath.go:21:28:21:69 | call to Join | provenance | FunctionModel Sink:MaD:1 |
|
||||
| TaintedPath.go:68:39:68:56 | ...+... | TaintedPath.go:68:28:68:57 | call to Clean | provenance | MaD:4 Sink:MaD:1 |
|
||||
| TaintedPath.go:69:39:69:56 | ...+... | TaintedPath.go:69:28:69:57 | call to Clean | provenance | MaD:4 Sink:MaD:1 |
|
||||
models
|
||||
| 1 | Sink: io/ioutil; ; false; ReadFile; ; ; Argument[0]; path-injection; manual |
|
||||
| 2 | Source: net/http; Request; true; URL; ; ; ; remote; manual |
|
||||
@@ -20,6 +20,6 @@ nodes
|
||||
| TaintedPath.go:17:29:17:40 | tainted_path | semmle.label | tainted_path |
|
||||
| TaintedPath.go:21:28:21:69 | call to Join | semmle.label | call to Join |
|
||||
| TaintedPath.go:21:57:21:68 | tainted_path | semmle.label | tainted_path |
|
||||
| TaintedPath.go:68:28:68:57 | call to Clean | semmle.label | call to Clean |
|
||||
| TaintedPath.go:68:39:68:56 | ...+... | semmle.label | ...+... |
|
||||
| TaintedPath.go:69:28:69:57 | call to Clean | semmle.label | call to Clean |
|
||||
| TaintedPath.go:69:39:69:56 | ...+... | semmle.label | ...+... |
|
||||
subpaths
|
||||
|
||||
@@ -8,8 +8,8 @@ import (
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
"os"
|
||||
)
|
||||
|
||||
func handler(w http.ResponseWriter, r *http.Request) {
|
||||
tainted_path := r.URL.Query()["path"][0]
|
||||
|
||||
@@ -58,9 +58,10 @@ func handler(w http.ResponseWriter, r *http.Request) {
|
||||
w.Write(data)
|
||||
}
|
||||
|
||||
// GOOD: Sanitized by filepath.Clean with a prepended '/' forcing interpretation
|
||||
// GOOD: Sanitized by filepath.Clean with a prepended '/' or os.PathSeparator forcing interpretation
|
||||
// as an absolute path, so that Clean will throw away any leading `..` components.
|
||||
data, _ = ioutil.ReadFile(filepath.Clean("/" + tainted_path))
|
||||
data, _ = ioutil.ReadFile(filepath.Clean(string(os.PathSeparator) + tainted_path))
|
||||
w.Write(data)
|
||||
|
||||
// BAD: Sanitized by path.Clean with a prepended '/' forcing interpretation
|
||||
|
||||
Reference in New Issue
Block a user