Skip to content

Commit c937230

Browse files
geoffw0subatoi
andauthored
Apply suggestions from code review
Co-authored-by: Ben Ahmady <[email protected]>
1 parent 727a7e8 commit c937230

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

swift/ql/src/queries/Security/CWE-020/MissingRegexAnchor.qhelp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,23 +46,25 @@
4646

4747
<p>
4848

49-
The check with the regular expression match is, however, easy to bypass. For example
50-
by embedding <code>http://www.example.com/</code> in the query
51-
string component: <code>http://evil-example.net/?x=http://www.example.com/</code>.
52-
Address these shortcomings by using anchors in the regular expression instead:
49+
However, this regular expression check can be easily bypassed,
50+
and a malicious actor could embed
51+
<code>http://www.example.com/</code> in the query
52+
string component of a malicious site. For example,
53+
<code>http://evil-example.net/?x=http://www.example.com/</code>.
54+
Instead, you should use anchors in the regular expression check:
5355

5456
</p>
5557

5658
<sample src="MissingRegexAnchorGood.swift"/>
5759

5860
<p>
5961

60-
A related mistake is to write a regular expression with
61-
multiple alternatives, but to only include an anchor for one of the
62-
alternatives. As an example, the regular expression
63-
<code>/^www\.example\.com|beta\.example\.com/</code> will match the host
64-
<code>evil.beta.example.com</code> because the regular expression is parsed
65-
as <code>/(^www\.example\.com)|(beta\.example\.com)/</code>
62+
If you need to write a regular expression to match
63+
multiple hosts, you should include an anchor for all of the
64+
alternatives. For example, the regular expression
65+
<code>/^www\.example\.com|beta\.example\.com/</code> will only match the host
66+
<code>evil.beta.example.com</code>, because the regular expression is parsed
67+
as <code>/(^www\.example\.com)|(beta\.example\.com)/</code>.
6668

6769
</p>
6870
</example>

0 commit comments

Comments
 (0)