Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Matomo ReDoS vulnerability (regex denial of service) #216

Open
bittner opened this issue Jul 13, 2022 · 0 comments
Open

Matomo ReDoS vulnerability (regex denial of service) #216

bittner opened this issue Jul 13, 2022 · 0 comments

Comments

@bittner
Copy link
Member

bittner commented Jul 13, 2022

We have been contacted by junior security researchers who pointed out that one of our regular expressions in the Matomo module makes software using Analytical vulnerable to Regular expression Denial of Service attacks (ReDoS).

I'm publishing this information in the faith that this vulnerability cannot be exploited easily in our context, because the Matomo server URL is a configuration setting that is not user supplied.

Details

From analytical/templatetags/matomo.py, line 20:

# domain name (characters separated by a dot), optional port, optional URI path, no slash
DOMAINPATH_RE = re.compile(r'^(([^./?#@:]+\.)*[^./?#@:]+)+(:[0-9]+)?(/[^/?#@:]+)*$')

The problematic bit is the repetition (]+)+) after a piece that induces backtracking.

Anyone willing to assist in fixing this issue is very welcome! 🙏

Potential Solution Approaches

  1. Simplify the regular expression (remove or limit the repetition)
  2. Use urllib.parse.urlparse and/or related functions
  3. A combination of 1. and 2.

Example: (note that urlparse alone seem unsuitable for our use case)

class MatomoNode(Node):
    def __init__(self):

        # avoid ReDoS vulnerability not using a regex with backtracking
        parsable_url = '//' + getattr(settings, 'MATOMO_DOMAIN_PATH', '')
        result = urlparse(parsable_url)
        if result.scheme or (not result.netloc and not result.path):
            # make this fail

Background Reading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant