How to prevent Sql-Injection on User-Generated Sql Queries

前端 未结 15 1950
伪装坚强ぢ
伪装坚强ぢ 2021-02-10 11:55

I have a project (private, ASP.net website, password protected with https) where one of the requirements is that the user be able to enter Sql queries that will directly query t

相关标签:
15条回答
  • 2021-02-10 12:42

    You can do a huge amount of damage with an update statement.

    I had a project similar to this, and our solution was to walk the user through a very annoying wizard allowing them to make the choices, but the query itself is constructed behind the scenes by the application code. Very laborious to create, but at least we were in control of the code that finally executed.

    0 讨论(0)
  • 2021-02-10 12:43

    What you're missing is the ingenuity of an attacker finding holes in your application.

    I can virtually guarantee you that you won't be able to close all the holes if you allow this. There might even be bugs in the database engine you don't know about but they do that allows an SQL statement you deem safe to wreck havoc in your system.

    In short: This is a monumentally bad idea!

    0 讨论(0)
  • 2021-02-10 12:46

    One (maybe overkill) option could be use a compiler for a reduced SQL language. Something like using JavaCC with a modified SQL grammar that only allows SELECT statements, then you might receive the query, compile it and if it compiles you can run it.

    For C# i know Irony but never used it.

    0 讨论(0)
提交回复
热议问题