Skip to content

Commit bc9396e

Browse files
author
Max Schaefer
committed
Address suggestions from review.
1 parent 4e4cd52 commit bc9396e

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

go/ql/src/Security/CWE-022/TaintedPath.qhelp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ that the resulting path is still within it.
7272
<sample src="TaintedPathGood2.go" />
7373
<p>
7474
Note that <code>/home/user</code> is just an example, you should replace it with the actual
75-
safe directory in your application.
75+
safe directory in your application. Also, while in this example the path of the safe
76+
directory is absolute, this may not always be the case, and you may need to resolve it
77+
first before checking the input.
7678
</p>
7779
</example>
7880

go/ql/src/Security/CWE-022/TaintedPathGood.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ func handler(w http.ResponseWriter, r *http.Request) {
1111
path := r.URL.Query()["path"][0]
1212

1313
// GOOD: ensure that the filename has no path separators or parent directory references
14+
// (Note that this is only suitable if `path` is expected to have a single component!)
1415
if strings.Contains(path, "/") || strings.Contains(path, "\\") || strings.Contains(path, "..") {
1516
http.Error(w, "Invalid file name", http.StatusBadRequest)
1617
return

0 commit comments

Comments
 (0)