Skip to content

Commit 1f58152

Browse files
committed
Swift: Revise the qhelp.
1 parent 54a8f9e commit 1f58152

File tree

3 files changed

+7
-13
lines changed

3 files changed

+7
-13
lines changed

swift/ql/src/queries/Security/CWE-1333/ReDoS.qhelp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
<include src="ReDoSIntroduction.inc.qhelp" />
44
<example>
55
<p>Consider this regular expression:</p>
6-
<sample language="ruby">
6+
<sample language="swift">
77
/^_(__|.)+_$/</sample>
88
<p>
9-
Its sub-expression <code>"(__|.)+?"</code> can match the string
9+
Its sub-expression <code>"(__|.)+"</code> can match the string
1010
<code>"__"</code> either by the first alternative <code>"__"</code> to the
1111
left of the <code>"|"</code> operator, or by two repetitions of the second
1212
alternative <code>"."</code> to the right. Thus, a string consisting of an
@@ -19,7 +19,7 @@
1919
the ambiguity between the two branches of the alternative inside the
2020
repetition:
2121
</p>
22-
<sample language="ruby">
22+
<sample language="swift">
2323
/^_(__|[^_])+_$/</sample>
2424
</example>
2525
<include src="ReDoSReferences.inc.qhelp"/>

swift/ql/src/queries/Security/CWE-1333/ReDoSIntroduction.inc.qhelp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,20 @@
55
Some regular expressions take a long time to match certain input strings
66
to the point where the time it takes to match a string of length <i>n</i>
77
is proportional to <i>n<sup>k</sup></i> or even <i>2<sup>n</sup></i>.
8-
Such regular expressions can negatively affect performance, or even allow
8+
Such regular expressions can negatively affect performance, and potentially allow
99
a malicious user to perform a Denial of Service ("DoS") attack by crafting
1010
an expensive input string for the regular expression to match.
1111
</p>
1212
<p>
13-
The regular expression engine used by the Ruby interpreter (MRI) uses
13+
The regular expression engine used by Swift uses a
1414
backtracking non-deterministic finite automata to implement regular
1515
expression matching. While this approach is space-efficient and allows
1616
supporting advanced features like capture groups, it is not time-efficient
1717
in general. The worst-case time complexity of such an automaton can be
18-
polynomial or even exponential, meaning that for strings of a certain
18+
polynomial or exponential, meaning that for strings of a certain
1919
shape, increasing the input length by ten characters may make the
2020
automaton about 1000 times slower.
2121
</p>
22-
<p>
23-
Note that Ruby 3.2 and later have implemented a caching mechanism that
24-
completely eliminates the worst-case time complexity for the regular
25-
expressions flagged by this query. The regular expressions flagged by this
26-
query are therefore only problematic for Ruby versions prior to 3.2.
27-
</p>
2822
<p>
2923
Typically, a regular expression is affected by this problem if it contains
3024
a repetition of the form <code>r*</code> or <code>r+</code> where the

swift/ql/src/queries/Security/CWE-1333/ReDoSReferences.inc.qhelp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<li>Wikipedia: <a href="https://en.wikipedia.org/wiki/ReDoS">ReDoS</a>.</li>
88
<li>Wikipedia: <a href="https://en.wikipedia.org/wiki/Time_complexity">Time complexity</a>.</li>
99
<li>James Kirrage, Asiri Rathnayake, Hayo Thielecke:
10-
<a href="http://www.cs.bham.ac.uk/~hxt/research/reg-exp-sec.pdf">Static Analysis for Regular Expression Denial-of-Service Attack</a>.
10+
<a href="https://arxiv.org/abs/1301.0849">Static Analysis for Regular Expression Denial-of-Service Attack</a>.
1111
</li>
1212
</references>
1313
</qhelp>

0 commit comments

Comments
 (0)