diff --git a/server/web/templatefunc.go b/server/web/templatefunc.go
index f7cce06a..ba2cc543 100644
--- a/server/web/templatefunc.go
+++ b/server/web/templatefunc.go
@@ -314,35 +314,53 @@ func RenderForm(obj interface{}) template.HTML {
// renderFormField returns a string containing HTML of a single form field. In case of select fType, it will retrun
// select tag with options. Value for select fType must be comma separated string which are use are
func renderFormField(label, name, fType string, value interface{}, id string, class string, required bool) string {
+ // Format attributes with spaces first
+ idAttr := ""
if id != "" {
- id = " id=\"" + id + "\""
+ idAttr = " id=\"" + template.HTMLEscapeString(id) + "\""
}
+ classAttr := ""
if class != "" {
- class = " class=\"" + class + "\""
+ classAttr = " class=\"" + template.HTMLEscapeString(class) + "\""
}
- requiredString := ""
+ requiredAttr := ""
if required {
- requiredString = " required"
+ requiredAttr = " required"
+ }
+
+ // Escape all string values
+ escapedName := template.HTMLEscapeString(name)
+ escapedLabel := template.HTMLEscapeString(label)
+ escapedType := template.HTMLEscapeString(fType)
+
+ // Handle value specially as it's an interface{}
+ escapedValue := ""
+ if value != nil {
+ escapedValue = template.HTMLEscapeString(fmt.Sprintf("%v", value))
}
if isValidForInput(fType) {
- return fmt.Sprintf(`%v`, label, id, class, name, fType, value, requiredString)
+ return fmt.Sprintf(`%v`,
+ escapedLabel, idAttr, classAttr, escapedName, escapedType, escapedValue, requiredAttr)
}
if fType == "select" {
- valueStr, ok := value.(string)
+ rawValueStr, ok := value.(string)
if !ok {
logs.Error("for select value must comma separated string that are the options for select")
return ""
}
var selectBuilder strings.Builder
- selectBuilder.WriteString(fmt.Sprintf(`%v