• 3 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CodeIgniter 4 Proposed Roadmap

#55
(09-16-2016, 09:13 PM)kilishan Wrote: A lot of people bring up prepared statements as the reason to use. A number of the non-PDO drivers also support that feature so that's kind of a wash.

I'm writing this from PostgreSQL's perspective.

The most important aspect of query parameterization is that if done properly, it prevents SQL injection type of attacks without requiring the developers to reinvent data-sanitizing procedures based on quoting and escaping (either client-side and therefore error-prone or server-side and therefore adding more round trips).

In most DB drivers, query parameterization is implemented either by using server-side prepared statements or by emulating them at client-side by replacing placeholders with their corresponding values. The former is suboptimal most of the time (one command is sent to prepare a statement, one to execute it, and sometimes - like in PDO - another one to deallocate the prepared statement). The latter is just unsafe.

The official Postgres client library, libpq, provides a convenient function PQexecParams(). It issues only one command to a server, sending a query string with placeholders and values separately, so the values will never have a chance to affect how the query is interpreted by the server.

In the reference PHP implementation, PQexecParams() is used internally under the hood of pg_query_params() (unconditionally) and PDOStatement::execute() (conditionally). The condition for PDOStatement::execute() to use PQexecParams() is that the option [PDO::PGSQL_ATTR_DISABLE_PREPARES => true] has to be passed either to PDO::__construct() (making it a per-handle setting) or to PDOStatement::prepare() (making it a one-time setting). By default PGSQL_ATTR_DISABLE_PREPARES is set to false, so PDO will use server-side prepared statements, which is a great feature but only when many executions of the same query with variable parameters are done. Using server-side prepared statements for single query execution is just crippling performance.

By not using pg_query_params() for query parameterization CodeIgniter leaves its users PDO as the only way of having easy, safe and performant protection from SQL injection type of attacks in a CodeIgniter-based application. Which is unfortunate, because PDO itself has the sad restriction that the question mark character is always interpreted as a placeholder, so it's impossible to use it in a query string literally as anything else than a placeholder (as in "SELECT 'a=>1,b=>2'::hstore ?| ARRAY['b','c']", for example). The restriction can be worked around, it probably can be even fixed in PDO, but for the time being, pg_query_params() would be my preference for query parameterization implementation.

To make things worse, when _protect_identifiers is true (the default), CI_DB_query_builder as of version 3 will try to escape string parameters with pg_escape_literal() regardless of whether it's actually needed or not. This adds another unnecessary round trip whenever PQexecParams() is used, because strings can be safely passed verbatim in that case.


Messages In This Thread
CodeIgniter 4 Proposed Roadmap - by kilishan - 08-05-2015, 09:33 AM
RE: CodeIgniter 4 Proposed Roadmap - by skunkbad - 08-05-2015, 10:50 PM
RE: CodeIgniter 4 Proposed Roadmap - by kilishan - 08-05-2015, 11:43 PM
RE: CodeIgniter 4 Proposed Roadmap - by marksman - 06-13-2016, 11:24 AM
RE: CodeIgniter 4 Proposed Roadmap - by kilishan - 08-07-2015, 09:13 PM
RE: CodeIgniter 4 Proposed Roadmap - by sv3tli0 - 08-08-2015, 08:01 AM
RE: CodeIgniter 4 Proposed Roadmap - by akharraz - 08-12-2015, 11:15 AM
RE: CodeIgniter 4 Proposed Roadmap - by peterdenk - 08-13-2015, 04:41 AM
RE: CodeIgniter 4 Proposed Roadmap - by sv3tli0 - 08-16-2015, 12:11 AM
RE: CodeIgniter 4 Proposed Roadmap - by kilishan - 08-16-2015, 08:30 PM
RE: CodeIgniter 4 Proposed Roadmap - by sv3tli0 - 08-16-2015, 10:59 PM
RE: CodeIgniter 4 Proposed Roadmap - by peterdenk - 08-17-2015, 12:49 PM
RE: CodeIgniter 4 Proposed Roadmap - by CroNiX - 08-17-2015, 05:51 PM
RE: CodeIgniter 4 Proposed Roadmap - by apsweb - 08-18-2015, 07:18 PM
RE: CodeIgniter 4 Proposed Roadmap - by peterdenk - 08-19-2015, 04:49 AM
RE: CodeIgniter 4 Proposed Roadmap - by kilishan - 08-19-2015, 08:49 PM
RE: CodeIgniter 4 Proposed Roadmap - by sepehr - 08-29-2015, 03:44 AM
RE: CodeIgniter 4 Proposed Roadmap - by Vimal - 09-01-2015, 06:35 AM
RE: CodeIgniter 4 Proposed Roadmap - by pravmahe - 09-18-2015, 03:09 AM
RE: CodeIgniter 4 Proposed Roadmap - by musheertm - 09-17-2015, 01:31 PM
RE: CodeIgniter 4 Proposed Roadmap - by Muzikant - 09-18-2015, 06:36 AM
RE: CodeIgniter 4 Proposed Roadmap - by ahmed - 10-06-2015, 12:50 PM
RE: CodeIgniter 4 Proposed Roadmap - by condor - 10-12-2015, 12:41 PM
RE: CodeIgniter 4 Proposed Roadmap - by mlantz - 10-26-2015, 12:41 PM
RE: CodeIgniter 4 Proposed Roadmap - by kilishan - 10-26-2015, 01:43 PM
RE: CodeIgniter 4 Proposed Roadmap - by sv3tli0 - 11-30-2015, 02:02 AM
RE: CodeIgniter 4 Proposed Roadmap - by kenjis - 11-30-2015, 02:01 PM
RE: CodeIgniter 4 Proposed Roadmap - by kilishan - 11-30-2015, 09:29 AM
RE: CodeIgniter 4 Proposed Roadmap - by sv3tli0 - 11-30-2015, 11:31 PM
RE: CodeIgniter 4 Proposed Roadmap - by kenjis - 12-02-2015, 12:32 AM
RE: CodeIgniter 4 Proposed Roadmap - by sv3tli0 - 12-02-2015, 01:29 AM
RE: CodeIgniter 4 Proposed Roadmap - by kenjis - 12-02-2015, 02:37 AM
RE: CodeIgniter 4 Proposed Roadmap - by condor - 02-01-2016, 01:51 AM
RE: CodeIgniter 4 Proposed Roadmap - by sv3tli0 - 02-01-2016, 02:24 AM
RE: CodeIgniter 4 Proposed Roadmap - by codenoon - 02-01-2016, 10:50 AM
RE: CodeIgniter 4 Proposed Roadmap - by sv3tli0 - 02-15-2016, 03:43 AM
RE: CodeIgniter 4 Proposed Roadmap - by Mladen - 04-12-2016, 11:38 AM
RE: CodeIgniter 4 Proposed Roadmap - by freebox - 09-03-2016, 05:54 PM
RE: CodeIgniter 4 Proposed Roadmap - by timw4mail - 09-16-2016, 04:13 PM
RE: CodeIgniter 4 Proposed Roadmap - by kilishan - 09-16-2016, 09:13 PM
RE: CodeIgniter 4 Proposed Roadmap - by pstef - 09-17-2016, 01:39 PM
RE: CodeIgniter 4 Proposed Roadmap - by pstef - 09-17-2016, 03:36 PM
RE: CodeIgniter 4 Proposed Roadmap - by kilishan - 09-17-2016, 08:28 PM
RE: CodeIgniter 4 Proposed Roadmap - by pstef - 09-21-2016, 11:03 PM
RE: CodeIgniter 4 Proposed Roadmap - by JayPatel - 03-17-2017, 12:25 AM
RE: CodeIgniter 4 Proposed Roadmap - by kilishan - 02-26-2017, 11:51 PM
RE: CodeIgniter 4 Proposed Roadmap - by ross03 - 03-13-2017, 12:56 AM
RE: CodeIgniter 4 Proposed Roadmap - by sv3tli0 - 03-13-2017, 02:57 AM
RE: CodeIgniter 4 Proposed Roadmap - by kilishan - 03-17-2017, 07:40 AM
RE: CodeIgniter 4 Proposed Roadmap - by bose - 04-21-2017, 11:34 PM
RE: CodeIgniter 4 Proposed Roadmap - by AppJetty - 06-02-2017, 06:07 AM
RE: CodeIgniter 4 Proposed Roadmap - by ardavan - 07-09-2017, 03:53 AM
RE: CodeIgniter 4 Proposed Roadmap - by yuricua - 10-30-2017, 09:42 AM
RE: CodeIgniter 4 Proposed Roadmap - by ciadmin - 10-30-2017, 09:58 AM
RE: CodeIgniter 4 Proposed Roadmap - by ciadmin - 03-23-2018, 05:33 PM
RE: CodeIgniter 4 Proposed Roadmap - by madadi - 04-13-2018, 09:37 PM
RE: CodeIgniter 4 Proposed Roadmap - by goeko77 - 08-20-2018, 01:15 PM
RE: CodeIgniter 4 Proposed Roadmap - by ciadmin - 08-20-2018, 03:44 PM
RE: CodeIgniter 4 Proposed Roadmap - by ciadmin - 09-15-2018, 02:14 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.