Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix code scanning alert no. 15: Reflected cross-site scripting #466

Merged
merged 4 commits into from
Nov 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions pkg/operator/controllers/allocation_utils.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package controllers

import (
"html"
"net/http"
"regexp"

Expand Down Expand Up @@ -40,26 +41,26 @@ type RequestMultiplayerServerResponse struct {
func internalServerError(w http.ResponseWriter, l logr.Logger, err error, msg string) {
l.Error(err, msg)
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte("500 - " + msg + " " + err.Error()))
w.Write([]byte("500 - " + html.EscapeString(msg) + " " + html.EscapeString(err.Error())))
}

// badRequestError is a helper function for returning a bad request error
func badRequestError(w http.ResponseWriter, l logr.Logger, err error, msg string) {
l.Info(msg)
w.WriteHeader(http.StatusBadRequest)
w.Write([]byte("400 - " + msg + " " + err.Error()))
w.Write([]byte("400 - " + html.EscapeString(msg) + " " + html.EscapeString(err.Error())))
}

// tooManyRequestsError is a helper function for returning a too many requests error
func tooManyRequestsError(w http.ResponseWriter, l logr.Logger, err error, msg string) {
l.Info(msg)
w.WriteHeader(http.StatusTooManyRequests)
w.Write([]byte("429 - " + msg + " " + err.Error()))
w.Write([]byte("429 - " + html.EscapeString(msg) + " " + html.EscapeString(err.Error())))
}

// notFoundError is a helper function for returning a not found error
func notFoundError(w http.ResponseWriter, l logr.Logger, err error, msg string) {
l.Info(msg)
w.WriteHeader(http.StatusNotFound)
w.Write([]byte("404 - " + msg + " " + err.Error()))
w.Write([]byte("404 - " + html.EscapeString(msg) + " " + html.EscapeString(err.Error())))
}
Loading