-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Go: Add Tainted Path sanitizers #17759
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d195273
Add mux.Vars() and url.Path sanitizers
Kwstubbs 1287f1b
Address feedback
Kwstubbs 374b13e
Remove path sanitizer
Kwstubbs 8744f15
New tests
Kwstubbs eb3a76d
Merge branch 'github:main' into path-sanitizers
Kwstubbs 460ed30
Fixed tests
Kwstubbs a94ba25
Apply suggestions from code review
Kwstubbs 74f16ee
Merge branch 'main' into path-sanitizers
Kwstubbs 250cbb6
Change location of postprocess queries
owen-mc 347e5ed
Update model in test expectation
owen-mc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| --- | ||
| category: minorAnalysis | ||
| --- | ||
| * Added [github.com/gorilla/mux.Vars](https://pkg.go.dev/github.com/gorilla/mux#Vars) to path sanitizers (disabled if [github.com/gorilla/mix.Router.SkipClean](https://pkg.go.dev/github.com/gorilla/mux#Router.SkipClean) has been called). |
22 changes: 22 additions & 0 deletions
22
go/ql/test/query-tests/Security/CWE-022/GorillaMuxDefault/MuxClean.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "io/ioutil" | ||
| "net/http" | ||
| "path/filepath" | ||
|
|
||
| "github.com/gorilla/mux" | ||
| ) | ||
|
|
||
| // GOOD: Sanitized by Gorilla's cleaner | ||
| func GorillaHandler(w http.ResponseWriter, r *http.Request) { | ||
| not_tainted_path := mux.Vars(r)["id"] | ||
| data, _ := ioutil.ReadFile(filepath.Join("/home/user/", not_tainted_path)) | ||
| w.Write(data) | ||
| } | ||
|
|
||
| func main() { | ||
| var router = mux.NewRouter() | ||
| router.SkipClean(false) | ||
| router.HandleFunc("/{category}", GorillaHandler) | ||
| } |
4 changes: 4 additions & 0 deletions
4
go/ql/test/query-tests/Security/CWE-022/GorillaMuxDefault/TaintedPath.expected
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| edges | ||
| nodes | ||
| subpaths | ||
| #select |
2 changes: 2 additions & 0 deletions
2
go/ql/test/query-tests/Security/CWE-022/GorillaMuxDefault/TaintedPath.qlref
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| query: Security/CWE-022/TaintedPath.ql | ||
| postprocess: utils/test//PrettyPrintModels.ql |
5 changes: 5 additions & 0 deletions
5
go/ql/test/query-tests/Security/CWE-022/GorillaMuxDefault/go.mod
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| module codeql-go-tests/frameworks/Mux | ||
|
|
||
| go 1.14 | ||
|
|
||
| require github.com/gorilla/mux v1.7.4 |
27 changes: 27 additions & 0 deletions
27
...test/query-tests/Security/CWE-022/GorillaMuxDefault/vendor/github.com/gorilla/mux/LICENSE
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
252 changes: 252 additions & 0 deletions
252
...test/query-tests/Security/CWE-022/GorillaMuxDefault/vendor/github.com/gorilla/mux/stub.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
go/ql/test/query-tests/Security/CWE-022/GorillaMuxDefault/vendor/modules.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # github.com/gorilla/mux v1.7.4 | ||
| ## explicit | ||
| github.com/gorilla/mux |
22 changes: 22 additions & 0 deletions
22
go/ql/test/query-tests/Security/CWE-022/GorillaMuxSkipClean/MuxClean.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "io/ioutil" | ||
| "net/http" | ||
| "path/filepath" | ||
|
|
||
| "github.com/gorilla/mux" | ||
| ) | ||
|
|
||
| // BAD: Gorilla's `Vars` is not a sanitizer as `Router.SkipClean` has been called | ||
| func GorillaHandler(w http.ResponseWriter, r *http.Request) { | ||
| not_tainted_path := mux.Vars(r)["id"] | ||
| data, _ := ioutil.ReadFile(filepath.Join("/home/user/", not_tainted_path)) | ||
| w.Write(data) | ||
| } | ||
|
|
||
| func main() { | ||
| var router = mux.NewRouter() | ||
| router.SkipClean(true) | ||
| router.HandleFunc("/{category}", GorillaHandler) | ||
| } |
13 changes: 13 additions & 0 deletions
13
go/ql/test/query-tests/Security/CWE-022/GorillaMuxSkipClean/TaintedPath.expected
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| #select | ||
| | MuxClean.go:14:29:14:74 | call to Join | MuxClean.go:13:22:13:32 | call to Vars | MuxClean.go:14:29:14:74 | call to Join | This path depends on a $@. | MuxClean.go:13:22:13:32 | call to Vars | user-provided value | | ||
| edges | ||
| | MuxClean.go:13:22:13:32 | call to Vars | MuxClean.go:14:58:14:73 | not_tainted_path | provenance | Src:MaD:2 | | ||
| | MuxClean.go:14:58:14:73 | not_tainted_path | MuxClean.go:14:29:14:74 | call to Join | provenance | FunctionModel Sink:MaD:1 | | ||
| models | ||
| | 1 | Sink: io/ioutil; ; false; ReadFile; ; ; Argument[0]; path-injection; manual | | ||
| | 2 | Source: github.com/gorilla/mux; ; true; Vars; ; ; ReturnValue; remote; manual | | ||
| nodes | ||
| | MuxClean.go:13:22:13:32 | call to Vars | semmle.label | call to Vars | | ||
| | MuxClean.go:14:29:14:74 | call to Join | semmle.label | call to Join | | ||
| | MuxClean.go:14:58:14:73 | not_tainted_path | semmle.label | not_tainted_path | | ||
| subpaths | ||
2 changes: 2 additions & 0 deletions
2
go/ql/test/query-tests/Security/CWE-022/GorillaMuxSkipClean/TaintedPath.qlref
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| query: Security/CWE-022/TaintedPath.ql | ||
| postprocess: utils/test//PrettyPrintModels.ql |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.