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

Commit bdb3e54

Browse files
committed
Add tests for stdlib-http fields that aren't supposed to cause open-redirect alerts
1 parent b6b7bd2 commit bdb3e54

File tree

1 file changed

+25
-0
lines changed
  • ql/test/query-tests/Security/CWE-601/OpenUrlRedirect

1 file changed

+25
-0
lines changed

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,5 +194,30 @@ func serveStdlib() {
194194
http.Redirect(w, r, target.EscapedPath(), 301)
195195
})
196196

197+
http.HandleFunc("/ex11", func(w http.ResponseWriter, r *http.Request) {
198+
// GOOD: all these fields and methods are disregarded for OpenRedirect attacks:
199+
buf := make([]byte, 100)
200+
r.Body.Read(buf)
201+
http.Redirect(w, r, string(buf), 301)
202+
bodyReader, _ := r.GetBody()
203+
bodyReader.Read(buf)
204+
http.Redirect(w, r, string(buf), 301)
205+
http.Redirect(w, r, r.PostForm["someField"][0], 301)
206+
http.Redirect(w, r, r.MultipartForm.Value["someField"][0], 301)
207+
http.Redirect(w, r, r.Header.Get("someField"), 301)
208+
http.Redirect(w, r, r.Trailer.Get("someField"), 301)
209+
http.Redirect(w, r, r.PostFormValue("someField"), 301)
210+
cookie, _ := r.Cookie("key")
211+
http.Redirect(w, r, cookie.Value, 301)
212+
http.Redirect(w, r, r.Cookies()[0].Value, 301)
213+
http.Redirect(w, r, r.Referer(), 301)
214+
http.Redirect(w, r, r.UserAgent(), 301)
215+
http.Redirect(w, r, r.PostFormValue("target"), 301)
216+
reader, _ := r.MultipartReader()
217+
part, _ := reader.NextPart()
218+
part.Read(buf)
219+
http.Redirect(w, r, string(buf), 301)
220+
})
221+
197222
http.ListenAndServe(":80", nil)
198223
}

0 commit comments

Comments
 (0)