How does one make the following psql statement sql-injection resilient?

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: How does one make the following psql statement sql-injection resilient?
Date: 2015-03-16 21:30:45
Message-ID: CAKFQuwbxvjF4+Ey5iFK6FdtoU8Z-7o+BmcxgcvB323W_Ev8SBA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

psql "$SERVICE" \
--echo-queries \
--set=string_input="${1:-ok_to_return}" \
--set=start="${2:-5}" \
--set=end="${3:-10}" \
<<'SQL'
SELECT idx
FROM generate_series(1, 20) gs (idx)
WHERE 'short-circuit' != :'string_input'
AND idx BETWEEN :start AND :end;
SQL

# (6 rows)

--set=end="${3:-10 AND false}"

# (0 rows)

Am I forced to represent the input as text (using :'end') and then perform
a conversion to integer?

Thanks!

David J.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Andy Colson 2015-03-16 21:45:51 Re: How does one make the following psql statement sql-injection resilient?
Previous Message Tom Lane 2015-03-16 21:06:36 Re: Slow query with join