Skip to content
This repository has been archived by the owner on Dec 15, 2023. It is now read-only.

Special characters are not escaped for named groups #38

Closed
th3-s3m opened this issue Jul 5, 2019 · 1 comment
Closed

Special characters are not escaped for named groups #38

th3-s3m opened this issue Jul 5, 2019 · 1 comment
Assignees
Labels

Comments

@th3-s3m
Copy link

th3-s3m commented Jul 5, 2019

In the modify_message function, when dynamically generating the regex value, special characters are not escaped if they're part of a named group (?P<{}>{}). When executing "match_exp = re_compile(exp + groups_exp)", groups_exp may contain special that will either generate an error or unexpected behavior.

Workaround:
In my case I was extracting a string that sometimes contains a + (base64-ish) with the following regex "token": "(?P<token>[^"]+).
I substituted lines 462, 463

    match_exp = re_compile(exp + groups_exp)
    self.logger.debug('match_exp adjusted to:\n{}'.format(match_exp.pattern))

with

    try:
        match_exp = re_compile(exp + groups_exp.replace('+','\+'))
    except re_error as e:
        self.logger.error(exc_invalid_regex.format(ph_target_exp, e))
        return msg_as_string

This workaround only fixed my case (+ char in extracted group), groups_exp should be properly escaped for all regex special characters before being recompiled.

Edit: workaround was not so clear.

elespike added a commit that referenced this issue Aug 17, 2019
group_match may contain RegEx characters (such as +)
which should be escaped prior to compiling groups_exp
@elespike
Copy link
Owner

Great catch, thank you!

Fixed here: 8d46886#diff-d59f892b7de1f2c8e5a2321095f452b4R451

@elespike elespike self-assigned this Aug 17, 2019
@elespike elespike added the bug label Aug 17, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants