Skip to content

Commit 03c5efd

Browse files
committed
Code Securty QL
1 parent 1e1aea0 commit 03c5efd

2 files changed

Lines changed: 14 additions & 12 deletions

File tree

.github/codeql/queries/FindHardcodedSecrets.ql

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@ predicate isSecretField(Field f) {
1414
f.getName().regexpMatch("(?i).*(apiKey|token|secret|password|auth)")
1515
}
1616

17-
predicate isSecretValue(string_literal s) {
18-
s.getValue().regexpMatch("(?i)^(sk_.*|token_.*|apikey_.*|[a-zA-Z0-9+/=]{32,})")
17+
predicate isSecretValue(string value) {
18+
value.regexpMatch("(?i)^(sk_.*|token_.*|apikey_.*|[a-zA-Z0-9+/=]{32,})")
1919
}
2020

21-
from Field f, string_literal s
21+
from Field f, Expr::Literal lit
2222
where
2323
isSecretField(f) and
24-
f.getInitializer() = s and
25-
isSecretValue(s)
26-
select s, "Hardcoded secret detected: '" + s.getValue() + "' assigned to field '" + f.getName() + "'"
24+
lit.getType().hasName("string") and
25+
f.getInitializer() = lit and
26+
isSecretValue(lit.getValue())
27+
select lit, "Hardcoded secret detected: '" + lit.getValue() + "' assigned to field '" + f.getName() + "'"

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -501,16 +501,17 @@ predicate isSecretField(Field f) {
501501
f.getName().regexpMatch("(?i).*(apiKey|token|secret|password|auth)")
502502
}
503503
504-
predicate isSecretValue(string_literal s) {
505-
s.getValue().regexpMatch("(?i)^(sk_.*|token_.*|apikey_.*|[a-zA-Z0-9+/=]{32,})")
504+
predicate isSecretValue(string value) {
505+
value.regexpMatch("(?i)^(sk_.*|token_.*|apikey_.*|[a-zA-Z0-9+/=]{32,})")
506506
}
507507
508-
from Field f, string_literal s
508+
from Field f, Expr::Literal lit
509509
where
510510
isSecretField(f) and
511-
f.getInitializer() = s and
512-
isSecretValue(s)
513-
select s, "Hardcoded secret detected: '" + s.getValue() + "' assigned to field '" + f.getName() + "'"
511+
lit.getType().hasName("string") and
512+
f.getInitializer() = lit and
513+
isSecretValue(lit.getValue())
514+
select lit, "Hardcoded secret detected: '" + lit.getValue() + "' assigned to field '" + f.getName() + "'"
514515
515516
```
516517

0 commit comments

Comments
 (0)