如果我使用 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/