1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-27 12:41:57 +03:00

Add a new GUC parameter backslash_quote, which determines whether the SQL

parser will allow "\'" to be used to represent a literal quote mark.  The
"\'" representation has been deprecated for some time in favor of the
SQL-standard representation "''" (two single quote marks), but it has been
used often enough that just disallowing it immediately won't do.  Hence
backslash_quote allows the settings "on", "off", and "safe_encoding",
the last meaning to allow "\'" only if client_encoding is a valid server
encoding.  That is now the default, and the reason is that in encodings
such as SJIS that allow 0x5c (ASCII backslash) to be the last byte of a
multibyte character, accepting "\'" allows SQL-injection attacks as per
CVE-2006-2314 (further details will be published after release).  The
"on" setting is available for backward compatibility, but it must not be
used with clients that are exposed to untrusted input.

Thanks to Akio Ishida and Yasuo Ohgaki for identifying this security issue.
This commit is contained in:
Tom Lane
2006-05-21 20:11:02 +00:00
parent 8fe643b41b
commit 3d4dc1acf5
6 changed files with 99 additions and 11 deletions

View File

@ -1,5 +1,5 @@
<!--
$PostgreSQL: pgsql/doc/src/sgml/config.sgml,v 1.36.2.5 2006/04/18 12:41:29 momjian Exp $
$PostgreSQL: pgsql/doc/src/sgml/config.sgml,v 1.36.2.6 2006/05/21 20:11:02 tgl Exp $
-->
<chapter Id="runtime-config">
<title>Server Configuration</title>
@ -3660,6 +3660,35 @@ dynamic_library_path = 'C:\tools\postgresql;H:\my_project\lib;$libdir'
</listitem>
</varlistentry>
<varlistentry id="guc-backslash-quote" xreflabel="backslash_quote">
<term><varname>backslash_quote</varname> (<type>string</type>)</term>
<indexterm><primary>strings</><secondary>backslash quotes</></>
<indexterm>
<primary><varname>backslash_quote</> configuration parameter</primary>
</indexterm>
<listitem>
<para>
This controls whether a quote mark can be represented by
<literal>\'</> in a string literal. The preferred, SQL-standard way
to represent a quote mark is by doubling it (<literal>''</>) but
<productname>PostgreSQL</> has historically also accepted
<literal>\'</>. However, use of <literal>\'</> creates security risks
because in some client character set encodings, there are multibyte
characters in which the last byte is numerically equivalent to ASCII
<literal>\</>. If client-side code does escaping incorrectly then a
SQL-injection attack is possible. This risk can be prevented by
making the server reject queries in which a quote mark appears to be
escaped by a backslash.
The allowed values of <varname>backslash_quote</> are
<literal>on</> (allow <literal>\'</> always),
<literal>off</> (reject always), and
<literal>safe_encoding</> (allow only if client encoding does not
allow ASCII <literal>\</> within a multibyte character).
<literal>safe_encoding</> is the default setting.
</para>
</listitem>
</varlistentry>
<varlistentry id="guc-default-with-oids" xreflabel="default_with_oids">
<term><varname>default_with_oids</varname> (<type>boolean</type>)</term>
<indexterm>