Entity Framework, LinqToSQL and sql injection

浪子不回头ぞ 提交于 2019-12-06 02:18:04

问题


Is it possible for a project using entirely LinqToSQL or Entity Framewok to suffer from SQL Injection.

I think that probably not because the SQL that the ORM generates should be sql-injection free. But I'm not sure.


回答1:


When you use those frameworks as intended, i.e. the entities/tables directly, then no. All string comparisons (i.e. where name = 'smith' ) are parameterized.

The only vulnerable spots are:

  • any string can be executed directly against the context. dbContext.ExecuteQuery(); with any kind of destructive string.

  • a stored procedure executing dynamic SQL using any parameters given




回答2:


"It depends".

Plain LINQ queries against L2S or EF entities are injection safe, but you could always call a stored procedure or function that is not injection safe.

That would clearly be an edge case, but yes it happens that people write SPs/functions that are open to injection (composing SQL-in-strings with parameter values inside the proc).



来源:https://stackoverflow.com/questions/3473841/entity-framework-linqtosql-and-sql-injection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!