Skip to content

Commit 523f0fb

Browse files
committed
Enhance the query and update qldoc
1 parent d469e9b commit 523f0fb

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<qhelp>
33
<overview>
44
<p>
5-
Storing a plaintext password in a configuration file allows anyone who can read the file to access the password-protected resources. Therefore it is a common attack vector.
5+
Storing a plaintext password in a configuration file allows anyone who can read the file to access the password-protected resources.
66
</p>
77
</overview>
88

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,22 @@ predicate isNotPassword(XMLAttribute a) {
1616
or
1717
a.getValue().regexpMatch("\\$\\{.*\\}") // Variable placeholder ${password}
1818
or
19-
a.getValue().charAt(a.getValue().length() - 1) = "=" // A basic check of encrypted passwords ending with padding characters, which could be improved to be more accurate.
19+
a.getValue().matches("%=") // A basic check of encrypted passwords ending with padding characters, which could be improved to be more accurate.
2020
}
2121

22-
from XMLAttribute a
22+
from XMLAttribute nameAttr
2323
where
24-
a.getName().toLowerCase() in ["password", "pwd"] and not isNotPassword(a) // Attribute name "password" or "pwd"
24+
nameAttr.getName().toLowerCase() in ["password", "pwd"] and not isNotPassword(nameAttr) // Attribute name "password" or "pwd"
2525
or
2626
exists(
27-
XMLAttribute b // name/value pair like <property name="password" value="mysecret"/>
27+
XMLAttribute valueAttr // name/value pair like <property name="password" value="mysecret"/>
2828
|
29-
b.getElement() = a.getElement() and
30-
a.getName().toLowerCase() = "name" and
31-
a.getValue().toLowerCase() in ["password", "pwd"] and
32-
b.getName().toLowerCase() = "value" and
33-
not isNotPassword(b)
29+
valueAttr.getElement() = nameAttr.getElement() and
30+
nameAttr.getName().toLowerCase() = "name" and
31+
nameAttr.getValue().toLowerCase() in ["password", "pwd"] and
32+
valueAttr.getName().toLowerCase() = "value" and
33+
not isNotPassword(valueAttr)
3434
)
3535
or
36-
a.getValue().regexpMatch("(?is).*(pwd|password)\\s*=(?!\\s*;).*") // Attribute value matches password pattern
37-
select a, "Plaintext password in configuration file."
36+
nameAttr.getValue().regexpMatch("(?is).*(pwd|password)\\s*=(?!\\s*;).*") // Attribute value matches password pattern
37+
select nameAttr, "Plaintext password in configuration file."

0 commit comments

Comments
 (0)