Add server-side app name validation (closes #37)
Validate app names in both HandleAppCreate and HandleAppUpdate using a regex pattern matching the client-side HTML pattern: lowercase alphanumeric and hyphens, 2-63 chars, must start and end with alphanumeric character. This prevents Docker API errors, path traversal, and log injection from crafted POST requests bypassing browser validation.
This commit is contained in:
@@ -41,7 +41,7 @@ func (h *Handlers) HandleAppNew() http.HandlerFunc {
|
||||
}
|
||||
|
||||
// HandleAppCreate handles app creation.
|
||||
func (h *Handlers) HandleAppCreate() http.HandlerFunc {
|
||||
func (h *Handlers) HandleAppCreate() http.HandlerFunc { //nolint:funlen // validation adds necessary length
|
||||
tmpl := templates.GetParsed()
|
||||
|
||||
return func(writer http.ResponseWriter, request *http.Request) {
|
||||
@@ -71,6 +71,14 @@ func (h *Handlers) HandleAppCreate() http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
nameErr := validateAppName(name)
|
||||
if nameErr != nil {
|
||||
data["Error"] = "Invalid app name: " + nameErr.Error()
|
||||
_ = tmpl.ExecuteTemplate(writer, "app_new.html", data)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if branch == "" {
|
||||
branch = "main"
|
||||
}
|
||||
@@ -194,7 +202,7 @@ func (h *Handlers) HandleAppEdit() http.HandlerFunc {
|
||||
}
|
||||
|
||||
// HandleAppUpdate handles app updates.
|
||||
func (h *Handlers) HandleAppUpdate() http.HandlerFunc {
|
||||
func (h *Handlers) HandleAppUpdate() http.HandlerFunc { //nolint:funlen // validation adds necessary length
|
||||
tmpl := templates.GetParsed()
|
||||
|
||||
return func(writer http.ResponseWriter, request *http.Request) {
|
||||
@@ -214,7 +222,20 @@ func (h *Handlers) HandleAppUpdate() http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
application.Name = request.FormValue("name")
|
||||
newName := request.FormValue("name")
|
||||
|
||||
nameErr := validateAppName(newName)
|
||||
if nameErr != nil {
|
||||
data := h.addGlobals(map[string]any{
|
||||
"App": application,
|
||||
"Error": "Invalid app name: " + nameErr.Error(),
|
||||
}, request)
|
||||
_ = tmpl.ExecuteTemplate(writer, "app_edit.html", data)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
application.Name = newName
|
||||
application.RepoURL = request.FormValue("repo_url")
|
||||
application.Branch = request.FormValue("branch")
|
||||
application.DockerfilePath = request.FormValue("dockerfile_path")
|
||||
|
||||
Reference in New Issue
Block a user