Injection through another procedure
EXEC dbo.build_clause @term, @clause OUTPUT; DECLARE @sql NVARCHAR(800) = N'SELECT * FROM users ' + @clause; EXEC sp_executesql @sql;
Blocked. The version that binds the term as a parameter is allowed.
Without a key: PROC-DYNSQL at high, on the sp_executesql line. Tracing the value through the other procedure, DYNSQL-CONCAT at critical, needs a trial or Team key.
Full SQL, engine output and its safe twin
Injection across a procedure boundary: input flows through an OUTPUT parameter and QUOTENAME() before execution
-- Untrusted @term crosses into build_clause, is wrapped in QUOTENAME()
-- (not a sanitizer in a string-literal context), returned via an OUTPUT
-- parameter, then concatenated and executed back in the caller.
CREATE PROCEDURE dbo.build_clause @raw NVARCHAR(200), @out NVARCHAR(400) OUTPUT
AS
BEGIN
SET @out = N'WHERE name = ''' + QUOTENAME(@raw) + N'''';
END;
GO
CREATE PROCEDURE dbo.run_search @term NVARCHAR(200)
AS
BEGIN
DECLARE @clause NVARCHAR(400);
EXEC dbo.build_clause @term, @clause OUTPUT;
DECLARE @sql NVARCHAR(800) = N'SELECT * FROM users ' + @clause;
EXEC sp_executesql @sql;
END;
GODYNSQL-CONCATDynamic SQL argument is built via string concatenation or FORMAT(...) interpolation. SQL injection risk — switch to a parameterized query (USING clause / sp_executesql parameter binding).
lexega-sql 3.0.0 · mssql · with a key
The same search, parameterized. The helper procedure is gone and the term is bound as an sp_executesql parameter instead of concatenated, so the search is allowed.
-- Identical intent, but @term is bound via sp_executesql parameters -- instead of being concatenated into the statement text. CREATE PROCEDURE dbo.run_search @term NVARCHAR(200) AS BEGIN DECLARE @sql NVARCHAR(800) = N'SELECT * FROM users WHERE name = @p'; EXEC sp_executesql @sql, N'@p NVARCHAR(200)', @p = @term; END; GO
lexega-sql 3.0.0 · mssql · with a key