Skip to content

Commit baee3a3

Browse files
authored
Extendign password variable detection with patterns and antipatterns from C# query (#59)
1 parent 3325cb9 commit baee3a3

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

java/ql/lib/semmle/code/java/security/HardcodedCredentials.qll

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,16 @@ class CredentialsApiSink extends CredentialsSink {
6666
*/
6767
class PasswordVariable extends Variable {
6868
PasswordVariable() {
69-
this.getName().regexpMatch("(?i)(encrypted|old|new)?pass(wd|word|code|phrase)(chars|value)?")
69+
this.getName().regexpMatch("(?i).*pass(w|wd|wrd|word|code|phrase|key|_)(chars|value)?(?!.*(size|length|question|path|prompt)).*") or
70+
this.getName().regexpMatch("(?i)pwd")
7071
}
7172
}
7273

7374
/**
7475
* A variable whose name indicates that it may hold a user name.
7576
*/
7677
class UsernameVariable extends Variable {
77-
UsernameVariable() { this.getName().regexpMatch("(?i)(user|username)") }
78+
UsernameVariable() { this.getName().regexpMatch("(?i)(puid|user|username|userid)(?!.*(characters|claimtype)).*") }
7879
}
7980

8081
/**

java/ql/test/query-tests/security/CWE-798/semmle/tests/Test.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ public static void main(String[] args) throws SQLException {
88
String url = "jdbc:mysql://localhost/test";
99
String usr = "admin"; // hard-coded user name (flow source)
1010
String pass = "123456"; // hard-coded password (flow source)
11+
String pwd = "myPassword"; // hard-coded password (flow source)
1112

1213
test(url, usr, pass); // flow through method
1314

@@ -26,12 +27,18 @@ public static void main(String[] args) throws SQLException {
2627
passwordCheck(pass); // $ HardcodedCredentialsSourceCall
2728
}
2829

29-
public static void test(String url, String user, String password) throws SQLException {
30-
DriverManager.getConnection(url, user, password); // $ HardcodedCredentialsApiCall
30+
public static void test(String url, String user, String v) throws SQLException {
31+
DriverManager.getConnection(url, user, v); // $ HardcodedCredentialsApiCall
3132
}
3233

3334
public static final String password = "myOtherPassword"; // $ HardcodedPasswordField
3435

36+
public static final String pwd = "myOtherPassword"; // $ HardcodedPasswordField
37+
38+
public static final String hard_coded_passphrase_chars = "MyPassPhrase"; // $ HardcodedPasswordField
39+
40+
public static final String password_question = "What is your password?"; // Good: not a password
41+
3542
public static boolean passwordCheck(String password) {
3643
return password.equals("admin"); // $ HardcodedCredentialsComparison
3744
}

0 commit comments

Comments
 (0)