(i) MyBatis injection problem
MyBatis is the most commonly used ORM framework, and generally integrates with the SPRINGMVC framework, but there is a risk of SQL injection for improper use.
The SQL statement in MyBatis Mapper supports two forms of placeholder, one is #{value} and one is ${value}.
When using # for placeholders, such as:
<selectid= "selectusername"resulttype="com.example.bean.Admin">
SELECT * from admin where username= ' #{username} '
</Select>
The internal implementation is using the JDBC precompilation technology:
String sql = "SELECT * from admin where username=?";
Preparedsatement PS = conn.preparestatement (SQL);
Ps.setstring ("admin", username);
However, when using $ for placeholder, the string concatenation is in the internal implementation:
<selectid="Selectusername"resulttype="com.example.bean.Admin">
SELECT * from admin where username= ' ${value} '
</Select>
Code test:
If you use the $ placeholder, there is a risk of SQL injection, which is risky once it is not validated.
Therefore, in the audit, it is generally necessary to see mapper.xml or some of the implementation of the Mapper interface in the annotations in the case of using the $ placeholder, if used, it is a great chance of a problem.
(ii) Hibernet injection problem
Hibernet Framework also supports the case of SQL statement stitching, see the following code:
The input parameter here uses the stitching method into the query, which is obviously problematic and can be brought into single quotes to throw an injection vulnerability.
The safe way is to use placeholders, and then use SETXXX to fill in placeholders, and the internal implementation is based on precompilation, so there is no injection.
(iii) SPRINGMVC Framework XSS problem
SPRINGMVC is not a unified solution for XSS, so looking for code security issues and traditional audit ideas are consistent.
Like what:
When Springmvc and other third-party templates are consolidated, such as with Freemarker, the template does not automatically sanitize the bound data, so there is also an XSS problem.
(iv) Freemarker template injection problem
At present, the more popular freemarker and velocity have template injection vulnerability, which can execute system command or Getshell directly.
SPRINGMVC and Freemarker integration, when the user can control the template file content, including but not limited to editing custom templates, user input stitching in the template string medium:
The code for createhtmlfromstring is to compile the given template string and data, generating HTML for output:
When username is a malicious template syntax, it generates server-side attacks, including but not limited to command execution, Getshell, and so on:
Create a new Freemarkerview, you can refer to
Org.springframework.web.servlet.view.freemarker.FreeMarkerView implementation, and then in the
Add the following two lines of code to the Initapplicationcontext method:
(v) Spring JPA
@Autowired;
Use the Entitymanager to do the original SQL statement stitching.
Read the full text
Java Framework Security