You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: java/ql/src/experimental/Security/CWE/CWE-089/MyBatisAnnotationSqlInjection.qhelp
+6-8Lines changed: 6 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -4,23 +4,21 @@
4
4
"qhelp.dtd">
5
5
<qhelp>
6
6
<overview>
7
-
<p>MyBatis operates the database by using @Select, @Insert, etc. annotations in the method, and can use the $ character
8
-
to construct dynamic SQL statements. Attackers can modify the meaning of statements or execute arbitrary SQL commands.</p>
7
+
<p>MyBatis allows operating the database by annotating a method with the annotations <code>@Select</code>, <code>@Insert</code>, etc. to construct dynamic SQL statements.
8
+
If the syntax `${param}` is used in those statements, and `param` is a parameter of the annotated method, attackers can exploit this to tamper with the SQL statements or execute arbitrary SQL commands.</p>
9
9
</overview>
10
10
11
11
<<recommendation>
12
12
<p>
13
-
When writing MyBatis mapping statements, try to use the format "#{xxx}". If you have to use parameters
14
-
such as "${xxx}", you must manually filter to prevent SQL injection attacks.
13
+
When writing MyBatis mapping statements, try to use the syntax <code>#{xxx}</code>. If the syntax <code>${xxx}</code> must be used, any parameters included in it should be sanitized to prevent SQL injection attacks.
15
14
</p>
16
15
</recommendation>
17
16
18
17
<example>
19
18
<p>
20
-
The following examples show the bad situation and the good situation respectively. The <code>bad1</code> method uses <code>$(name)</code>
21
-
in the <code>@Select</code> annotation to dynamically splice SQL statements, and there is a SQL injection vulnerability.
22
-
The good1 method uses the <code>#{name}</code> method in the <code>@Select</code> annotation to splice SQL statements,
23
-
and the MyBatis framework will handle the dangerous characters entered by the user, And did not cause SQL injection vulnerabilities.
19
+
The following sample shows a bad and a good example of MyBatis annotations usage. The <code>bad1</code> method uses <code>$(name)</code>
20
+
in the <code>@Select</code> annotation to dynamically build a SQL statement, which causes a SQL injection vulnerability.
21
+
The <code>good1</code> method uses <code>#{name}</code> in the <code>@Select</code> annotation to to dynamically include the parameter in a SQL statement, which allows the MyBatis framework to handle the sanitization, preventing the vulnerability.
Copy file name to clipboardExpand all lines: java/ql/src/experimental/Security/CWE/CWE-089/MyBatisMapperXmlSqlInjection.qhelp
+2-3Lines changed: 2 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -9,16 +9,15 @@
9
9
10
10
<<recommendation>
11
11
<p>
12
-
When writing MyBatis mapping statements, try to use the format "#{xxx}". If you have to use parameters
13
-
such as "${xxx}", you must manually filter to prevent SQL injection attacks.
12
+
When writing MyBatis mapping statements, try to use the syntax <code>#{xxx}</code>. If the syntax <code>${xxx}</code> must be used, any parameters included in it should be sanitized to prevent SQL injection attacks.
14
13
</p>
15
14
</recommendation>
16
15
17
16
<example>
18
17
<p>
19
18
The following examples show the bad situation and the good situation respectively. In <code>bad1</code>
20
19
and <code>bad2</code> and <code>bad3</code> and <code>bad4</code> and <code >bad5</code>, the program
21
-
${xxx} are dynamic SQL statements, these five examples of SQL injection vulnerabilities. In <code>good1</code>,
20
+
${xxx} are dynamic SQL statements, these five examples of SQL injection vulnerabilities. In <code>good1</code>,
22
21
the program uses the ${xxx} dynamic feature SQL statement, but there are subtle restrictions on the data,
0 commit comments