mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
Java: fix 'matches' false branch
This commit is contained in:
@@ -497,9 +497,9 @@ private predicate isMatchesCall(StringMatchesCall matchesCall, Expr checkedExpr,
|
||||
target.getStringValue() = targetValue and
|
||||
checkedExpr = matchesCall.getQualifier()
|
||||
|
|
||||
targetValue.matches(["[%]*", "[%]+", "[%]{%}"]) and
|
||||
(
|
||||
// Allow anything except `.`, '/', '\'
|
||||
targetValue.matches(["[%]*", "[%]+", "[%]{%}"]) and
|
||||
(
|
||||
// Note: we do not account for when '.', '/', '\' are inside a character range
|
||||
not targetValue.matches("[%" + [".", "/", "\\\\\\\\"] + "%]%") and
|
||||
@@ -512,9 +512,10 @@ private predicate isMatchesCall(StringMatchesCall matchesCall, Expr checkedExpr,
|
||||
branch = true
|
||||
or
|
||||
// Disallow `.`, '/', '\'
|
||||
targetValue.matches("[%.%]%") and
|
||||
targetValue.matches("[%/%]%") and
|
||||
targetValue.matches("[%\\\\\\\\%]%") and
|
||||
targetValue.matches([".*[%].*", ".+[%].+"]) and
|
||||
targetValue.matches("%[%.%]%") and
|
||||
targetValue.matches("%[%/%]%") and
|
||||
targetValue.matches("%[%\\\\\\\\%]%") and
|
||||
not targetValue.matches("%[^%]%") and
|
||||
branch = false
|
||||
)
|
||||
|
||||
@@ -684,16 +684,33 @@ public class Test {
|
||||
// branch = false
|
||||
{
|
||||
String source = (String) source();
|
||||
if (source.matches(".*[\\./\\\\].*")) {
|
||||
sink(source); // $ hasTaintFlow
|
||||
} else {
|
||||
sink(source); // Safe
|
||||
}
|
||||
}
|
||||
{
|
||||
String source = (String) source();
|
||||
if (source.matches(".+[\\./\\\\].+")) {
|
||||
sink(source); // $ hasTaintFlow
|
||||
} else {
|
||||
sink(source); // Safe
|
||||
}
|
||||
}
|
||||
{
|
||||
String source = (String) source();
|
||||
// does not match whole string
|
||||
if (source.matches("[\\./\\\\]+")) {
|
||||
sink(source); // $ hasTaintFlow
|
||||
} else {
|
||||
sink(source); // $ Safe
|
||||
sink(source); // $ hasTaintFlow
|
||||
}
|
||||
}
|
||||
{
|
||||
String source = (String) source();
|
||||
// not a complete sanitizer since it doesn't protect against absolute path injection
|
||||
if (source.matches("[\\.]+")) {
|
||||
if (source.matches(".+[\\.].+")) {
|
||||
sink(source); // $ hasTaintFlow
|
||||
} else {
|
||||
sink(source); // $ hasTaintFlow
|
||||
|
||||
Reference in New Issue
Block a user