Skip to content
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
24 changes: 24 additions & 0 deletions api/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ import (

// CreateSecret represents the API handler to
// create a secret in the configured backend.
//
// nolint: funlen // ignore funlen linter
func CreateSecret(c *gin.Context) {
// capture middleware values
u := user.Retrieve(c)
Expand Down Expand Up @@ -129,6 +131,16 @@ func CreateSecret(c *gin.Context) {
return
}

// reject secrets with solely whitespace characters as its value
trimmed := strings.TrimSpace(input.GetValue())
if len(trimmed) == 0 {
retErr := fmt.Errorf("secret value must contain non-whitespace characters")

util.HandleError(c, http.StatusBadRequest, retErr)

return
}

// update fields in secret object
input.SetOrg(o)
input.SetRepo(n)
Expand Down Expand Up @@ -544,6 +556,8 @@ func GetSecret(c *gin.Context) {
// "$ref": "#/definitions/Error"

// UpdateSecret updates a secret for the provided secrets service.
//
// nolint: funlen // ignore funlen linter
func UpdateSecret(c *gin.Context) {
// capture middleware values
u := user.Retrieve(c)
Expand Down Expand Up @@ -595,6 +609,16 @@ func UpdateSecret(c *gin.Context) {
return
}

// reject secrets with solely whitespace characters as its value
trimmed := strings.TrimSpace(input.GetValue())
if len(trimmed) == 0 {
retErr := fmt.Errorf("secret value must contain non-whitespace characters")

util.HandleError(c, http.StatusBadRequest, retErr)

return
}

// update secret fields if provided
input.SetName(s)
input.SetOrg(o)
Expand Down