forked from zsdlove/Fortify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SQL注入
32 lines (32 loc) · 1.04 KB
/
SQL注入
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
SQL注入,SQL语句中存在用户输入的字符串,且未使用安全的查询方法进行执行SQL语句。
<b>修复建议</b>
使用带占位符的预编译执行方式的SQL语句,并且所有非程序自身的数据都不参与SQL语句的构成。
<b>修复示例</b>
如:
<pre>
public void risk(HttpServletRequest request, Connection c, org.apache.log4j.Logger logger) {
String text = request.getParameter("text");
String sql = "select * from tableName where columnName = '" + text
+ "'";
try {
Statement s = c.createStatement();
s.executeQuery(sql);
} catch (SQLException e) {
logger.warn("Exception", e);
}
}
</pre>
修复为:
<pre>
public void fix(HttpServletRequest request, Connection c, org.apache.log4j.Logger logger) {
String text = request.getParameter("text");
String sql = "select * from tableName where columnName = ?";
try {
PreparedStatement s = c.prepareStatement(sql);
s.setString(1, text);
s.executeQuery();
} catch (SQLException e) {
logger.warn("Exception", e);
}
}
</pre>