mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
Golang: Mark filepath.IsLocal as a tainted-path sanitizer guard
This commit is contained in:
@@ -243,4 +243,20 @@ module TaintedPath {
|
||||
|
||||
override predicate checks(Expr e, boolean branch) { regexpFunctionChecksExpr(this, e, branch) }
|
||||
}
|
||||
|
||||
/**
|
||||
* A call of the form `filepath.IsLocal(path)` considered as a sanitizer guard for `path`.
|
||||
*/
|
||||
class IsLocalCheck extends SanitizerGuard, DataFlow::CallNode {
|
||||
IsLocalCheck() {
|
||||
exists(Function f |
|
||||
f.hasQualifiedName("filepath", "IsLocal") and
|
||||
this = f.getACall()
|
||||
)
|
||||
}
|
||||
|
||||
override predicate checks(Expr e, boolean branch) {
|
||||
e = this.getArgument(0).asExpr() and branch = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,4 +93,10 @@ func handler(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
data, _ = ioutil.ReadFile(part.FileName())
|
||||
|
||||
// GOOD: An attempt has been made to prevent path traversal
|
||||
if filepath.IsLocal(tainted_path) {
|
||||
data, _ = ioutil.ReadFile(tainted_path)
|
||||
w.Write(data)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user