Skip to content

Commit 0abbd50

Browse files
committed
apply changes based on docs review
1 parent 595875f commit 0abbd50

File tree

8 files changed

+72
-84
lines changed

8 files changed

+72
-84
lines changed

java/ql/src/Security/CWE/CWE-020/OverlyLargeRange.qhelp

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,32 @@
55

66
<overview>
77
<p>
8-
A regexp range can by accident match more than was intended.
9-
For example, the regular expression <code>/[a-zA-z]/</code> will
10-
match every lowercase and uppercase letters, but the same regular
11-
expression will also match the chars: <code>[\]^_`</code>.
8+
It's easy to write a regular expression range that matches a wider range of characters than you intended.
9+
For example, <code>/[a-zA-z]/</code> matches all lowercase and all uppercase letters,
10+
as you would expect, but it also matches the characters: <code>[ \ ] ^ _ `</code>.
1211
</p>
1312
<p>
14-
On other occasions it can happen that the dash in a regular
15-
expression is not escaped, which will cause it to be interpreted
16-
as part of a range. For example in the character class <code>[a-zA-Z0-9%=.,-_]</code>
13+
Another common problem is failing to escape the dash character in a regular
14+
expression. An unescaped dash is interpreted
15+
as part of a range. For example, in the character class <code>[a-zA-Z0-9%=.,-_]</code>
1716
the last character range matches the 55 characters between
1817
<code>,</code> and <code>_</code> (both included), which overlaps with the
19-
range <code>[0-9]</code> and is thus clearly not intended.
18+
range <code>[0-9]</code> and is clearly not intended by the writer.
2019
</p>
2120
</overview>
2221

2322
<recommendation>
2423
<p>
25-
26-
Don't write character ranges were there might be confusion as to
27-
which characters are included in the range.
28-
24+
Avoid any confusion about which characters are included in the range by
25+
writing unambiguous regular expressions.
26+
Always check that character ranges match only the expected characters.
2927
</p>
3028
</recommendation>
3129

3230
<example>
3331

3432
<p>
35-
The following example code checks whether a string is a valid 6 digit hex color.
33+
The following example code is intended to check whether a string is a valid 6 digit hex color.
3634
</p>
3735

3836
<sample language="java">
@@ -45,8 +43,8 @@ public class Tester {
4543
</sample>
4644

4745
<p>
48-
However, the <code>A-f</code> range matches every uppercase character, and
49-
thus a "color" like <code>#XYZ</code> is considered valid.
46+
However, the <code>A-f</code> range is overly large and matches every uppercase character.
47+
It would parse a "color" like <code>#XXYYZZ</code> as valid.
5048
</p>
5149

5250
<p>
@@ -65,10 +63,9 @@ public class Tester {
6563
</example>
6664

6765
<references>
68-
<li>Mitre.org: <a href="https://cwe.mitre.org/data/definitions/20.html">CWE-020</a></li>
69-
<li>github.com: <a href="https://github.com/advisories/GHSA-g4rg-993r-mgx7">CVE-2021-42740</a></li>
66+
<li>GitHub Advisory Database: <a href="https://github.com/advisories/GHSA-g4rg-993r-mgx7">CVE-2021-42740: Improper Neutralization of Special Elements used in a Command in Shell-quote</a></li>
7067
<li>wh0.github.io: <a href="https://wh0.github.io/2021/10/28/shell-quote-rce-exploiting.html">Exploiting CVE-2021-42740</a></li>
71-
<li>ota-meshi.github.io: <a href="https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-obscure-range.html">no-obscure-range</a></li>
72-
<li>pboyd.io: <a href="https://pboyd.io/posts/comma-dash-dot/">The regex [,-.]</a></li>
68+
<li>Yosuke Ota: <a href="https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-obscure-range.html">no-obscure-range</a></li>
69+
<li>Paul Boyd: <a href="https://pboyd.io/posts/comma-dash-dot/">The regex [,-.]</a></li>
7370
</references>
7471
</qhelp>

java/ql/src/Security/CWE/CWE-020/OverlyLargeRange.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
2-
* @name Overly large regular expression range
3-
* @description Overly permissive regular expression ranges may cause regular expressions to match more than anticipated.
2+
* @name Overly permissive regular expression range
3+
* @description Overly permissive regular expression ranges match a wider range of characters than intended.
44
* This may allow an attacker to bypass a filter or sanitizer.
55
* @kind problem
66
* @problem.severity warning

javascript/ql/src/Security/CWE-020/OverlyLargeRange.qhelp

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,32 @@
55

66
<overview>
77
<p>
8-
A regexp range can by accident match more than was intended.
9-
For example, the regular expression <code>/[a-zA-z]/</code> will
10-
match every lowercase and uppercase letters, but the same regular
11-
expression will also match the chars: <code>[\]^_`</code>.
8+
It's easy to write a regular expression range that matches a wider range of characters than you intended.
9+
For example, <code>/[a-zA-z]/</code> matches all lowercase and all uppercase letters,
10+
as you would expect, but it also matches the characters: <code>[ \ ] ^ _ `</code>.
1211
</p>
1312
<p>
14-
On other occasions it can happen that the dash in a regular
15-
expression is not escaped, which will cause it to be interpreted
16-
as part of a range. For example in the character class <code>[a-zA-Z0-9%=.,-_]</code>
13+
Another common problem is failing to escape the dash character in a regular
14+
expression. An unescaped dash is interpreted
15+
as part of a range. For example, in the character class <code>[a-zA-Z0-9%=.,-_]</code>
1716
the last character range matches the 55 characters between
1817
<code>,</code> and <code>_</code> (both included), which overlaps with the
19-
range <code>[0-9]</code> and is thus clearly not intended.
18+
range <code>[0-9]</code> and is clearly not intended by the writer.
2019
</p>
2120
</overview>
2221

2322
<recommendation>
2423
<p>
25-
26-
Don't write character ranges were there might be confusion as to
27-
which characters are included in the range.
28-
24+
Avoid any confusion about which characters are included in the range by
25+
writing unambiguous regular expressions.
26+
Always check that character ranges match only the expected characters.
2927
</p>
3028
</recommendation>
3129

3230
<example>
3331

3432
<p>
35-
The following example code checks whether a string is a valid 6 digit hex color.
33+
The following example code is intended to check whether a string is a valid 6 digit hex color.
3634
</p>
3735

3836
<sample language="javascript">
@@ -42,8 +40,8 @@ function isValidHexColor(color) {
4240
</sample>
4341

4442
<p>
45-
However, the <code>A-f</code> range matches every uppercase character, and
46-
thus a "color" like <code>#XYZ</code> is considered valid.
43+
However, the <code>A-f</code> range is overly large and matches every uppercase character.
44+
It would parse a "color" like <code>#XXYYZZ</code> as valid.
4745
</p>
4846

4947
<p>
@@ -59,10 +57,9 @@ function isValidHexColor(color) {
5957
</example>
6058

6159
<references>
62-
<li>Mitre.org: <a href="https://cwe.mitre.org/data/definitions/20.html">CWE-020</a></li>
63-
<li>github.com: <a href="https://github.com/advisories/GHSA-g4rg-993r-mgx7">CVE-2021-42740</a></li>
60+
<li>GitHub Advisory Database: <a href="https://github.com/advisories/GHSA-g4rg-993r-mgx7">CVE-2021-42740: Improper Neutralization of Special Elements used in a Command in Shell-quote</a></li>
6461
<li>wh0.github.io: <a href="https://wh0.github.io/2021/10/28/shell-quote-rce-exploiting.html">Exploiting CVE-2021-42740</a></li>
65-
<li>ota-meshi.github.io: <a href="https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-obscure-range.html">no-obscure-range</a></li>
66-
<li>pboyd.io: <a href="https://pboyd.io/posts/comma-dash-dot/">The regex [,-.]</a></li>
62+
<li>Yosuke Ota: <a href="https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-obscure-range.html">no-obscure-range</a></li>
63+
<li>Paul Boyd: <a href="https://pboyd.io/posts/comma-dash-dot/">The regex [,-.]</a></li>
6764
</references>
6865
</qhelp>

javascript/ql/src/Security/CWE-020/OverlyLargeRange.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
2-
* @name Overly large regular expression range
3-
* @description Overly permissive regular expression ranges may cause regular expressions to match more than anticipated.
2+
* @name Overly permissive regular expression range
3+
* @description Overly permissive regular expression ranges match a wider range of characters than intended.
44
* This may allow an attacker to bypass a filter or sanitizer.
55
* @kind problem
66
* @problem.severity warning

python/ql/src/Security/CWE-020/OverlyLargeRange.qhelp

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,32 @@
55

66
<overview>
77
<p>
8-
A regexp range can by accident match more than was intended.
9-
For example, the regular expression <code>/[a-zA-z]/</code> will
10-
match every lowercase and uppercase letters, but the same regular
11-
expression will also match the chars: <code>[\]^_`</code>.
8+
It's easy to write a regular expression range that matches a wider range of characters than you intended.
9+
For example, <code>/[a-zA-z]/</code> matches all lowercase and all uppercase letters,
10+
as you would expect, but it also matches the characters: <code>[ \ ] ^ _ `</code>.
1211
</p>
1312
<p>
14-
On other occasions it can happen that the dash in a regular
15-
expression is not escaped, which will cause it to be interpreted
16-
as part of a range. For example in the character class <code>[a-zA-Z0-9%=.,-_]</code>
13+
Another common problem is failing to escape the dash character in a regular
14+
expression. An unescaped dash is interpreted
15+
as part of a range. For example, in the character class <code>[a-zA-Z0-9%=.,-_]</code>
1716
the last character range matches the 55 characters between
1817
<code>,</code> and <code>_</code> (both included), which overlaps with the
19-
range <code>[0-9]</code> and is thus clearly not intended.
18+
range <code>[0-9]</code> and is clearly not intended by the writer.
2019
</p>
2120
</overview>
2221

2322
<recommendation>
2423
<p>
25-
26-
Don't write character ranges were there might be confusion as to
27-
which characters are included in the range.
28-
24+
Avoid any confusion about which characters are included in the range by
25+
writing unambiguous regular expressions.
26+
Always check that character ranges match only the expected characters.
2927
</p>
3028
</recommendation>
3129

3230
<example>
3331

3432
<p>
35-
The following example code checks whether a string is a valid 6 digit hex color.
33+
The following example code is intended to check whether a string is a valid 6 digit hex color.
3634
</p>
3735

3836
<sample language="python">
@@ -42,8 +40,8 @@ def is_valid_hex_color(color):
4240
</sample>
4341

4442
<p>
45-
However, the <code>A-f</code> range matches every uppercase character, and
46-
thus a "color" like <code>#XYZ</code> is considered valid.
43+
However, the <code>A-f</code> range is overly large and matches every uppercase character.
44+
It would parse a "color" like <code>#XXYYZZ</code> as valid.
4745
</p>
4846

4947
<p>
@@ -59,10 +57,9 @@ def is_valid_hex_color(color):
5957
</example>
6058

6159
<references>
62-
<li>Mitre.org: <a href="https://cwe.mitre.org/data/definitions/20.html">CWE-020</a></li>
63-
<li>github.com: <a href="https://github.com/advisories/GHSA-g4rg-993r-mgx7">CVE-2021-42740</a></li>
60+
<li>GitHub Advisory Database: <a href="https://github.com/advisories/GHSA-g4rg-993r-mgx7">CVE-2021-42740: Improper Neutralization of Special Elements used in a Command in Shell-quote</a></li>
6461
<li>wh0.github.io: <a href="https://wh0.github.io/2021/10/28/shell-quote-rce-exploiting.html">Exploiting CVE-2021-42740</a></li>
65-
<li>ota-meshi.github.io: <a href="https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-obscure-range.html">no-obscure-range</a></li>
66-
<li>pboyd.io: <a href="https://pboyd.io/posts/comma-dash-dot/">The regex [,-.]</a></li>
62+
<li>Yosuke Ota: <a href="https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-obscure-range.html">no-obscure-range</a></li>
63+
<li>Paul Boyd: <a href="https://pboyd.io/posts/comma-dash-dot/">The regex [,-.]</a></li>
6764
</references>
6865
</qhelp>

python/ql/src/Security/CWE-020/OverlyLargeRange.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
2-
* @name Overly large regular expression range
3-
* @description Overly permissive regular expression ranges may cause regular expressions to match more than anticipated.
2+
* @name Overly permissive regular expression range
3+
* @description Overly permissive regular expression ranges match a wider range of characters than intended.
44
* This may allow an attacker to bypass a filter or sanitizer.
55
* @kind problem
66
* @problem.severity warning

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

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,32 @@
55

66
<overview>
77
<p>
8-
A regexp range can by accident match more than was intended.
9-
For example, the regular expression <code>/[a-zA-z]/</code> will
10-
match every lowercase and uppercase letters, but the same regular
11-
expression will also match the chars: <code>[\]^_`</code>.
8+
It's easy to write a regular expression range that matches a wider range of characters than you intended.
9+
For example, <code>/[a-zA-z]/</code> matches all lowercase and all uppercase letters,
10+
as you would expect, but it also matches the characters: <code>[ \ ] ^ _ `</code>.
1211
</p>
1312
<p>
14-
On other occasions it can happen that the dash in a regular
15-
expression is not escaped, which will cause it to be interpreted
16-
as part of a range. For example in the character class <code>[a-zA-Z0-9%=.,-_]</code>
13+
Another common problem is failing to escape the dash character in a regular
14+
expression. An unescaped dash is interpreted
15+
as part of a range. For example, in the character class <code>[a-zA-Z0-9%=.,-_]</code>
1716
the last character range matches the 55 characters between
1817
<code>,</code> and <code>_</code> (both included), which overlaps with the
19-
range <code>[0-9]</code> and is thus clearly not intended.
18+
range <code>[0-9]</code> and is clearly not intended by the writer.
2019
</p>
2120
</overview>
2221

2322
<recommendation>
2423
<p>
25-
26-
Don't write character ranges were there might be confusion as to
27-
which characters are included in the range.
28-
24+
Avoid any confusion about which characters are included in the range by
25+
writing unambiguous regular expressions.
26+
Always check that character ranges match only the expected characters.
2927
</p>
3028
</recommendation>
3129

3230
<example>
3331

3432
<p>
35-
The following example code checks whether a string is a valid 6 digit hex color.
33+
The following example code is intended to check whether a string is a valid 6 digit hex color.
3634
</p>
3735

3836
<sample language="ruby">
@@ -42,8 +40,8 @@ end
4240
</sample>
4341

4442
<p>
45-
However, the <code>A-f</code> range matches every uppercase character, and
46-
thus a "color" like <code>#XYZ</code> is considered valid.
43+
However, the <code>A-f</code> range is overly large and matches every uppercase character.
44+
It would parse a "color" like <code>#XXYYZZ</code> as valid.
4745
</p>
4846

4947
<p>
@@ -59,10 +57,9 @@ end
5957
</example>
6058

6159
<references>
62-
<li>Mitre.org: <a href="https://cwe.mitre.org/data/definitions/20.html">CWE-020</a></li>
63-
<li>github.com: <a href="https://github.com/advisories/GHSA-g4rg-993r-mgx7">CVE-2021-42740</a></li>
60+
<li>GitHub Advisory Database: <a href="https://github.com/advisories/GHSA-g4rg-993r-mgx7">CVE-2021-42740: Improper Neutralization of Special Elements used in a Command in Shell-quote</a></li>
6461
<li>wh0.github.io: <a href="https://wh0.github.io/2021/10/28/shell-quote-rce-exploiting.html">Exploiting CVE-2021-42740</a></li>
65-
<li>ota-meshi.github.io: <a href="https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-obscure-range.html">no-obscure-range</a></li>
66-
<li>pboyd.io: <a href="https://pboyd.io/posts/comma-dash-dot/">The regex [,-.]</a></li>
62+
<li>Yosuke Ota: <a href="https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-obscure-range.html">no-obscure-range</a></li>
63+
<li>Paul Boyd: <a href="https://pboyd.io/posts/comma-dash-dot/">The regex [,-.]</a></li>
6764
</references>
6865
</qhelp>

ruby/ql/src/queries/security/cwe-020/OverlyLargeRange.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
2-
* @name Overly large regular expression range
3-
* @description Overly permissive regular expression ranges may cause regular expressions to match more than anticipated.
2+
* @name Overly permissive regular expression range
3+
* @description Overly permissive regular expression ranges match a wider range of characters than intended.
44
* This may allow an attacker to bypass a filter or sanitizer.
55
* @kind problem
66
* @problem.severity warning

0 commit comments

Comments
 (0)