Skip to content
This repository was archived by the owner on Jan 5, 2023. It is now read-only.

Commit 8f0592a

Browse files
author
Max Schaefer
committed
Consider Request.FormValue(...) as a source for URL redirects.
Despite its name, this method doesn't just handle form values but also query parameters.
1 parent 1c5dd51 commit 8f0592a

4 files changed

Lines changed: 14 additions & 1 deletion

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
lgtm,codescanning
2+
* The query "Open URL redirect" (`go/unvalidated-url-redirection`) now recognizes values returned by method `http.Request.FormValue` as possibly user controlled, allowing it to flag more true positive results.

ql/src/semmle/go/security/OpenUrlRedirectCustomizations.qll

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ module OpenUrlRedirect {
5858
|
5959
methName = "Cookie" or
6060
methName = "Cookies" or
61-
methName = "FormValue" or
6261
methName = "MultipartReader" or
6362
methName = "PostFormValues" or
6463
methName = "Referer" or

ql/test/query-tests/Security/CWE-601/OpenUrlRedirect/OpenUrlRedirect.expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ edges
1515
| stdlib.go:146:11:146:15 | selection of URL : pointer type | stdlib.go:149:24:149:35 | call to String |
1616
| stdlib.go:160:35:160:39 | selection of URL : pointer type | stdlib.go:160:24:160:52 | ...+... |
1717
| stdlib.go:160:35:160:39 | selection of URL : pointer type | stdlib.go:160:24:160:52 | ...+... |
18+
| stdlib.go:169:13:169:33 | call to FormValue : string | stdlib.go:171:23:171:28 | target |
1819
nodes
1920
| OpenUrlRedirect.go:10:23:10:28 | selection of Form : Values | semmle.label | selection of Form : Values |
2021
| OpenUrlRedirect.go:10:23:10:42 | call to Get | semmle.label | call to Get |
@@ -44,6 +45,8 @@ nodes
4445
| stdlib.go:160:24:160:52 | ...+... | semmle.label | ...+... |
4546
| stdlib.go:160:35:160:39 | selection of URL : pointer type | semmle.label | selection of URL : pointer type |
4647
| stdlib.go:160:35:160:39 | selection of URL : pointer type | semmle.label | selection of URL : pointer type |
48+
| stdlib.go:169:13:169:33 | call to FormValue : string | semmle.label | call to FormValue : string |
49+
| stdlib.go:171:23:171:28 | target | semmle.label | target |
4750
#select
4851
| OpenUrlRedirect.go:10:23:10:42 | call to Get | OpenUrlRedirect.go:10:23:10:28 | selection of Form : Values | OpenUrlRedirect.go:10:23:10:42 | call to Get | Untrusted URL redirection due to $@. | OpenUrlRedirect.go:10:23:10:28 | selection of Form | user-provided value |
4952
| stdlib.go:14:30:14:35 | target | stdlib.go:12:13:12:18 | selection of Form : Values | stdlib.go:14:30:14:35 | target | Untrusted URL redirection due to $@. | stdlib.go:12:13:12:18 | selection of Form | user-provided value |
@@ -53,3 +56,4 @@ nodes
5356
| stdlib.go:66:23:66:40 | ...+... | stdlib.go:63:13:63:18 | selection of Form : Values | stdlib.go:66:23:66:40 | ...+... | Untrusted URL redirection due to $@. | stdlib.go:63:13:63:18 | selection of Form | user-provided value |
5457
| stdlib.go:91:23:91:28 | target | stdlib.go:88:13:88:18 | selection of Form : Values | stdlib.go:91:23:91:28 | target | Untrusted URL redirection due to $@. | stdlib.go:88:13:88:18 | selection of Form | user-provided value |
5558
| stdlib.go:139:23:139:28 | target | stdlib.go:133:13:133:18 | selection of Form : Values | stdlib.go:139:23:139:28 | target | Untrusted URL redirection due to $@. | stdlib.go:133:13:133:18 | selection of Form | user-provided value |
59+
| stdlib.go:171:23:171:28 | target | stdlib.go:169:13:169:33 | call to FormValue : string | stdlib.go:171:23:171:28 | target | Untrusted URL redirection due to $@. | stdlib.go:169:13:169:33 | call to FormValue | user-provided value |

ql/test/query-tests/Security/CWE-601/OpenUrlRedirect/stdlib.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,5 +163,13 @@ func serveStdlib() {
163163
}
164164
})
165165

166+
http.HandleFunc("/ex9", func(w http.ResponseWriter, r *http.Request) {
167+
r.ParseForm()
168+
169+
target := r.FormValue("target")
170+
// BAD: a request parameter is incorporated without validation into a URL redirect
171+
http.Redirect(w, r, target, 301)
172+
})
173+
166174
http.ListenAndServe(":80", nil)
167175
}

0 commit comments

Comments
 (0)