Skip to content

Commit 6d6852f

Browse files
committed
Test PathAssignmentBarrier for OpenUrlRedirect
1 parent f0f5fc7 commit 6d6852f

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
| stdlib.go:198:23:198:42 | call to EscapedPath | stdlib.go:194:36:194:56 | call to FormValue | stdlib.go:198:23:198:42 | call to EscapedPath | This path to an untrusted URL redirection depends on a $@. | stdlib.go:194:36:194:56 | call to FormValue | user-provided value |
1313
| stdlib.go:212:23:212:28 | selection of Path | stdlib.go:210:12:210:30 | call to FormValue | stdlib.go:212:23:212:28 | selection of Path | This path to an untrusted URL redirection depends on a $@. | stdlib.go:210:12:210:30 | call to FormValue | user-provided value |
1414
| stdlib.go:214:23:214:32 | call to String | stdlib.go:210:12:210:30 | call to FormValue | stdlib.go:214:23:214:32 | call to String | This path to an untrusted URL redirection depends on a $@. | stdlib.go:210:12:210:30 | call to FormValue | user-provided value |
15+
| stdlib.go:261:23:261:32 | call to String | stdlib.go:257:12:257:30 | call to FormValue | stdlib.go:261:23:261:32 | call to String | This path to an untrusted URL redirection depends on a $@. | stdlib.go:257:12:257:30 | call to FormValue | user-provided value |
1516
edges
1617
| OpenUrlRedirect.go:10:23:10:28 | selection of Form | OpenUrlRedirect.go:10:23:10:42 | call to Get | provenance | Src:MaD:2 Config Sink:MaD:1 |
1718
| stdlib.go:13:13:13:18 | selection of Form | stdlib.go:13:13:13:32 | call to Get | provenance | Src:MaD:2 Config |
@@ -75,6 +76,19 @@ edges
7576
| stdlib.go:212:23:212:23 | u [postupdate] | stdlib.go:212:23:212:23 | implicit dereference | provenance | Config |
7677
| stdlib.go:212:23:212:23 | u [postupdate] | stdlib.go:214:23:214:23 | u | provenance | |
7778
| stdlib.go:214:23:214:23 | u | stdlib.go:214:23:214:32 | call to String | provenance | Config Sink:MaD:1 |
79+
| stdlib.go:257:3:257:3 | implicit dereference [postupdate] | stdlib.go:257:3:257:3 | u [postupdate] | provenance | Config |
80+
| stdlib.go:257:3:257:3 | implicit dereference [postupdate] | stdlib.go:257:3:257:3 | u [postupdate] [pointer] | provenance | |
81+
| stdlib.go:257:3:257:3 | u [postupdate] | stdlib.go:260:3:260:3 | u | provenance | |
82+
| stdlib.go:257:3:257:3 | u [postupdate] [pointer] | stdlib.go:260:3:260:3 | u [pointer] | provenance | |
83+
| stdlib.go:257:12:257:30 | call to FormValue | stdlib.go:257:3:257:3 | implicit dereference [postupdate] | provenance | Src:MaD:3 Config |
84+
| stdlib.go:257:12:257:30 | call to FormValue | stdlib.go:257:3:257:3 | u [postupdate] | provenance | Src:MaD:3 Config |
85+
| stdlib.go:260:3:260:3 | implicit dereference | stdlib.go:260:3:260:3 | u [postupdate] | provenance | Config |
86+
| stdlib.go:260:3:260:3 | u | stdlib.go:260:3:260:3 | implicit dereference | provenance | Config |
87+
| stdlib.go:260:3:260:3 | u | stdlib.go:261:23:261:23 | u | provenance | |
88+
| stdlib.go:260:3:260:3 | u [pointer] | stdlib.go:260:3:260:3 | implicit dereference | provenance | |
89+
| stdlib.go:260:3:260:3 | u [postupdate] | stdlib.go:260:3:260:3 | implicit dereference | provenance | Config |
90+
| stdlib.go:260:3:260:3 | u [postupdate] | stdlib.go:261:23:261:23 | u | provenance | |
91+
| stdlib.go:261:23:261:23 | u | stdlib.go:261:23:261:32 | call to String | provenance | Config Sink:MaD:1 |
7892
models
7993
| 1 | Sink: net/http; ; false; Redirect; ; ; Argument[2]; url-redirection[0]; manual |
8094
| 2 | Source: net/http; Request; true; Form; ; ; ; remote; manual |
@@ -147,4 +161,14 @@ nodes
147161
| stdlib.go:212:23:212:28 | selection of Path | semmle.label | selection of Path |
148162
| stdlib.go:214:23:214:23 | u | semmle.label | u |
149163
| stdlib.go:214:23:214:32 | call to String | semmle.label | call to String |
164+
| stdlib.go:257:3:257:3 | implicit dereference [postupdate] | semmle.label | implicit dereference [postupdate] |
165+
| stdlib.go:257:3:257:3 | u [postupdate] | semmle.label | u [postupdate] |
166+
| stdlib.go:257:3:257:3 | u [postupdate] [pointer] | semmle.label | u [postupdate] [pointer] |
167+
| stdlib.go:257:12:257:30 | call to FormValue | semmle.label | call to FormValue |
168+
| stdlib.go:260:3:260:3 | implicit dereference | semmle.label | implicit dereference |
169+
| stdlib.go:260:3:260:3 | u | semmle.label | u |
170+
| stdlib.go:260:3:260:3 | u [pointer] | semmle.label | u [pointer] |
171+
| stdlib.go:260:3:260:3 | u [postupdate] | semmle.label | u [postupdate] |
172+
| stdlib.go:261:23:261:23 | u | semmle.label | u |
173+
| stdlib.go:261:23:261:32 | call to String | semmle.label | call to String |
150174
subpaths

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,5 +239,27 @@ func serveStdlib() {
239239
http.Redirect(w, r, string(buf), 301)
240240
})
241241

242+
http.HandleFunc("/ex13", func(w http.ResponseWriter, r *http.Request) {
243+
r.ParseForm()
244+
245+
u, _ := url.Parse("http://example.com")
246+
u.Host = r.FormValue("host")
247+
// GOOD: Path field is assigned a value with a hostname-sanitizing substring,
248+
// so subsequent uses of u are sanitized by PathAssignmentBarrier
249+
u.Path = "/safe/" + r.FormValue("path")
250+
http.Redirect(w, r, u.String(), 301)
251+
})
252+
253+
http.HandleFunc("/ex14", func(w http.ResponseWriter, r *http.Request) {
254+
r.ParseForm()
255+
256+
u, _ := url.Parse("http://example.com")
257+
u.Host = r.FormValue("host") // $ Source
258+
// BAD: Path field is assigned but without a hostname-sanitizing substring,
259+
// so the Host field remains untrusted
260+
u.Path = r.FormValue("path")
261+
http.Redirect(w, r, u.String(), 301) // $ Alert
262+
})
263+
242264
http.ListenAndServe(":80", nil)
243265
}

0 commit comments

Comments
 (0)