Skip to content

Commit 7b44ee5

Browse files
committed
Revamp the functions to have a string parameter
1 parent b44f01a commit 7b44ee5

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

java/ql/src/experimental/Security/CWE/CWE-555/PasswordInConfigurationFile.ql

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,28 @@
1212
import java
1313

1414
/* 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.
2322
}
2423

2524
/* Holds if the attribute value has an embedded password */
26-
predicate hasEmbeddedPassword(XMLAttribute attr) {
25+
bindingset[value]
26+
predicate hasEmbeddedPassword(string value) {
2727
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)
3430
)
3531
}
3632

3733
from XMLAttribute nameAttr
3834
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"
4037
or
4138
exists(
4239
XMLAttribute valueAttr // name/value pair like <property name="password" value="mysecret"/>
@@ -45,8 +42,8 @@ where
4542
nameAttr.getName().toLowerCase() = "name" and
4643
nameAttr.getValue().toLowerCase() in ["password", "pwd"] and
4744
valueAttr.getName().toLowerCase() = "value" and
48-
not isNotPassword(valueAttr)
45+
not isNotPassword(valueAttr.getValue().trim())
4946
)
5047
or
51-
hasEmbeddedPassword(nameAttr) // Attribute value matches password pattern
48+
hasEmbeddedPassword(nameAttr.getValue().trim()) // Attribute value matches password pattern
5249
select nameAttr, "Plaintext password in configuration file."

0 commit comments

Comments
 (0)