Skip to content

@streq values with brackets or without quotes are silently parsed as @rx #163

Open

Description

@fzipi

Summary

Some @streq values are parsed as rx instead of streq, and no error is raised. This happens when the value has ( ) [ ] in it, and also when it isn't wrapped in single quotes. The parse result then has operator.streq=None and operator.rx="streq <value>".

Reproduction (main @ 2fa0869, 0.4.2)

from secrules_parsing import parser
for op in ["@streq abc", "@streq phpinfo()", "@streq 'abc'", "@streq 'phpinfo()'",
           "@streq 'a[b]'", "@streq 'a{b}'", "@streq '%{tx.a}()'"]:
    o = parser.process_from_str(f'SecRule ARGS "{op}" "id:1,phase:2,deny"').rules[0].operator
    print(repr(op), "-> streq=%r rx=%r" % (o.streq, o.rx))
'@streq abc'          -> streq=None     rx='streq abc'
'@streq phpinfo()'    -> streq=None     rx='streq phpinfo()'
"@streq 'abc'"        -> streq="'abc'"  rx=None
"@streq 'phpinfo()'"  -> streq=None     rx="streq 'phpinfo()'"
"@streq 'a[b]'"       -> streq=None     rx="streq 'a[b]'"
"@streq 'a{b}'"       -> streq="'a{b}'" rx=None
"@streq '%{tx.a}()'"  -> streq=None     rx="streq '%{tx.a}()'"

Only quoted values without parentheses or square brackets parse as streq.

Cause

In src/secrules_parsing/model/secrules.tx:

Suggested fix

  • Give streq a value rule that accepts any operator text, quoted or unquoted, including brackets and macros.
  • Consider whether the '' rx=RegExp fallback should apply when the input starts with a known operator name (@streq ...), since it hides parse failures like this one.
  • Add parametrized tests that check operator.streq is set, not just that parsing succeeds.

Found while reviewing #161.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions