VeraCode报告ServiceStack OrmLite对SQL命令中使用的特殊元素进行了不适当的中和(';S

本文关键字:不适当 元素 OrmLite ServiceStack 报告 SQL 命令 VeraCode | 更新日期: 2023-09-27 18:28:14

好的,所以我在Web API中使用ServiceStack OrmLite来满足我的数据需求。当我将代码提交给VeraCode进行代码安全扫描和验证时,结果报告显示OrmLite显示了潜在的SQL注入攻击向量。

ServiceStack.OrmLite.dll       GridReader DapperMultiple(System.Data.IDbConnection, string, object, System.Data.IDbTransaction,System.Nullable<int>, System.Nullable<System.Data.CommandType>)
ServiceStack.OrmLite.dll       int ExecuteCommand(System.Data.IDbConnection, System.Data.IDbTransaction, string, System.Action<System.Data.IDbCommand,object>, object, System.Nullable<int>, System.Nullable<System.Data.CommandType>)
ServiceStack.OrmLite.dll       int ExecuteDapper(System.Data.IDbConnection, string, object, System.Data.IDbTransaction, System.Nullable<int>, System.Nullable<System.Data.CommandType>)
ServiceStack.OrmLite.dll       object Scalar(System.Data.IDbCommand, string)
ServiceStack.OrmLite.dll       System.Data.IDataReader ExecReader(System.Data.IDbCommand, string)
ServiceStack.OrmLite.dll       System.Data.IDataReader ExecReader(System.Data.IDbCommand, string, System.Collections.Generic.IEnumerable<System.Data.IDataParameter>)

我不知道该怎么分类。我应该用EntityFramework替换OrmLite吗?

VeraCode报告ServiceStack OrmLite对SQL命令中使用的特殊元素进行了不适当的中和(';S

Eh?所有这些都显示了OrmLite API允许您执行原始SQL字符串吗?最后,每个ORM都将使用ADO.NET的底层API来执行RawSQL。

大多数OrmLite API都是在其值被转义并受到SQL注入攻击保护的情况下类型化的。但由于OrmLite是一个通用的ORM,它还提供了自定义的API,可以让您执行Raw SQL,但即使在这种情况下,您也可以通过使用参数化查询来保护自己免受SQL注入的影响:

自定义SQL API

List<Person> results = db.SqlList<Person>(
    "SELECT * FROM Person WHERE Age < @age", new { age=50});
List<Poco> results = db.SqlList<Poco>(
    "EXEC GetAnalyticsForWeek @weekNo", new { weekNo = 1 });

此外,前几行看起来像是来自Dapper的内部版本,这是另一个Micro ORM,为了方便起见,它嵌入了OrmLite中,但OrmLite本身没有使用。与OrmLite一样,它提供自定义SQL API,还允许您使用参数化参数,并且不受SQL注入攻击。

在使用VeraCode读取代码期间,建议正确的补救措施是用EntityFramework 6.1替换ServiceStack ORM。

这只是对当前存储库模式的一个小更新。