SqlCommand.Parameters.AddWithValue
方法注入安全吗?
它接受Object
有效载荷,那么它如何防止注入呢?
SqlCommand.Parameters.AddWithValue
方法注入安全吗?
它接受Object
有效载荷,那么它如何防止注入呢?
这实际上取决于您如何使用它们。
看看这里的区别。第一个是安全的,但不是第二个。
sqlCommand.CommandText = "select * from Books where Title = @title";
sqlCommand.Parameters.AddWithValue("title", txtTitle.Text);
string sql = "select * from Books where title = " + txtTitle.Text;
sqlCommand.CommandText = "exec(@sql)";
sqlCommand.Parameters.AddWithValue("sql", sql);
在Does asp.net 防止 sql 注入攻击中查看有关它的更多详细信息