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

t:lowercase check #44

Closed
theMiddleBlue opened this issue Mar 16, 2023 · 2 comments · Fixed by #67
Closed

t:lowercase check #44

theMiddleBlue opened this issue Mar 16, 2023 · 2 comments · Fixed by #67

Comments

@theMiddleBlue
Copy link
Contributor

is it possible to check if a rule has t:lowercase but the operator argument contains any character in A-Z range?

@airween
Copy link
Contributor

airween commented Mar 16, 2023

I think secrules_parsing is not able to do that. But you can do that with msc_pyparser.

@fzipi
Copy link
Member

fzipi commented Jan 27, 2024

@theMiddleBlue Finally dived into this one.

Wrote a test like this:

def test_lowercase_and_uppercase_in_argument() -> None:
    """Test that a collection argument can contain `$` (e.g., a key in a JSON document)"""
    rule_text = """
    SecRule REQUEST_FILENAME "@rx /[ABCD]+/$" \
    "id:1234,\
    phase:1,\
    pass,\
    t:lowercase,\
    nolog
    """

    uppercase_regex = re.compile('/[A-Z]/')
    parsed_rule = parser.process_from_str(rule_text)
    for rule in parsed_rule.rules:
        assert rule.__class__.__name__ == "SecRule"
        for action in rule.actions:
            if action.transformations:
                for t in action.transformations:
                    if t == "lowercase":
                        assert not uppercase_regex.match(rule.operator.rx)

So you can indeed write something similar to match your usage.

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

Successfully merging a pull request may close this issue.

3 participants