Skip to content

Commit af2965c

Browse files
committed
Explain anchors in MissingRegExpAnchor qlhelp
1 parent 6f9dc5e commit af2965c

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

ruby/ql/src/queries/security/cwe-020/MissingRegExpAnchor.qhelp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
Sanitizing untrusted input with regular expressions is a
1010
common technique. However, it is error-prone to match untrusted input
11-
against regular expressions without anchors such as <code>^</code> or
12-
<code>$</code>. Malicious input can bypass such security checks by
11+
against regular expressions without anchors such as <code>\A</code> or
12+
<code>\z</code>. Malicious input can bypass such security checks by
1313
embedding one of the allowed patterns in an unexpected location.
1414

1515
</p>
@@ -68,10 +68,17 @@
6868
</p>
6969

7070
<p>
71+
In Ruby the anchors <code>^</code> and <code>$</code> match the
72+
start and end of a line, whereas the anchors <code>\A</code> and
73+
<code>\z</code> match the start and end of the entire string.
7174

72-
TODO: describe the danger of using line anchors like <code>^</code>
73-
or <code>$</code>.
75+
Using line anchors can be dangerous, as this can allow malicious
76+
input to be hidden using newlines, leading to vulnerabilities such
77+
as HTTP header injection.
7478

79+
Unless you specifically need the line-matching behaviour of
80+
<code>^</code> and <code>$</code>, you should use <code>\A</code>
81+
and <code>\z</code> instead.
7582
</p>
7683

7784
</example>

0 commit comments

Comments
 (0)