Re: proof concept: do statement parametrization - Mailing list pgsql-hackers

From Florian Pflug
Subject Re: proof concept: do statement parametrization
Date
Msg-id 308EF99C-0A24-41ED-8E62-E9FD30C2BB32@phlo.org
Whole thread Raw
In response to Re: proof concept: do statement parametrization  (Pavel Stehule <pavel.stehule@gmail.com>)
Responses Re: proof concept: do statement parametrization
List pgsql-hackers
On Jul4, 2010, at 13:57 , Pavel Stehule wrote:
>> I don't really buy that argument. By using a psql variable, you simply move the quoting & escaping business from SQL
tothe shell where psql is called. True, you avoid SQL injectiont, but in turn you make yourself vulnerable to shell
injection.
>
> can you show some example of shell injection? For me, this way via
> psql variables is the best. There are clean interface between outer
> and inner space. And I can call simply just psql scripts - without
> external bash.

Well, on the one hand you have (with your syntax)
echo "DO (a int := $VALUE) $$ ... $$" | psql
which allows sql injection if $VALUE isn't sanitized or quoted & escaped properly.

On the other hand you have
echo "DO (a int := :value) $$ ... $$$ | psql --variable value=$VALUE
which allows at least injection of additional arguments to psql if $VALUE contains spaces. You might try to avoid that
byencoding value=$VALUE in double quotes, but I doubt that it's 100% safe even then. 

The point is that interpolating the value into the command is always risky, independent from whether it's a shell
commandor an sql command. 

best regards,
Florian Pflug



pgsql-hackers by date:

Previous
From: Pavel Stehule
Date:
Subject: Re: proof concept: do statement parametrization
Next
From: Takahiro Itagaki
Date:
Subject: Always truncate segments before unlink