Home / Learn Secure SQL / Injection Through Stored Procedures: the Concept
Injection Through Stored Procedures: the Concept
A stored procedure is not automatically immune, revisited with the injection lens.
The idea, explained simply
Definition
This lesson revisits the "Stored Procedures Are Not Automatically Safe" idea from the Why hand-built SQL is risky group, specifically through the injection lens: if a stored procedure itself builds a SQL string internally by concatenating one of its own input parameters (rather than using the procedure's safe, built-in parameter binding), the procedure reintroduces exactly the same risk it might otherwise seem to prevent.
Why you need this
Developers sometimes assume "it is in a stored procedure, so it must be safe" — this lesson exists to directly correct that assumption with the specific injection framing, since the misconception is common enough to warrant repeating.
How it works
When reviewing a stored procedure, check whether it uses any form of dynamic SQL construction internally (concatenating its own parameters into a string before executing it); if so, apply the exact same bound-parameter and allowlist rules inside the procedure as you would anywhere else.
Where you'll see this
- Web application code review
- Backend development
- Database administration
-- SQL Server example: even dynamic SQL inside a procedure can bind safely
EXEC sp_executesql N'SELECT * FROM orders WHERE status = @s',
N'@s NVARCHAR(20)', @s = @status;
-- @status is still a bound parameter here, never concatenated into the string.The fix inside a stored procedure is identical in spirit to the fix anywhere else: the procedure's own database engine provides a safe way to use its parameters in dynamic SQL if dynamic SQL is genuinely needed, and that mechanism should always be used instead of string concatenation.
Test what you just read
1. A stored procedure that concatenates its own input parameter into a SQL string...
Being inside a procedure does not itself provide safety.