Skip to content

Commit 20f4864

Browse files
committed
Replace manual loop looking for secret related tokens with regex
Signed-off-by: Talon Bowler <[email protected]>
1 parent 6e04857 commit 20f4864

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

frontend/dockerfile/dockerfile2llb/convert.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"os"
1212
"path"
1313
"path/filepath"
14+
"regexp"
1415
"runtime"
1516
"sort"
1617
"strconv"
@@ -2362,14 +2363,10 @@ func validateNoSecretKey(key string, location []parser.Range, lint *linter.Linte
23622363
"secret",
23632364
"token",
23642365
}
2365-
2366-
keyWords := strings.Split(strings.ToLower(key), "_")
2367-
for _, token := range secretTokens {
2368-
if token == keyWords[0] || token == keyWords[len(keyWords)-1] {
2369-
msg := linter.RuleSecretsUsedInArgOrEnv.Format(key)
2370-
lint.Run(&linter.RuleSecretsUsedInArgOrEnv, location, msg)
2371-
return
2372-
}
2366+
pattern := `(?i)(?:_|^)(?:`+strings.Join(secretTokens, "|")+`)(?:_|$)`
2367+
if matched, _ := regexp.MatchString(pattern, key); matched {
2368+
msg := linter.RuleSecretsUsedInArgOrEnv.Format(key)
2369+
lint.Run(&linter.RuleSecretsUsedInArgOrEnv, location, msg)
23732370
}
23742371
}
23752372

0 commit comments

Comments
 (0)