@@ -140,6 +140,7 @@ predicate isMybatisXmlOrAnnotationSqlInjection(
140140 )
141141 or
142142 // 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.
143144 // e.g.
144145 //
145146 // ```java
@@ -152,6 +153,8 @@ predicate isMybatisXmlOrAnnotationSqlInjection(
152153 unsafeExpression .matches ( "${param" + ( i + 1 ) + "%}" )
153154 or
154155 unsafeExpression .matches ( "${arg" + i + "%}" )
156+ or
157+ unsafeExpression .matches ( "${" + ma .getMethod ( ) .getParameter ( i ) .getName ( ) + "}" )
155158 ) and
156159 ma .getArgument ( i ) = node .asExpr ( )
157160 )
@@ -185,21 +188,5 @@ predicate isMybatisXmlOrAnnotationSqlInjection(
185188 unsafeExpression .matches ( "${%}" ) and
186189 ma .getAnArgument ( ) = node .asExpr ( )
187190 )
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- )
204191 )
205192}
0 commit comments