I have an application (Crystal Reports) that inserts a users parameters directly into the query it is running.
The nature of the queries I need to run means I can't change this behaviour.
I've found that this allows users to run any SQL commands they like via the report.
For example, my SQL query is something like:
declare @text varchar(100)
set @text = '{users parameter}'
select *
from blah
where blah.field = @text
-- rest of query
So if a user sets the parameter to '; select * from blah; --
it will run this query.
I am already running the command via a very limited user but still want to try to prevent injections.
Is there any way to prevent or at least mitigate them via the query I am running?
Something like:
declare @text varchar(100)
set @text = NeverEscape('{users parameter}')
select *
from blah
where blah.field = @text
-- rest of query
Edit
To clarify how there is a vulnerability, the application passes a single text query to the server, in the example I gave, the following query would be passed to the server:
declare @text varchar(100)
set @text = ''; select * from blah; --'
select *
from blah
where blah.field = @text
-- rest of query