|
13 | 13 | */ |
14 | 14 |
|
15 | 15 | import go |
| 16 | +import semmle.go.security.SensitiveActions |
16 | 17 |
|
17 | 18 | /** |
18 | 19 | * Holds if `sink` is used in a context that suggests it may hold sensitive data of |
19 | 20 | * the given `type`. |
20 | 21 | */ |
21 | | -predicate isSensitive(DataFlow::Node sink, string type) { |
| 22 | +predicate isSensitive(DataFlow::Node sink, SensitiveExpr::Classification type) { |
22 | 23 | exists(Write write, string name | |
23 | 24 | write.getRhs() = sink and |
24 | 25 | name = write.getLhs().getName() and |
25 | 26 | // whitelist obvious test password variables |
26 | | - not name.regexpMatch("(?i)test.*") |
| 27 | + not name.regexpMatch(HeuristicNames::notSensitive()) |
27 | 28 | | |
28 | | - name.regexpMatch("(?i)_*secret") and |
29 | | - type = "secret" |
30 | | - or |
31 | | - name.regexpMatch("(?i)_*(secret|access|private|rsa|aes)_*key") and |
32 | | - type = "key" |
33 | | - or |
34 | | - name.regexpMatch("(?i)_*(encrypted|old|new)?_*pass(wd|word|code|phrase)_*(chars|value)?") and |
35 | | - type = "password" |
| 29 | + name.regexpMatch(HeuristicNames::maybeSensitive(type)) |
36 | 30 | ) |
37 | 31 | } |
38 | 32 |
|
39 | | -from DataFlow::Node source, string message, DataFlow::Node sink, string type |
| 33 | +from DataFlow::Node source, string message, DataFlow::Node sink, SensitiveExpr::Classification type |
40 | 34 | where |
41 | 35 | exists(string val | val = source.getStringValue() and val != "" | |
42 | 36 | isSensitive(sink, type) and |
43 | 37 | DataFlow::localFlow(source, sink) and |
44 | 38 | // whitelist obvious dummy/test values |
45 | | - not val.regexpMatch("(?i)test|password|secret|--- redacted ---") and |
46 | | - not sink.asExpr().(Ident).getName().regexpMatch("(?i)test.*") |
| 39 | + not PasswordHeuristics::isDummyPassword(val) and |
| 40 | + not sink.asExpr().(Ident).getName().regexpMatch(HeuristicNames::notSensitive()) |
47 | 41 | ) and |
48 | 42 | message = "Hard-coded $@." |
49 | 43 | or |
|
52 | 46 | .regexpMatch("(?s)-+BEGIN\\b.*\\bPRIVATE KEY-+.+-+END\\b.*\\bPRIVATE KEY-+\n?") and |
53 | 47 | (source.asExpr() instanceof StringLit or source.asExpr() instanceof AddExpr) and |
54 | 48 | sink = source and |
55 | | - type = "" and |
| 49 | + type = SensitiveExpr::certificate() and |
56 | 50 | message = "Hard-coded private key." |
57 | | -select sink, message, source, type |
| 51 | +select sink, message, source, type.toString() |
0 commit comments