From 1287f1befc2a942458ebd329de02277ed87067d1 Mon Sep 17 00:00:00 2001 From: Kevin Stubbings Date: Tue, 15 Oct 2024 14:01:14 -0700 Subject: [PATCH] Address feedback --- .../go/security/TaintedPathCustomizations.qll | 20 +++++++++---------- .../Security/CWE-022/TaintedPath.go | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/go/ql/lib/semmle/go/security/TaintedPathCustomizations.qll b/go/ql/lib/semmle/go/security/TaintedPathCustomizations.qll index f75a16ceccf8..f505df8b34bf 100644 --- a/go/ql/lib/semmle/go/security/TaintedPathCustomizations.qll +++ b/go/ql/lib/semmle/go/security/TaintedPathCustomizations.qll @@ -93,26 +93,26 @@ module TaintedPath { } } - // /** - // * A call to `mux.Vars(path)`, considered to sanitize `path` against path traversal. - // * Only enabled when `SkipClean` is not set true. - // */ + /** + * A call to `mux.Vars(path)`, considered to sanitize `path` against path traversal. + * Only enabled when `SkipClean` is not set true. + */ class MuxVarsSanitizer extends Sanitizer { MuxVarsSanitizer() { exists(Function m | - m.hasQualifiedName("github.com/gorilla/mux", "Vars") and + m.hasQualifiedName(package("github.com/gorilla/mux", ""), "Vars") and this = m.getACall().getResult() ) and not exists(CallExpr f | - f.getTarget().hasQualifiedName("github.com/gorilla/mux", "SkipClean") and - f.getArgument(0).toString().toLowerCase() = "true" + f.getTarget().hasQualifiedName(package("github.com/gorilla/mux", ""), "SkipClean") and + f.getArgument(0).getBoolValue() = true ) } } - // /** - // * A read from `net/url` which is sanitized - // */ + /** + * A read from the field `Path` of the type `net/url.URL`, which is sanitized. + */ class UrlPathSanitizer extends Sanitizer { UrlPathSanitizer() { exists(DataFlow::Field fld | diff --git a/go/ql/test/query-tests/Security/CWE-022/TaintedPath.go b/go/ql/test/query-tests/Security/CWE-022/TaintedPath.go index b57e293a8243..3fed218b7000 100644 --- a/go/ql/test/query-tests/Security/CWE-022/TaintedPath.go +++ b/go/ql/test/query-tests/Security/CWE-022/TaintedPath.go @@ -99,7 +99,7 @@ func handler(w http.ResponseWriter, r *http.Request) { // GOOD: Sanitized by Gorilla's cleaner func GorillaHandler(w http.ResponseWriter, r *http.Request) { - not_tainted_path := mux.Vars(r) + not_tainted_path := mux.Vars(r)["id"] data, _ := ioutil.ReadFile(filepath.Join("/home/user/", not_tainted_path)) w.Write(data) }