[Bug]: Overly permissive regular expression range
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 45/100
Research direction
The issue points to tests/integration/stackscripts/test_stackscripts.py at line 95; inspect the regular expression there and its existing coverage. Verify that the character ranges accept only the intended characters, update the relevant test or expression, and run the associated integration test.
Written by the indexing model from the issue text.
Description
CLI Version
v5.56.2
Command
It's easy to write a regular expression range that matches a wider range of characters than you intended. /[a-zA-z]/ matches all lowercase and all uppercase letters, as you would expect, but it also matches the characters: `[ \ ] ^ _ ``.
Another common problem is failing to escape the dash character in a regular expression. An unescaped dash is interpreted as part of a range. For example, in the character class [a-zA-Z0-9%=.,-_] the last character range matches the 55 characters between , and _ (both included), which overlaps with the range [0-9] and is clearly not intended by the writer.
Output
No response
Expected Behavior
[CWE-20
Actual Behavior
Improper Neutralization of Special Elements used in a Command in Shell-quote
Exploiting CVE-2021-42740
no-obscure-range
The regex [,-.]
CWE-20.
Steps to Reproduce
POC
The following code is intended to check whether a string is a valid 6 digit hex color.
import re
def is_valid_hex_color(color):
return re.match(r'^#[0-9a-fA-f]{6}$', color) is not None
However, the A-f range is overly large and matches every uppercase character. It would parse a "color" like #XXYYZZ as valid.
The fix is to use an uppercase A-F range instead.
import re
def is_valid_hex_color(color):
return re.match(r'^#[0-9a-fA-F]{6}$', color) is not None
Recommendation
Avoid any confusion about which characters are included in the range by writing unambiguous regular expressions. Always check that character ranges match only the expected characters.
- Dominant language
- Python
- Stars
- 442
- Forks
- 159
- Avg merge
- 7d 21h
- Merged PRs (30d)
- 8
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from linode/linode-cli
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
linode/linode-cli#894 ·
-
enhancement
Difficulty 1/5 Under an hour Newbie friendliness 85/100
linode/linode-cli#859 · 1 comment ·
-
enhancement
Difficulty 4/5 3-5 days Newbie friendliness 35/100
linode/linode-cli#868 ·
-
bug
Difficulty 3/5 1-2 days Newbie friendliness 45/100
linode/linode-cli#825 · 1 comment ·
-
enhancement
Difficulty 4/5 3-5 days Newbie friendliness 35/100
linode/linode-cli#788 ·
All issues in linode/linode-cli
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
stephrobert/dsoxlab#238 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
sublimehq/package_control#1780 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
nwg-piotr/nwg-displays#145 ·