|
12 | 12 | import java |
13 | 13 |
|
14 | 14 | /* Holds if the attribute value is not a cleartext password */ |
15 | | -predicate isNotPassword(XMLAttribute attr) { |
16 | | - exists(string value | value = attr.getValue().trim() | |
17 | | - value = "" // Empty string |
18 | | - or |
19 | | - value.regexpMatch("\\$\\{.*\\}") // Variable placeholder ${password} |
20 | | - or |
21 | | - value.matches("%=") // A basic check of encrypted passwords ending with padding characters, which could be improved to be more accurate. |
22 | | - ) |
| 15 | +bindingset[value] |
| 16 | +predicate isNotPassword(string value) { |
| 17 | + value = "" // Empty string |
| 18 | + or |
| 19 | + value.regexpMatch("\\$\\{.*\\}") // Variable placeholder ${password} |
| 20 | + or |
| 21 | + value.matches("%=") // A basic check of encrypted passwords ending with padding characters, which could be improved to be more accurate. |
23 | 22 | } |
24 | 23 |
|
25 | 24 | /* Holds if the attribute value has an embedded password */ |
26 | | -predicate hasEmbeddedPassword(XMLAttribute attr) { |
| 25 | +bindingset[value] |
| 26 | +predicate hasEmbeddedPassword(string value) { |
27 | 27 | exists(string password | |
28 | | - password = attr.getValue().regexpCapture("(?is).*(pwd|password)\\s*=([^;:,]*).*", 2).trim() and |
29 | | - not ( |
30 | | - password = "" or |
31 | | - password.regexpMatch("\\$\\{.*\\}") or |
32 | | - password.matches("%=") |
33 | | - ) |
| 28 | + password = value.regexpCapture("(?is).*(pwd|password)\\s*=([^;:,]*).*", 2).trim() and |
| 29 | + not isNotPassword(password) |
34 | 30 | ) |
35 | 31 | } |
36 | 32 |
|
37 | 33 | from XMLAttribute nameAttr |
38 | 34 | where |
39 | | - nameAttr.getName().toLowerCase() in ["password", "pwd"] and not isNotPassword(nameAttr) // Attribute name "password" or "pwd" |
| 35 | + nameAttr.getName().toLowerCase() in ["password", "pwd"] and |
| 36 | + not isNotPassword(nameAttr.getValue().trim()) // Attribute name "password" or "pwd" |
40 | 37 | or |
41 | 38 | exists( |
42 | 39 | XMLAttribute valueAttr // name/value pair like <property name="password" value="mysecret"/> |
|
45 | 42 | nameAttr.getName().toLowerCase() = "name" and |
46 | 43 | nameAttr.getValue().toLowerCase() in ["password", "pwd"] and |
47 | 44 | valueAttr.getName().toLowerCase() = "value" and |
48 | | - not isNotPassword(valueAttr) |
| 45 | + not isNotPassword(valueAttr.getValue().trim()) |
49 | 46 | ) |
50 | 47 | or |
51 | | - hasEmbeddedPassword(nameAttr) // Attribute value matches password pattern |
| 48 | + hasEmbeddedPassword(nameAttr.getValue().trim()) // Attribute value matches password pattern |
52 | 49 | select nameAttr, "Plaintext password in configuration file." |
0 commit comments