@@ -140,6 +140,7 @@ predicate isMybatisXmlOrAnnotationSqlInjection(
140
140
)
141
141
or
142
142
// MyBatis default parameter sql injection vulnerabilities.the default parameter form of the method is arg[0...n] or param[1...n].
143
+ // When compiled with '-parameters' compiler option, the parameter can be reflected in SQL statement as named in method signature.
143
144
// e.g.
144
145
//
145
146
// ```java
@@ -152,6 +153,8 @@ predicate isMybatisXmlOrAnnotationSqlInjection(
152
153
unsafeExpression .matches ( "${param" + ( i + 1 ) + "%}" )
153
154
or
154
155
unsafeExpression .matches ( "${arg" + i + "%}" )
156
+ or
157
+ unsafeExpression .matches ( "${" + ma .getMethod ( ) .getParameter ( i ) .getName ( ) + "}" )
155
158
) and
156
159
ma .getArgument ( i ) = node .asExpr ( )
157
160
)
@@ -185,21 +188,5 @@ predicate isMybatisXmlOrAnnotationSqlInjection(
185
188
unsafeExpression .matches ( "${%}" ) and
186
189
ma .getAnArgument ( ) = node .asExpr ( )
187
190
)
188
- or
189
- // Some of method parameters are not annotated with `@Param`, which named in the SQL statement as their name.
190
- // Improper use of these parameters has a SQL injection vulnerability.
191
- // e.g.
192
- //
193
- // ```java
194
- // @Select(select id,name from test where id = #{id} or name = '${name}')
195
- // Test test(Integer id, String name);
196
- // ```
197
- exists ( Parameter param , int idx |
198
- param = ma .getMethod ( ) .getParameter ( idx )
199
- |
200
- not param .getAnAnnotation ( ) .getType ( ) instanceof TypeParam and
201
- unsafeExpression .matches ( "${" + param .getName ( ) + "}" ) and
202
- ma .getArgument ( idx ) = node .asExpr ( )
203
- )
204
191
)
205
192
}
0 commit comments