File tree Expand file tree Collapse file tree 1 file changed +11
-4
lines changed
ruby/ql/src/queries/security/cwe-020 Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Original file line number Diff line number Diff line change 8
8
9
9
Sanitizing untrusted input with regular expressions is a
10
10
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
13
13
embedding one of the allowed patterns in an unexpected location.
14
14
15
15
</p >
68
68
</p >
69
69
70
70
<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.
71
74
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.
74
78
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.
75
82
</p >
76
83
77
84
</example >
You can’t perform that action at this time.
0 commit comments