Skip to content

Commit 30fe416

Browse files
committed
Removed filepath.base sanitizer
1 parent c4c0b22 commit 30fe416

File tree

5 files changed

+7
-51
lines changed

5 files changed

+7
-51
lines changed

go/ql/lib/change-notes/2023-10-08-addional-gopath-sanitizers.md

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
* ---
3+
category: minorAnalysis
4+
---
5+
* Added strings.ReplaceAll, http.ParseMultipartForm sanitizers and remove path sanitizer.

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

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -88,19 +88,6 @@ module TaintedPath {
8888
}
8989
}
9090

91-
/**
92-
* A call to `filepath.Base(e)`, considered to sanitize `e` against path traversal.
93-
*/
94-
class FilepathBaseSanitizer extends Sanitizer {
95-
FilepathBaseSanitizer() {
96-
exists(Function f, FunctionOutput outp |
97-
f.hasQualifiedName("path/filepath", "Base") and
98-
outp.isResult(0) and
99-
this = outp.getNode(f.getACall())
100-
)
101-
}
102-
}
103-
10491
/**An call to ParseMultipartForm creates multipart.Form and cleans mutlpart.Form.FileHeader.Filename using path.Base() */
10592
class MultipartClean extends Sanitizer {
10693
MultipartClean() {
Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,10 @@
11
edges
2-
<<<<<<< HEAD
3-
<<<<<<< HEAD
42
| TaintedPath.go:13:18:13:22 | selection of URL | TaintedPath.go:13:18:13:30 | call to Query | provenance | |
53
| TaintedPath.go:13:18:13:30 | call to Query | TaintedPath.go:16:29:16:40 | tainted_path | provenance | |
64
| TaintedPath.go:13:18:13:30 | call to Query | TaintedPath.go:20:57:20:68 | tainted_path | provenance | |
5+
| TaintedPath.go:13:18:13:30 | call to Query | TaintedPath.go:67:39:67:56 | ...+... | provenance | |
76
| TaintedPath.go:20:57:20:68 | tainted_path | TaintedPath.go:20:28:20:69 | call to Join | provenance | |
8-
| tst.go:14:2:14:39 | ... := ...[1] | tst.go:17:41:17:56 | selection of Filename | provenance | |
9-
=======
10-
| TaintedPath.go:13:18:13:22 | selection of URL : pointer type | TaintedPath.go:16:29:16:40 | tainted_path |
11-
| TaintedPath.go:13:18:13:22 | selection of URL : pointer type | TaintedPath.go:20:28:20:69 | call to Join |
12-
| TaintedPath.go:13:18:13:22 | selection of URL : pointer type | TaintedPath.go:67:28:67:57 | call to Clean |
13-
| TaintedPath.go:13:18:13:22 | selection of URL : pointer type | TaintedPath.go:77:28:77:56 | call to Base |
14-
| tst.go:14:2:14:39 | ... := ...[1] : pointer type | tst.go:17:41:17:56 | selection of Filename |
15-
>>>>>>> a45343fb6c (Add New Sanitizers and Modify Old Ones)
16-
=======
17-
| TaintedPath.go:13:18:13:22 | selection of URL | TaintedPath.go:13:18:13:30 | call to Query |
18-
| TaintedPath.go:13:18:13:30 | call to Query | TaintedPath.go:16:29:16:40 | tainted_path |
19-
| TaintedPath.go:13:18:13:30 | call to Query | TaintedPath.go:20:57:20:68 | tainted_path |
20-
| TaintedPath.go:13:18:13:30 | call to Query | TaintedPath.go:67:39:67:56 | ...+... |
21-
| TaintedPath.go:13:18:13:30 | call to Query | TaintedPath.go:77:38:77:55 | ...+... |
22-
| TaintedPath.go:20:57:20:68 | tainted_path | TaintedPath.go:20:28:20:69 | call to Join |
23-
| TaintedPath.go:67:39:67:56 | ...+... | TaintedPath.go:67:28:67:57 | call to Clean |
24-
| TaintedPath.go:77:38:77:55 | ...+... | TaintedPath.go:77:28:77:56 | call to Base |
25-
>>>>>>> db14838a4f (resolve feedback)
7+
| TaintedPath.go:67:39:67:56 | ...+... | TaintedPath.go:67:28:67:57 | call to Clean | provenance | |
268
nodes
279
| TaintedPath.go:13:18:13:22 | selection of URL | semmle.label | selection of URL |
2810
| TaintedPath.go:13:18:13:30 | call to Query | semmle.label | call to Query |
@@ -31,11 +13,8 @@ nodes
3113
| TaintedPath.go:20:57:20:68 | tainted_path | semmle.label | tainted_path |
3214
| TaintedPath.go:67:28:67:57 | call to Clean | semmle.label | call to Clean |
3315
| TaintedPath.go:67:39:67:56 | ...+... | semmle.label | ...+... |
34-
| TaintedPath.go:77:28:77:56 | call to Base | semmle.label | call to Base |
35-
| TaintedPath.go:77:38:77:55 | ...+... | semmle.label | ...+... |
3616
subpaths
3717
#select
3818
| TaintedPath.go:16:29:16:40 | tainted_path | TaintedPath.go:13:18:13:22 | selection of URL | TaintedPath.go:16:29:16:40 | tainted_path | This path depends on a $@. | TaintedPath.go:13:18:13:22 | selection of URL | user-provided value |
3919
| TaintedPath.go:20:28:20:69 | call to Join | TaintedPath.go:13:18:13:22 | selection of URL | TaintedPath.go:20:28:20:69 | call to Join | This path depends on a $@. | TaintedPath.go:13:18:13:22 | selection of URL | user-provided value |
4020
| TaintedPath.go:67:28:67:57 | call to Clean | TaintedPath.go:13:18:13:22 | selection of URL | TaintedPath.go:67:28:67:57 | call to Clean | This path depends on a $@. | TaintedPath.go:13:18:13:22 | selection of URL | user-provided value |
41-
| TaintedPath.go:77:28:77:56 | call to Base | TaintedPath.go:13:18:13:22 | selection of URL | TaintedPath.go:77:28:77:56 | call to Base | This path depends on a $@. | TaintedPath.go:13:18:13:22 | selection of URL | user-provided value |

go/ql/test/query-tests/Security/CWE-022/TaintedPath.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,6 @@ func handler(w http.ResponseWriter, r *http.Request) {
6767
data, _ = ioutil.ReadFile(path.Clean("/" + tainted_path))
6868
w.Write(data)
6969

70-
// GOOD: Sanitized by filepath.Base with a prepended '/' forcing interpretation
71-
// as an absolute path, so that Base will throw away any leading `..` components.
72-
data, _ = ioutil.ReadFile(filepath.Base("/" + tainted_path))
73-
w.Write(data)
74-
75-
// BAD: Sanitized by path.Base with a prepended '/' forcing interpretation
76-
// as an absolute path, however is not sufficient for Windows paths.
77-
data, _ = ioutil.ReadFile(path.Base("/" + tainted_path))
78-
w.Write(data)
79-
8070
// GOOD: Multipart.Form.FileHeader.Filename sanitized by filepath.Base when calling ParseMultipartForm
8171
r.ParseMultipartForm(32 << 20)
8272
form := r.MultipartForm

0 commit comments

Comments
 (0)