参数化的静态/代码SQL语句是否会受到SQL注入攻击?
例如,假设我有以下简化存储过程:如果输入@PSeries_desc是参数化的,那么它是否意味着受到注入攻击?以前,这是一个动态SQL语句,代码是使用exec (而不是sp_executesql )执行的,因此,它肯定会受到攻击。
CREATE procedure get_product_by_title
@PSearchType int = NULL
, @Pseries_desc varchar(40) = NULL
as
begin
declare
@whereLikeBeg varchar(1)
, @whereLikeEnd varchar(1)
set @whereLikeBeg = ''
set @whereLikeEnd = ''
if @search_code = 'contains'
begin
set @whereLikeBeg = '%'
set @whereLikeEnd = '%'
end
if @search_code = 'starts_with'
begin
set @whereLikeEnd = '%'
end
select
distinct B.parent_product_id
, B.parent_product_id
from
tableA
where
parent_product_id = child_product_id
and product_title like @whereLikeBeg + @Pseries_desc + @whereLikeEnd
end发布于 2011-03-29 18:17:09
在我看来这个密码很安全..。
参数化查询并不是保护自己免受SQL注入攻击的唯一方法,但它可能是最简单和最安全的方法。
即使您忘记了SQL注入攻击,动态构建查询也不是一个好做法,特别是当您使用字符串时,因为它们可能包含对查询有影响的SQL保留字/字符。
发布于 2011-03-29 18:17:53
如果在访问代码中使用参数化查询,则不需要担心。在存储过程中检查它是不正确的。
https://stackoverflow.com/questions/5476870
复制相似问题