防止 SQL 注入使用EXECUTE AS
有人告诉我,防止 SQL 注入的方法之一是在没有登录的情况下创建数据库用户:
CREATE USER User1 WITHOUT LOGIN
Go
GRANT DELETE ON T1 to User1
Go
create proc [dbo].[t1] (@ID INT)
with execute as 'user1'
as
begin
declare @sql as varchar(500)
SET @sql = 'delete from T WHERE ID = @ID'
exec (@sql)
end
我的问题是,由于 User1 没有登录权限,我们如何使用上述程序?