Skip to content

v2: !@validateHash matches when the regex fails (same as #3123) #3710

Done

Description

@fzipi

Describe the bug

ModSecurity v2's @validateHash has the same flaw #3123 describes for @rx. When the regex can't be evaluated, the operator returns 0 ("no match"), and the generic negation in execute_operator() (apache2/re.c) turns that into a match. A !@validateHash rule therefore fires on a regex error.

On v2/master (0875b19), in msre_op_validateHash_execute() (apache2/re_operators.c):

  • Line 848: a macro-expanded pattern that fails to compile at runtime sets *error_msg and returns 0.
  • Line 918: when the PCRE match or recursion limit is exceeded, it sets TX:MSC_PCRE_LIMITS_EXCEEDED and returns 0.

The match limit is easy for a client to hit with a long input, especially with the low SecPcreMatchLimit in modsecurity.conf-recommended.

Expected behavior

As with @rx in #3709, a regex failure should be neither a match nor a mismatch. Return rule->op_negated on both paths, so that neither @validateHash nor !@validateHash matches, and keep the error visible through the TX:MSC_* flags. For a compile error, that means setting TX:MSC_PCRE_ERROR, which #3709 introduces.

Related

The fix should come with regression tests in tests/regression/, mirroring misc/10-pcre-negated.t from #3709.

Activity

  1. added
    bug
    2.x
    on Oct 26, 2026
  2. fzipi commented on Nov 30, 2026

    @fzipi
    CollaboratorAuthor

    Fixed by #3712 (merged into v2/master on 2026-10-27): @validateHash now returns the negation flag on a regex compile error or exceeded PCRE limits, so a !@validateHash rule no longer matches on a regex error. Closing.

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

    2.xbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions