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 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 >
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 >
You can’t perform that action at this time.
0 commit comments