下面是下面的伪代码:
public updated(int id) {
// Note that variable **id** is not surrounded by single/double quotes.
sql = "Update table user set status=2 where user_id=**id** ";
// execute command
}
这是否容易受到 SQL 注入(可能是算术 SQL 注入)的影响?
下面是下面的伪代码:
public updated(int id) {
// Note that variable **id** is not surrounded by single/double quotes.
sql = "Update table user set status=2 where user_id=**id** ";
// execute command
}
这是否容易受到 SQL 注入(可能是算术 SQL 注入)的影响?
不,您的查询需要一个整数,并保证得到一个。只有当攻击者可以提供会改变查询的意外数据时,才会出现 SQL 注入漏洞。不同的整数不影响语法。但是,一旦您停止强制执行该类型,它就会变得不安全。
正如@CodesInChaos 所说,如果你是这个片段的作者,你应该考虑使用参数化查询。这样,提供的类型变得无关紧要,更容易审计,更难被意外破坏。
没有已知的通过整数执行 SQL 注入的技术。但请注意,在某些情况下,通过横向 SQL 注入,非整数很容易受到 SQL注入的影响。目前尚不清楚整数是否会永远保持安全。
正如其他答案所提到的 - 即使对数字和日期也使用参数化查询。