參數化的靜態/代碼SQL語句是否受SQL注入攻擊?代碼/靜態SQL(T-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
您確實應該從DAL中顯示調用代碼(C#或VB)以查看其安全性。 – m4tt1mus 2011-03-29 18:26:59
不幸的是,現有的代碼基於經典的ASP。傳統應用程序的萬歲! – Abe 2011-03-29 18:43:18