加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

LINQ的ExecuteCommand是否提供SQL注入攻击的保护?

发布时间:2020-12-12 16:12:20 所属栏目:MsSql教程 来源:网络整理
导读:我有一种情况,我需要使用LINQ的ExecuteCommand方法来运行插入. 类似的东西(简化为这个问题的目的): object[] oParams = { Guid.NewGuid(),rec.WebMethodID };TransLogDataContext.ExecuteCommand ("INSERT INTO dbo.Transaction_Log (ID,WebMethodID) VALUE



我有一种情况,我需要使用LINQ的ExecuteCommand方法来运行插入.

类似的东西(简化为这个问题的目的):

object[] oParams = { Guid.NewGuid(),rec.WebMethodID };

TransLogDataContext.ExecuteCommand (
"INSERT INTO dbo.Transaction_Log (ID,WebMethodID) VALUES ({0},{1})",oParams);

问题是如果这是SQL注入证明与参数化查询相同的方式?

解决方法

做了一些研究,我发现这个:

In my simple testing,it looks like
the parameters passed in the
ExecuteQuery and ExecuteCommand
methods are automatically SQL encoded
based on the value being supplied. So
if you pass in a string with a ‘
character,it will automatically SQL
escape it to ”. I believe a similar
policy is used for other data types
like DateTimes,Decimals,etc.

http://weblogs.asp.net/scottgu/archive/2007/08/27/linq-to-sql-part-8-executing-custom-sql-expressions.aspx
(你有滚动的方式找到它)

这似乎对我来说有点奇怪 – 大多数其他的.Net工具比“SQL逃避”更好知道什么;他们使用真正的查询参数.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读