Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion java/ql/lib/semmle/code/java/security/SensitiveActions.qll
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,26 @@ private string nonSuspicious() {
}

/**
* Gets a regular expression for matching common names of variables that indicate the value being held contains sensitive information.
* Gets a regular expression for matching common names of variables that
* indicate the value being held contains sensitive information.
*/
string getCommonSensitiveInfoRegex() {
result = "(?i).*(challenge|pass(wd|word|code|phrase))(?!.*question).*" or
result = "(?i).*(token|secret).*"
}

/**
* Gets a regular expression for matching common names of variables that
* indicate the value being held does not contains sensitive information,
* but is a false positive for `getCommonSensitiveInfoRegex`.
*
* - "tokenizer" is often used for java.util.StringTokenizer.
* - "tokenImage" appears in parser code generated by JavaCC.
*/
string getCommonSensitiveInfoFPRegex() {
result = "(?i).*(null|tokenizer).*" or result = "tokenImage"
}

/** An expression that might contain sensitive data. */
abstract class SensitiveExpr extends Expr { }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ class VariableWithSensitiveName extends Variable {
VariableWithSensitiveName() {
exists(string name | name = this.getName() |
name.regexpMatch(getCommonSensitiveInfoRegex()) and
not name.regexpMatch("(?i).*null.*") and
name != "tokenImage" // appears in parser code generated by JavaCC
not name.regexpMatch(getCommonSensitiveInfoFPRegex())
)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
category: minorAnalysis
---
* Variables names containing the string "tokenizer" (case-insensitively) are no longer sources for the `java/sensitive-log` query. They normally relate to things like `java.util.StringTokenizer`, which are not sensitive information. This should fix some false positive alerts.
19 changes: 2 additions & 17 deletions java/ql/test/query-tests/security/CWE-532/Test.java
Original file line number Diff line number Diff line change
@@ -1,28 +1,13 @@
import org.apache.logging.log4j.Logger;

class Test {
void test(String password) {
void test(String password, String authToken, String username, String nullToken, String stringTokenizer) {
Logger logger = null;

logger.info("User's password is: " + password); // $ hasTaintFlow
}

void test2(String authToken) {
Logger logger = null;

logger.error("Auth failed for: " + authToken); // $ hasTaintFlow
}

void test3(String username) {
Logger logger = null;

logger.error("Auth failed for: " + username); // Safe
}

void test4(String nullToken) {
Logger logger = null;

logger.error("Auth failed for: " + nullToken); // Safe
logger.error("Auth failed for: " + stringTokenizer); // Safe
}

}