Dynamic SQL built with format pastes a value with %s instead of quoting it with %L or %I

tx0/sql:format-unquoted-valuerecommendederrorsecurity/injectiondepth fastsecurity, cwe-89

What it finds

EXECUTE format('SELECT * FROM t WHERE name = ''%s''', name): %s pastes the value as it is, so quotes in it end the literal and the rest runs as SQL. %L quotes a value as a literal and %I a name, which is what format offers dynamic SQL for.

From the rule's source, format_unquoted_value.rs.

Turn it on, off or suppress it

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

tx0.toml
[rules]
"tx0/sql:format-unquoted-value" = "error"

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

tx0 explain tx0/sql:format-unquoted-value shows the same in the terminal. Found a false positive? Report it.