c# - SQL 注入(inject)攻击和 Subsonic

标签 c# subsonic sql-injection

如果我使用 SubSonic 为我的 Web 项目创建 DAL,我是否需要担心防止 SQL 注入(inject)攻击?

最佳答案

这取决于您构建查询的方式。如果不使用参数,则完全有可能使用 subsonic 编写不安全的查询。

// Bad example:

string sql = "delete from Products where ProductName = " + rawUserInput;
QueryCommand qry = new QueryCommand(sql, Product.Schema.Provider.Name);
DataService.ExecuteQuery(qry);

// Should be:

string sql = "delete from Products where ProductName = @TargetName";
QueryCommand qry = new QueryCommand(sql, Product.Schema.Provider.Name);
qry.AddParamter("@TargetName", rawUserInput, DbType.String);
DataService.ExecuteQuery(qry);

关于c# - SQL 注入(inject)攻击和 Subsonic,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/823821/

相关文章:

php - 如何防止PHP中的SQL注入(inject)?

open-source - SubSonic 的许可证是什么?

asp.net - 哪个.NET对象关系映射器最快?

asp.net-mvc - Visual Web Developer Express 中的 SubSonic ASP.NET MVC 示例

c# - 创建 Visual Studio 模板

mysql - 为什么 SQL 语句产生了语法错误,但 SQL 注入(inject)却成功了?

php - 不太了解SQL注入(inject)

c# - 使用 UI 自动化获取 Firefox URL

c# - 哪个标识符变量更适合作为参数传递给方法?

c# - 当我们创建并启动一个新的 .NET 线程时,它会创建一个新的操作系统级线程吗?