mirror of
https://github.com/github/codeql.git
synced 2025-12-20 18:56:32 +01:00
28 lines
653 B
Go
28 lines
653 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"html"
|
|
"html/template"
|
|
"net/http"
|
|
)
|
|
|
|
func serve1() {
|
|
var template template.Template
|
|
|
|
http.HandleFunc("/user", func(w http.ResponseWriter, r *http.Request) {
|
|
r.ParseForm()
|
|
username := r.Form.Get("username")
|
|
if !isValidUsername(username) {
|
|
// GOOD: a request parameter is escaped before being put into the response
|
|
fmt.Fprintf(w, "%q is an unknown user", html.EscapeString(username))
|
|
// GOOD: using html/template escapes values for us
|
|
template.Execute(w, username)
|
|
template.ExecuteTemplate(w, "test", username)
|
|
} else {
|
|
// TODO: do something exciting
|
|
}
|
|
})
|
|
http.ListenAndServe(":80", nil)
|
|
}
|