Skip to content

Commit 84f00c2

Browse files
committed
update IfConditionSink.
1 parent 3e376f9 commit 84f00c2

File tree

1 file changed

+48
-46
lines changed

1 file changed

+48
-46
lines changed

java/ql/src/experimental/Security/CWE/CWE-348/UseOfLessTrustedSourceLib.qll

Lines changed: 48 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -38,49 +38,53 @@ private class IfConditionSink extends UseOfLessTrustedSink {
3838
IfConditionSink() {
3939
exists(IfStmt is |
4040
is.getCondition() = this.asExpr() and
41-
not exists(EQExpr eqe |
42-
eqe.getAnOperand() instanceof NullLiteral and
43-
is.getCondition() = eqe.getParent*()
44-
) and
45-
not exists(NEExpr nee |
46-
nee.getAnOperand() instanceof NullLiteral and
47-
is.getCondition() = nee.getParent*()
48-
) and
49-
not exists(MethodAccess ma |
50-
ma.getMethod().hasName("equals") and
51-
ma.getMethod().getNumberOfParameters() = 1 and
52-
(
53-
ma.getQualifier().(CompileTimeConstantExpr).getStringValue() = "" or
54-
ma.getArgument(0).(CompileTimeConstantExpr).getStringValue() = ""
55-
) and
56-
is.getCondition() = ma.getParent*()
57-
) and
58-
not exists(MethodAccess ma |
59-
ma.getMethod().hasName("equalsIgnoreCase") and
60-
ma.getMethod().getNumberOfParameters() = 1 and
61-
(
62-
ma.getQualifier().(CompileTimeConstantExpr).getStringValue() = "unknown" or
63-
ma.getArgument(0).(CompileTimeConstantExpr).getStringValue() = "unknown"
64-
) and
65-
is.getCondition() = ma.getParent*()
66-
) and
67-
not exists(MethodAccess ma |
68-
ma.getMethod().getName() in ["isEmpty", "isNotEmpty"] and
69-
ma.getMethod().getNumberOfParameters() = 1 and
70-
is.getCondition() = ma.getParent*()
71-
) and
72-
not exists(MethodAccess ma |
73-
(
74-
ma.getMethod().hasQualifiedName("org.apache.commons.lang3", "StringUtils", "isBlank") or
75-
ma.getMethod().hasQualifiedName("org.apache.commons.lang3", "StringUtils", "isNotBlank")
76-
) and
77-
is.getCondition() = ma.getParent*()
78-
) and
79-
not exists(MethodAccess ma |
80-
ma.getMethod()
81-
.hasQualifiedName("org.apache.commons.lang3", "StringUtils", "equalsIgnoreCase") and
82-
ma.getAnArgument().(CompileTimeConstantExpr).getStringValue() = "unknown" and
83-
is.getCondition() = ma.getParent*()
41+
(
42+
exists(MethodAccess ma |
43+
ma.getMethod().getName() in ["equals", "equalsIgnoreCase"] and
44+
ma.getMethod().getDeclaringType() instanceof TypeString and
45+
ma.getMethod().getNumberOfParameters() = 1 and
46+
not ma.getQualifier().(CompileTimeConstantExpr).getStringValue().toLowerCase() in [
47+
"", "unknown", ":"
48+
] and
49+
not ma.getArgument(0).(CompileTimeConstantExpr).getStringValue().toLowerCase() in [
50+
"", "unknown", ":"
51+
] and
52+
is.getCondition() = ma.getParent*()
53+
)
54+
or
55+
exists(MethodAccess ma |
56+
ma.getMethod().hasName("contains") and
57+
ma.getMethod().getDeclaringType() instanceof TypeString and
58+
ma.getMethod().getNumberOfParameters() = 1 and
59+
ma.getAnArgument().(CompileTimeConstantExpr).getStringValue().toLowerCase() in [
60+
"", "unknown"
61+
] and
62+
is.getCondition() = ma.getParent*()
63+
)
64+
or
65+
exists(MethodAccess ma |
66+
ma.getMethod().hasName("startsWith") and
67+
ma.getMethod()
68+
.getDeclaringType()
69+
.hasQualifiedName(["org.apache.commons.lang3", "org.apache.commons.lang"],
70+
"StringUtils") and
71+
ma.getMethod().getNumberOfParameters() = 2 and
72+
ma.getAnArgument().(CompileTimeConstantExpr).getStringValue() != "" and
73+
is.getCondition() = ma.getParent*()
74+
)
75+
or
76+
exists(MethodAccess ma |
77+
ma.getMethod().getName() in ["equals", "equalsIgnoreCase"] and
78+
ma.getMethod()
79+
.getDeclaringType()
80+
.hasQualifiedName(["org.apache.commons.lang3", "org.apache.commons.lang"],
81+
"StringUtils") and
82+
ma.getMethod().getNumberOfParameters() = 2 and
83+
not ma.getAnArgument().(CompileTimeConstantExpr).getStringValue().toLowerCase() in [
84+
"", "unknown", ":"
85+
] and
86+
is.getCondition() = ma.getParent*()
87+
)
8488
)
8589
)
8690
}
@@ -101,9 +105,7 @@ private class PrintSink extends UseOfLessTrustedSink {
101105
PrintSink() {
102106
exists(MethodAccess ma |
103107
ma.getMethod().getName() in ["print", "println"] and
104-
(
105-
ma.getMethod().getDeclaringType().hasQualifiedName("java.io", ["PrintWriter", "PrintStream"])
106-
) and
108+
ma.getMethod().getDeclaringType().hasQualifiedName("java.io", ["PrintWriter", "PrintStream"]) and
107109
ma.getAnArgument() = this.asExpr()
108110
)
109111
}

0 commit comments

Comments
 (0)