<s>
is	O
an	O
algorithmic	B-General_Concept
complexity	I-General_Concept
attack	I-General_Concept
that	O
produces	O
a	O
denial-of-service	O
by	O
providing	O
a	O
regular	B-Language
expression	I-Language
and/or	O
an	O
input	O
that	O
takes	O
a	O
long	O
time	O
to	O
evaluate	O
.	O
</s>
<s>
The	O
attack	O
exploits	O
the	O
fact	O
that	O
many	O
regular	B-Language
expression	I-Language
implementations	O
have	O
super-linear	O
worst-case	B-General_Concept
complexity	I-General_Concept
;	O
on	O
certain	O
regex-input	O
pairs	O
,	O
the	O
time	O
taken	O
can	O
grow	O
polynomially	O
or	O
exponentially	O
in	O
relation	O
to	O
the	O
input	O
size	O
.	O
</s>
<s>
An	O
attacker	O
can	O
thus	O
cause	O
a	O
program	O
to	O
spend	O
substantial	O
time	O
by	O
providing	O
a	O
specially	O
crafted	O
regular	B-Language
expression	I-Language
and/or	O
input	O
.	O
</s>
<s>
Regular	B-Language
expression	I-Language
(	O
"	O
regex	B-Language
"	O
)	O
matching	O
can	O
be	O
done	O
by	O
building	O
a	O
finite-state	B-Architecture
automaton	I-Architecture
.	O
</s>
<s>
Regex	B-Language
can	O
be	O
easily	O
converted	O
to	O
nondeterministic	B-General_Concept
automata	I-General_Concept
(	O
NFAs	O
)	O
,	O
in	O
which	O
for	O
each	O
state	O
and	O
input	O
symbol	O
,	O
there	O
may	O
be	O
several	O
possible	O
next	O
states	O
.	O
</s>
<s>
the	O
engine	O
may	O
convert	O
it	O
to	O
a	O
deterministic	O
finite-state	B-Architecture
automaton	I-Architecture
(	O
DFA	B-General_Concept
)	O
and	O
run	O
the	O
input	O
through	O
the	O
result	O
;	O
</s>
<s>
the	O
engine	O
may	O
convert	O
the	O
nondeterministic	O
automaton	O
to	O
a	O
DFA	B-General_Concept
lazily	O
(	O
i.e.	O
,	O
on	O
the	O
fly	O
,	O
during	O
the	O
match	O
)	O
.	O
</s>
<s>
The	O
first	O
is	O
problematic	O
because	O
a	O
deterministic	O
automaton	O
could	O
have	O
up	O
to	O
states	O
where	O
is	O
the	O
number	O
of	O
states	O
in	O
the	O
nondeterministic	O
automaton	O
;	O
thus	O
,	O
the	O
conversion	O
from	O
NFA	O
to	O
DFA	B-General_Concept
may	O
take	O
exponential	O
time	O
.	O
</s>
<s>
Note	O
that	O
for	O
non-pathological	O
regular	B-Language
expressions	I-Language
,	O
the	O
problematic	O
algorithms	O
are	O
usually	O
fast	O
,	O
and	O
in	O
practice	O
,	O
one	O
can	O
expect	O
them	O
to	O
"	O
compile	B-Language
"	O
a	O
regex	B-Language
in	O
O(m )	O
time	O
and	O
match	O
it	O
in	O
O(n )	O
time	O
;	O
instead	O
,	O
simulation	O
of	O
an	O
NFA	O
and	O
lazy	O
computation	O
of	O
the	O
DFA	B-General_Concept
have	O
O(m2n )	O
worst-case	B-General_Concept
complexity	I-General_Concept
.	O
</s>
<s>
Regex	B-Language
denial	O
of	O
service	O
occurs	O
when	O
these	O
expectations	O
are	O
applied	O
to	O
a	O
regex	B-Language
provided	O
by	O
the	O
user	O
,	O
and	O
malicious	O
regular	B-Language
expressions	I-Language
provided	O
by	O
the	O
user	O
trigger	O
the	O
worst-case	B-General_Concept
complexity	I-General_Concept
of	O
the	O
regex	B-Language
matcher	O
.	O
</s>
<s>
While	O
regex	B-Language
algorithms	O
can	O
be	O
written	O
in	O
an	O
efficient	O
way	O
,	O
most	O
regex	B-Language
engines	O
in	O
existence	O
extend	O
the	O
regex	B-Language
languages	O
with	O
additional	O
constructs	O
that	O
cannot	O
always	O
be	O
solved	O
efficiently	O
.	O
</s>
<s>
Such	O
extended	O
patterns	O
essentially	O
force	O
the	O
implementation	O
of	O
regex	B-Language
in	O
most	O
programming	O
languages	O
to	O
use	O
backtracking	O
.	O
</s>
<s>
The	O
most	O
severe	O
type	O
of	O
problem	O
happens	O
with	O
backtracking	O
regular	B-Language
expression	I-Language
matches	O
,	O
where	O
some	O
patterns	O
have	O
a	O
runtime	O
that	O
is	O
exponential	O
in	O
the	O
length	O
of	O
the	O
input	O
string	O
.	O
</s>
<s>
This	O
happens	O
when	O
a	O
regular	B-Language
expression	I-Language
has	O
three	O
properties	O
:	O
</s>
<s>
the	O
regular	B-Language
expression	I-Language
applies	O
repetition	O
( +	O
,	O
*	O
)	O
to	O
a	O
subexpression	O
;	O
</s>
<s>
All	O
three	O
of	O
the	O
above	O
regular	B-Language
expressions	I-Language
will	O
exhibit	O
exponential	O
runtime	O
when	O
applied	O
to	O
strings	O
of	O
the	O
form	O
.	O
</s>
<s>
So-called	O
"	O
evil	O
"	O
or	O
vulnerable	O
regexes	B-Language
have	O
been	O
found	O
in	O
online	O
regular	B-Language
expression	I-Language
repositories	O
.	O
</s>
<s>
Note	O
that	O
it	O
is	O
enough	O
to	O
find	O
a	O
vulnerable	O
subexpression	O
in	O
order	O
to	O
attack	O
the	O
full	O
regex	B-Language
:	O
</s>
<s>
If	O
the	O
regex	B-Language
itself	O
is	O
affected	O
by	O
user	O
input	O
,	O
such	O
as	O
a	O
web	O
service	O
permitting	O
clients	O
to	O
provide	O
a	O
search	O
pattern	O
,	O
then	O
an	O
attacker	O
can	O
inject	O
a	O
malicious	O
regex	B-Language
to	O
consume	O
the	O
server	O
's	O
resources	O
.	O
</s>
<s>
Therefore	O
,	O
in	O
most	O
cases	O
,	O
regular	B-Algorithm
expression	I-Algorithm
denial	I-Algorithm
of	I-Algorithm
service	I-Algorithm
can	O
be	O
avoided	O
by	O
removing	O
the	O
possibility	O
for	O
the	O
user	O
to	O
execute	O
arbitrary	O
patterns	O
on	O
the	O
server	O
.	O
</s>
<s>
However	O
,	O
if	O
a	O
vulnerable	O
regex	B-Language
exists	O
on	O
the	O
server-side	O
already	O
,	O
then	O
an	O
attacker	O
may	O
instead	O
be	O
able	O
to	O
provide	O
an	O
input	O
that	O
triggers	O
its	O
worst-case	O
behavior	O
.	O
</s>
<s>
Fortunately	O
,	O
in	O
most	O
cases	O
,	O
the	O
problematic	O
regular	B-Language
expressions	I-Language
can	O
be	O
rewritten	O
as	O
"	O
non-evil	O
"	O
patterns	O
.	O
</s>
<s>
In	O
the	O
case	O
of	O
a	O
web	O
application	O
,	O
the	O
programmer	O
may	O
use	O
the	O
same	O
regular	B-Language
expression	I-Language
to	O
validate	O
input	O
on	O
both	O
the	O
client	O
and	O
the	O
server	O
side	O
of	O
the	O
system	O
.	O
</s>
<s>
An	O
attacker	O
could	O
inspect	O
the	O
client	O
code	O
,	O
looking	O
for	O
evil	O
regular	B-Language
expressions	I-Language
,	O
and	O
send	O
crafted	O
input	O
directly	O
to	O
the	O
web	O
server	O
in	O
order	O
to	O
hang	O
it	O
.	O
</s>
