mirror of
https://github.com/github/codeql.git
synced 2026-04-25 00:35:20 +02:00
Add log-injection test using strings.ReplaceAll
This commit is contained in:
@@ -369,3 +369,11 @@ func handlerGood(req *http.Request) {
|
||||
escapedUsername = strings.Replace(escapedUsername, "\r", "", -1)
|
||||
log.Printf("user %s logged in.\n", escapedUsername)
|
||||
}
|
||||
|
||||
// GOOD: The user-provided value is escaped before being written to the log.
|
||||
func handlerGood2(req *http.Request) {
|
||||
username := req.URL.Query()["username"][0]
|
||||
escapedUsername := strings.ReplaceAll(username, "\n", "")
|
||||
escapedUsername = strings.ReplaceAll(escapedUsername, "\r", "")
|
||||
log.Printf("user %s logged in.\n", escapedUsername)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user