pg.ddx.io pgsql-jdbc@postgresql.org mailing list archive
help / color / mirror / Atom feedCannot use prepared statements with create user command
2+ messages / 2 participants
[nested] [flat]
* Cannot use prepared statements with create user command
@ 2006-08-23 04:09 Justin Waddell <jwaddell@gmail.com>
0 siblings, 1 reply; 2+ messages in thread
From: Justin Waddell @ 2006-08-23 04:09 UTC (permalink / raw)
To: pgsql-jdbc
To avoid SQL injection attacks I am keen to use prepared statements
for all JDBC calls. However prepared statements do not work with the
CREATE USER command.
I am using the following command:
CREATE USER ? PASSWORD ? CREATEUSER
and then setting the parameters before executing it. This causes the
following exception:
org.postgresql.util.PSQLException: ERROR: syntax error at or near "$1"
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1525)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1309)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:188)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:452)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:354)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:347)
If a prepared statement is not used, then this command is definitely
open to SQL injection attacks - I dropped a database table by using
the following username:
blah;drop table dummy;--
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: Cannot use prepared statements with create user command
@ 2006-08-23 06:31 Oliver Jowett <oliver@opencloud.com>
parent: Justin Waddell <jwaddell@gmail.com>
0 siblings, 0 replies; 2+ messages in thread
From: Oliver Jowett @ 2006-08-23 06:31 UTC (permalink / raw)
To: Justin Waddell <jwaddell@gmail.com>; +Cc: pgsql-jdbc
Justin Waddell wrote:
>> From my research into this problem it seems like prepared statements
> have been deliberately left out of the create user command as they use
> a different type of parameter; this would be fine if the security hole
> wasn't there!
The JDBC driver can only put parameters in where the server-side grammar
allows it (it does not interpolate parameter values into the actual
query, it puts $1,$2,... placeholders in place of the ? placeholders and
passes the actual parameter values out-of-line from the query itself).
If you want to change the grammar, you need to take this up with the
backend developers.. the JDBC driver can't do anything about it.
-O
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2006-08-23 06:31 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2006-08-23 04:09 Cannot use prepared statements with create user command Justin Waddell <jwaddell@gmail.com>
2006-08-23 06:31 ` Oliver Jowett <oliver@opencloud.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox