Skip to content

Commit 8bcbf8e

Browse files
committed
rename isMybatisCollectionTypeSqlInjection
1 parent a18aad8 commit 8bcbf8e

File tree

3 files changed

+6
-36
lines changed

3 files changed

+6
-36
lines changed

java/ql/src/experimental/Security/CWE/CWE-089/MyBatisAnnotationSqlInjection.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ where
5353
unsafeExpression = getAMybatisAnnotationSqlValue(isoa) and
5454
(
5555
isMybatisXmlOrAnnotationSqlInjection(sink.getNode(), ma, unsafeExpression) or
56-
isMybatisAnnotationCollectionTypeSqlInjection(sink.getNode(), ma, unsafeExpression)
56+
isMybatisCollectionTypeSqlInjection(sink.getNode(), ma, unsafeExpression)
5757
)
5858
select sink.getNode(), source, sink,
5959
"MyBatis annotation SQL injection might include code from $@ to $@.", source.getNode(),

java/ql/src/experimental/Security/CWE/CWE-089/MyBatisCommonLib.qll

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ string getAMybatisAnnotationSqlValue(IbatisSqlOperationAnnotation isoa) {
7676

7777
/** Holds if `node` is an argument to `ma` that is vulnerable to SQL injection attacks if `unsafeExpression` occurs in a MyBatis SQL expression. */
7878
bindingset[unsafeExpression]
79-
predicate isMybatisAnnotationCollectionTypeSqlInjection(
79+
predicate isMybatisCollectionTypeSqlInjection(
8080
DataFlow::Node node, MethodAccess ma, string unsafeExpression
8181
) {
8282
not unsafeExpression.regexpMatch("\\$\\{" + getAMybatisConfigurationVariableKey() + "\\}") and
@@ -100,38 +100,6 @@ predicate isMybatisAnnotationCollectionTypeSqlInjection(
100100
)
101101
}
102102

103-
/** Holds if `node` is an argument to `ma` that is vulnerable to SQL injection attacks if `unsafeExpression` occurs in a MyBatis SQL expression. */
104-
bindingset[unsafeExpression]
105-
predicate isMybatisXmlCollectionTypeSqlInjection(
106-
DataFlow::Node node, MethodAccess ma, string unsafeExpression, MyBatisMapperXMLElement mmxe
107-
) {
108-
not unsafeExpression.regexpMatch("\\$\\{" + getAMybatisConfigurationVariableKey() + "\\}") and
109-
// The parameter type of the MyBatis method parameter is Map or List or Array.
110-
// SQL injection vulnerability caused by improper use of this parameter.
111-
// e.g.
112-
//
113-
// ```java
114-
// Test test(Map map);
115-
// <select id="test" resultMap="BaseResultMap">
116-
// select id,name from test where name in
117-
// <foreach collection="list" item="value" open="(" close=")" separator=",">
118-
// ${value}
119-
// </foreach>
120-
// </select>
121-
// ```
122-
exists(int i, MyBatisMapperForeach mbmf |
123-
mbmf = mmxe and
124-
not ma.getMethod().getParameter(i).getAnAnnotation().getType() instanceof TypeParam and
125-
(
126-
ma.getMethod().getParameterType(i) instanceof MapType or
127-
ma.getMethod().getParameterType(i) instanceof ListType or
128-
ma.getMethod().getParameterType(i) instanceof Array
129-
) and
130-
unsafeExpression.matches("${%}") and
131-
ma.getArgument(i) = node.asExpr()
132-
)
133-
}
134-
135103
/** Holds if `node` is an argument to `ma` that is vulnerable to SQL injection attacks if `unsafeExpression` occurs in a MyBatis SQL expression. */
136104
bindingset[unsafeExpression]
137105
predicate isMybatisXmlOrAnnotationSqlInjection(

java/ql/src/experimental/Security/CWE/CWE-089/MyBatisMapperXmlSqlInjection.ql

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,10 @@ where
5252
myBatisMapperXMLElementFromMethod(ma.getMethod(), mmxe) and
5353
unsafeExpression = getAMybatisXmlSetValue(mmxe) and
5454
(
55-
isMybatisXmlOrAnnotationSqlInjection(sink.getNode(), ma, unsafeExpression) or
56-
isMybatisXmlCollectionTypeSqlInjection(sink.getNode(), ma, unsafeExpression, mmxe)
55+
isMybatisXmlOrAnnotationSqlInjection(sink.getNode(), ma, unsafeExpression)
56+
or
57+
mmxe instanceof MyBatisMapperForeach and
58+
isMybatisCollectionTypeSqlInjection(sink.getNode(), ma, unsafeExpression)
5759
)
5860
select sink.getNode(), source, sink,
5961
"MyBatis Mapper XML SQL injection might include code from $@ to $@.", source.getNode(),

0 commit comments

Comments
 (0)