Skip to content

Commit b44f01a

Browse files
committed
Enhance the check for embedded passwords
1 parent 523f0fb commit b44f01a

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

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

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,27 @@
1111

1212
import java
1313

14-
predicate isNotPassword(XMLAttribute a) {
15-
a.getValue() = "" // Empty string
16-
or
17-
a.getValue().regexpMatch("\\$\\{.*\\}") // Variable placeholder ${password}
18-
or
19-
a.getValue().matches("%=") // A basic check of encrypted passwords ending with padding characters, which could be improved to be more accurate.
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+
)
23+
}
24+
25+
/* Holds if the attribute value has an embedded password */
26+
predicate hasEmbeddedPassword(XMLAttribute attr) {
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+
)
34+
)
2035
}
2136

2237
from XMLAttribute nameAttr
@@ -33,5 +48,5 @@ where
3348
not isNotPassword(valueAttr)
3449
)
3550
or
36-
nameAttr.getValue().regexpMatch("(?is).*(pwd|password)\\s*=(?!\\s*;).*") // Attribute value matches password pattern
51+
hasEmbeddedPassword(nameAttr) // Attribute value matches password pattern
3752
select nameAttr, "Plaintext password in configuration file."
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
| applicationContext.xml:9:3:9:48 | name=password | Plaintext password in configuration file. |
22
| context.xml:4:2:8:50 | password=1234 | Plaintext password in configuration file. |
3+
| custom-config.xml:3:2:3:137 | value=server=myoracle.example.com;port=1521;database=testdb;username=root;password=test1234 | Plaintext password in configuration file. |
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<db-connections>
3+
<db-connection name="oracleServerConn" value="server=myoracle.example.com;port=1521;database=testdb;username=root;password=test1234" />
4+
</db-connections>

0 commit comments

Comments
 (0)