Skip to content

Commit

Permalink
fixing whitespace secret bug (#590)
Browse files Browse the repository at this point in the history
  • Loading branch information
ecrupper authored Feb 21, 2022
1 parent 5012235 commit a3269dc
Showing 1 changed file with 24 additions and 0 deletions.
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

0 comments on commit a3269dc

Please sign in to comment.