From: Tom Lane <tgl@sss.pgh.pa.us>
To: Stuart McGraw <smcg4191@mtneva.com>
Cc: pgsql-general@postgresql.org <pgsql-general@postgresql.org>
Subject: Re: regex DoS in postgresql?
Date: Sun, 03 Mar 2019 00:05:17 -0500
Message-ID: <8823.1551589517@sss.pgh.pa.us> (raw)
In-Reply-To: <dbc6cd12-8147-a66d-9471-eed4df3a8292@mtneva.com>
References: <dbc6cd12-8147-a66d-9471-eed4df3a8292@mtneva.com>
Stuart McGraw <smcg4191@mtneva.com> writes:
> I would like to deploy a web application with a Postgresql backend
> that allows a user to both add a record containing arbitrary text,
> and to search that text column with an arbitrary regular expression.
> My question is, is the app subject to a regex denial of service attack?
Possibly. We've run into such problems before (eg [1][2][3]), and
generally been able to find mitigations, but I wouldn't promise that
somebody who was intent on making a query run a long time couldn't do so.
However, I don't really think that this is a showstopper reason not to
allow users to give regexp patterns --- just make sure you use a statement
timeout to limit the runtime.
> I would have presumed so but I have been unable produce any problems
> when testing using the "evil" regexs described in the Wikipedia
> article on the subject: https://en.wikipedia.org/wiki/ReDoS
> Is there something in the way Postgresql implements its RE engine
> that makes it immune to this attack?
PG's RE engine is based on Henry Spencer's third regex library (also used
by Tcl), which is quite different from most others out there such as
Perl's. That wikipedia entry doesn't seem to go into much detail, but
I suspect the examples it gives are intended to cause problems for Perl's
engine. Perl's engine does a lot more backtracking than ours does, and
consequently it's easier to send it down the rabbit hole.
regards, tom lane
[1] https://git.postgresql.org/gitweb/?p=postgresql.git&a=commit&h=3bb3f42f3749d40b8d4de65871e8d...
[2] https://git.postgresql.org/gitweb/?p=postgresql.git&a=commit&h=48789c5d23a7f382e3cb721547d5e...
[3] https://git.postgresql.org/gitweb/?p=postgresql.git&a=commit&h=98f27aaef34291246c09ce5d0e0fb...
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: tgl@sss.pgh.pa.us, smcg4191@mtneva.com
Subject: Re: regex DoS in postgresql?
In-Reply-To: <8823.1551589517@sss.pgh.pa.us>
References: <dbc6cd12-8147-a66d-9471-eed4df3a8292@mtneva.com> <8823.1551589517@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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