Forbid use of LF and CR characters in database and role names - Mailing list pgsql-hackers

From Michael Paquier
Subject Forbid use of LF and CR characters in database and role names
Date
Msg-id CAB7nPqRbDwmrZW-W6QW6AwiL1WoZJO4XJ-b1+_O4xyy67zn=Fw@mail.gmail.com
Whole thread Raw
Responses Re: Forbid use of LF and CR characters in database and role names  (Michael Paquier <michael.paquier@gmail.com>)
Re: Forbid use of LF and CR characters in database and role names  (Peter Geoghegan <pg@heroku.com>)
Re: Forbid use of LF and CR characters in database and role names  (Peter Eisentraut <peter.eisentraut@2ndquadrant.com>)
Re: Forbid use of LF and CR characters in database and role names  (Peter Eisentraut <peter.eisentraut@2ndquadrant.com>)
List pgsql-hackers
Hi all,

As CVE-2016-5424 has put recently in light, using LF and CR in
database and role names can lead to unexpected problems in the way
they are handled in logical backups or generated command lines. There
is as well a comment in the code mentioning a potential restriction
for that, precisely in fe_utils/string_utils.c:
+ * Forbid LF or CR characters, which have scant practical use beyond designing
+ * security breaches.  The Windows command shell is unusable as a conduit for
+ * arguments containing LF or CR characters.  A future major release should
+ * reject those characters in CREATE ROLE and CREATE DATABASE, because use
+ * there eventually leads to errors here.

Note that pg_dump[all] and pg_upgrade already have safeguards against
those things per the same routines putting quotes for execution as
commands into psql and shell. So attached is a patch to implement this
restriction in the backend, and I am adding that to the next CF for
10.0. Attached is as well a script able to trigger those errors.
Thoughts?
--
Michael

Attachment

pgsql-hackers by date:

Previous
From: Jim Nasby
Date:
Subject: Re: Add hint for function named "is"
Next
From: Craig Ringer
Date:
Subject: [PATCH] COPY vs \copy HINT