Given the following PostgreSQL code, I think that this code is not vulnerable to SQL injection:
_filter 'day'
_start 1
_end 10
_sort 'article_name'
_order 'ASC'
RETURN QUERY EXECUTE '
SELECT *
FROM articles a
WHERE article_name ILIKE ''%' || $1 || '%''
ORDER BY $4 ' || $5 || '
LIMIT ($3-$2) OFFSET $2'
USING _filter, _start, _end, _sort, _order;
But I don't find that much documentation on the USING
clause in combination with strings. I did find this nice article (accepted answer) on DBA: https://dba.stackexchange.com/questions/159424/how-to-use-function-parameters-in-dynamic-sql-with-execute which I think I've implemented correctly