Skip to content

Commit

Permalink
fix: issue with accidental secret exposure via wrong syntax (#110)
Browse files Browse the repository at this point in the history
* throw error if no source or target from secret slice

* fmt

* unnecessary leading newline (whitespace)
  • Loading branch information
tvangtarget committed Sep 29, 2020
1 parent 24f0a72 commit 574ca72
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
8 changes: 8 additions & 0 deletions yaml/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package yaml

import (
"errors"
"fmt"
"strings"

"github.com/go-vela/types/constants"
Expand Down Expand Up @@ -206,6 +207,13 @@ func (s *StepSecretSlice) UnmarshalYAML(unmarshal func(interface{}) error) error
// attempt to unmarshal as a step secret slice type
err = unmarshal(secrets)
if err == nil {
// check for secret source and target
for _, secret := range *secrets {
if len(secret.Source) == 0 || len(secret.Target) == 0 {
return fmt.Errorf("no secret source or target found")
}
}

// overwrite existing StepSecretSlice
*s = StepSecretSlice(*secrets)
return nil
Expand Down
10 changes: 10 additions & 0 deletions yaml/secret_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,16 @@ func TestYaml_StepSecretSlice_UnmarshalYAML(t *testing.T) {
},
},
},
{
failure: true,
file: "testdata/step_secret_slice_invalid_no_source.yml",
want: nil,
},
{
failure: true,
file: "testdata/step_secret_slice_invalid_no_target.yml",
want: nil,
},
{
failure: true,
file: "testdata/invalid.yml",
Expand Down
2 changes: 2 additions & 0 deletions yaml/testdata/step_secret_slice_invalid_no_source.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
- target: foo
2 changes: 2 additions & 0 deletions yaml/testdata/step_secret_slice_invalid_no_target.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
- source: foo

0 comments on commit 574ca72

Please sign in to comment.