EXEC runs a string built in a variable instead of sp_executesql with parameters

tx0/sql:exec-string-variablestrictwarningsecurity/injectiondepth fastsecurity, cwe-89

What it finds

EXEC (@sql) runs a string with no way to pass values separately, so every value has to be pasted into it. sp_executesql takes parameters, which keeps values out of the statement text and lets SQL Server reuse the plan.

From the rule's source, exec_string_variable.rs.

Turn it on, off or suppress it

The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/sql:exec-string-variable" = "warning"

To keep one finding, suppress it with a reason: tx0 suppress ID --reason "..." writes the comment for it.

tx0 explain tx0/sql:exec-string-variable shows the same in the terminal. Found a false positive? Report it.