escaping user input

Signed-off-by: GitHub <[email protected]>
This commit is contained in:
Florian Wagner
2022-04-29 04:59:19 +00:00
committed by GitHub
parent 9f2780c5e5
commit c972445c27
+6 -5
View File
@@ -4,6 +4,7 @@ import (
"encoding/json" "encoding/json"
"flag" "flag"
"fmt" "fmt"
"html"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"path" "path"
@@ -50,7 +51,7 @@ func main() {
if orgReq.Login == authenticatedLogin { if orgReq.Login == authenticatedLogin {
w.WriteHeader(http.StatusUnprocessableEntity) w.WriteHeader(http.StatusUnprocessableEntity)
_, err := w.Write([]byte(fmt.Sprintf("%s is a user, not an organization", orgReq.Login))) _, err := w.Write([]byte(fmt.Sprintf("%s is a user, not an organization", html.EscapeString(orgReq.Login))))
if err != nil { if err != nil {
panic(err) panic(err)
} }
@@ -58,7 +59,7 @@ func main() {
if orgReq.Login == existingOrg { if orgReq.Login == existingOrg {
w.WriteHeader(http.StatusUnprocessableEntity) w.WriteHeader(http.StatusUnprocessableEntity)
_, err := w.Write([]byte(fmt.Sprintf("Organization %s already exists", orgReq.Login))) _, err := w.Write([]byte(fmt.Sprintf("Organization %s already exists", html.EscapeString(orgReq.Login))))
if err != nil { if err != nil {
panic(err) panic(err)
} }
@@ -77,7 +78,7 @@ func main() {
if orgName != existingOrg { if orgName != existingOrg {
w.WriteHeader(http.StatusNotFound) w.WriteHeader(http.StatusNotFound)
_, err := w.Write([]byte(fmt.Sprintf("Organization %s not found", orgName))) _, err := w.Write([]byte(fmt.Sprintf("Organization %s not found", html.EscapeString(orgName))))
if err != nil { if err != nil {
panic(err) panic(err)
} }
@@ -107,7 +108,7 @@ func main() {
if repoReq.Name == "repo-already-exists" { if repoReq.Name == "repo-already-exists" {
w.WriteHeader(http.StatusUnprocessableEntity) w.WriteHeader(http.StatusUnprocessableEntity)
_, err := w.Write([]byte(fmt.Sprintf("Repo %s already exists", repoReq.Name))) _, err := w.Write([]byte(fmt.Sprintf("Repo %s already exists", html.EscapeString(repoReq.Name))))
if err != nil { if err != nil {
panic(err) panic(err)
} }
@@ -137,7 +138,7 @@ func main() {
if repoReq.Name == existingRepo { if repoReq.Name == existingRepo {
w.WriteHeader(http.StatusUnprocessableEntity) w.WriteHeader(http.StatusUnprocessableEntity)
_, err := w.Write([]byte(fmt.Sprintf("Repo %s already exists", repoReq.Name))) _, err := w.Write([]byte(fmt.Sprintf("Repo %s already exists", html.EscapeString(repoReq.Name))))
if err != nil { if err != nil {
panic(err) panic(err)
} }