sql server - Preventing SQL injection in a report generator with custom formulas -


for customers, building custom report generator, can create own reports.

the concept this: in control table, fill in content of report columns. each column can either consist of data different data sources (=tables), or of formula.

here reduced sample how looks:

column | source  | year   | account | formula ---------------------------------------------- col1   | tab1    | 2015   | sales   | (null) col2   | tab2    | 2014   | sales   | (null) col3   | formula | (null) | (null)  | ([col2]-[col1]) 

so col1 , col2 data tables tab1 , tab2, , col3 calculates difference.

a stored procedure creates dynamic sql, , delivers report data. resulting sql query looks this:

select      (select sum(val) tab1 year=2015 , account='sales') col1,     (select sum(val) tab2 year=2014 , account='sales') col2,     (        (select sum(val) tab1 year=2015 , account='sales')        -         (select sum(val) tab2 year=2014 , account='sales')     ) col3 ; 

in reality far more complex, because there more parameters, , i'm using coalesce(), etc.

my main headache formulas. while give users flexible tool @ hand, total vulnerable sql injections.

just wanted know if there simple way check parameter possible sql injection.

otherwise think need limit flexibility of system normal users, , "super users" access full flexible reports.

not - many injections involve comments (to comment out rest of regulare statment) check comments (-- , /*) , ; sign (end of statment).

on other side if allow users put filters - why should not write filter 1 = (select password users username = 'admin') provoke error message error converting 'reallystrongpassword' integer'?

furthermore guess performance bigger problem injection if see queries (it read tab1 , tab2 twice instead once if write 'regular').

edit: check sql codewords select, update, delete, exec ... in filter parameter, harden code / queries.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -