Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip assessment if environment variable is empty #194

Merged
merged 1 commit into from
Jul 23, 2022
Merged
Show file tree
Hide file tree
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
Skip assessment if environment variable is empty
  • Loading branch information
tomoyamachi committed Jul 23, 2022
commit 36a0d83cdb0191a3749007c7c9c5415f8482b4cb
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