I was hoping to confirm that while SQL injection is possible with dynamic queries that don't use parameterized queries, ownership chains are broken when using the dynamic query, so the only risk would be if that account had more than SELECT permissions on the underlying tables.
For instance, if I had a user called "TestUser" that had db_datareader access to a database (e.g., DatabaseA") and execute permissions on a stored procedure (e.g., spA), it would not be possible for "TestUser" to pass a parameter to spA that could modify any tables in DatabaseA if spA was using only dynamic queries?
Here is an example:
CREATE DATABASE DatabaseA;
CREATE TABLE TableA ( ColumnA VARCHAR(255) )
INSERT INTO TableA VALUES ('ABC');
INSERT INTO TableA VALUES ('DEF');
INSERT INTO TableA VALUES ('GHI');
INSERT INTO TableA VALUES ('JKL');
GRANT SELECT ON OBJECT::dbo.TableA TO [Test\TestUser];
CREATE PROCEDURE spA
EXEC('SELECT * FROM tableA WHERE ColumnA = ''' + @paramA + '''');
GRANT EXECUTE ON dbo.spA TO [Test\TestUser];
Then to test whether or not we can do bad things, I ran this query as Test\TestUser:
EXEC dbo.spA 'ABC'';DROP TABLE TableA;SELECT ''';
I just want to confirm whether or not there is no risk, other than SELECTing data that we've already granted access to. The stored procedure comes from a vendor and it does not use parameterized queries because they have a dynamic list of columns. They do however use only dynamic queries, and their account only has read-only access to the underlying tables and only execute permissions on the stored procedure.
I know that my specific example doesn't work because I do get an error about insufficient permissions, but I just wanted to confirm my understanding that there isn't a risk that I'm unaware of because this is all new to me.