I have a following problem/challenge:
Web application (ASP.NET 3.5) installed on corporate LAN and operates on SQL Server DB needs to provide ability to generate custom reports. These reports can be basically anything from underline DB, include complicated joints, unions and whatever you can think of. (Just selects, no Insert/delete/drop/update)
The easiest way to do it – allow to the system to execute SQL queries. System admin will add custom queries to the system and “regular” users will be able to execute them. If they need new query, they will ask Admin to create a query for them and then they will be able to run it by Query ID.
White List approach is not going to work here (at least I can’t see how).
What about black list? I was thinking about something like that:
blackList={"--", ";", "/*", "*/", "@@", "@",
"char", "nchar", "varchar", "nvarchar",
"alter", "begin", "cast", "create", "cursor",
"declare", "delete", "drop", "end", "exec",
"execute", "fetch", "insert", "kill", "open",
"sys", "sysobjects", "syscolumns",
"table", "update"};
Once again – the only person that can create such Custom Query is admin (and he most likely has full control over DB in any case).
Any help would be welcome.
Thanks
A
CAST
and datatypes) which should be allowed, for a variety of reasons. Also, how were you planning on checking the statement for these tokens? Depending on your strategy, the check can either be bypassed, or return a false positive (like if someone has a column namedbegin
that's a timestamp?). You've also eliminated the use of cursors, which are usually used to read data in blocks (a strategy for decreasing application access counts), which feels wrong.