Skip to content

Commit

Permalink
Replace manual loop looking for secret related tokens with regex
Browse files Browse the repository at this point in the history
Signed-off-by: Talon Bowler <[email protected]>
  • Loading branch information
daghack committed Jul 2, 2024
1 parent 6e04857 commit 20f4864
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions frontend/dockerfile/dockerfile2llb/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"os"
"path"
"path/filepath"
"regexp"
"runtime"
"sort"
"strconv"
Expand Down Expand Up @@ -2362,14 +2363,10 @@ func validateNoSecretKey(key string, location []parser.Range, lint *linter.Linte
"secret",
"token",
}

keyWords := strings.Split(strings.ToLower(key), "_")
for _, token := range secretTokens {
if token == keyWords[0] || token == keyWords[len(keyWords)-1] {
msg := linter.RuleSecretsUsedInArgOrEnv.Format(key)
lint.Run(&linter.RuleSecretsUsedInArgOrEnv, location, msg)
return
}
pattern := `(?i)(?:_|^)(?:`+strings.Join(secretTokens, "|")+`)(?:_|$)`
if matched, _ := regexp.MatchString(pattern, key); matched {
msg := linter.RuleSecretsUsedInArgOrEnv.Format(key)
lint.Run(&linter.RuleSecretsUsedInArgOrEnv, location, msg)
}
}

Expand Down

0 comments on commit 20f4864

Please sign in to comment.