c# - Npgsql run query as readonly -


given user in connection string has write/alter/etc. permissions, there reliable way prevent data modification running user provided query?

using (npgsqltransaction transaction = conn.begintransaction()) {     using (npgsqlcommand setreadonlycommand = new npgsqlcommand("set transaction read only;", conn, transaction))     {         setreadonlycommand.executenonquery();     }      using (npgsqlcommand command = new npgsqlcommand(query, conn, transaction))     {         using (var reader = command.executereader())         {             //... read query results         }     }      transaction.rollback(); } 

the snippet above has 2 safety nets - running in readonly transaction, , rolling transaction @ end.

but both of these can overridden user adding statements "set transaction read write;" , "commit;"

is there more sophisticated way of making sure ad-hoc query won't make changes db?

please note not have access db itself, cannot create sps, roles, etc. solve issue. have in case user specified connection string , user query.


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -