Skip to content

Commit

Permalink
Skip assessment if environment variable is empty (#194)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomoyamachi authored Jul 23, 2022
1 parent d62b963 commit ff13dd0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pkg/assessor/manifest/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,12 @@ func sensitiveVars(cmd string) (bool, string) {
if !strings.Contains(word, "=") {
continue
}
varName := strings.Split(word, "=")[0]
vars := strings.Split(word, "=")
varName, varVal := vars[0], vars[1]
if varVal == "" {
continue
}

if _, ok := acceptanceEnvKey[varName]; ok {
continue
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/assessor/manifest/manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,10 @@ func TestSensitiveVars(t *testing.T) {
expected bool
}{
"basic": {cmd: "/bin/sh -c #(nop) ENV PASS=ADMIN", expected: true},
"empty value": {cmd: "/bin/sh -c #(nop) ENV PASS=", expected: false},
"mixed cases": {cmd: "/bin/sh -c #(nop) ENV PasS=ADMIN", expected: true},
"two vars": {cmd: "/bin/sh -c #(nop) ENV abc=hello password=sensibledata", expected: true},
"empty two value": {cmd: "/bin/sh -c #(nop) ENV ABC=hello PASS= ", expected: false},
"run command": {cmd: `/bin/sh -c SECRET_API_KEY=63AF7AA15067C05616FDDD88A3A2E8F226F0BC06 echo "data"`, expected: true},
"run false positive": {cmd: `/bin/sh -c HELLO="PASS=\"notThis\"" echo "false positive"`, expected: false},
"run command 2": {cmd: `/bin/sh -c SECRET=myLittleSecret VAR2=VALUE2 VAR3=VALUE3 echo "Do something"`, expected: true},
Expand Down

0 comments on commit ff13dd0

Please sign in to comment.