|
| 1 | +### Regex errors with negated @rx |
| 2 | + |
| 3 | +# Neither @rx nor !@rx must match when the regex fails. A failure must |
| 4 | +# be visible through the TX:MSC_* flags instead. |
| 5 | + |
| 6 | +{ |
| 7 | + type => "misc", |
| 8 | + comment => "PCRE limits exceeded - negated rx does not match", |
| 9 | + conf => qq( |
| 10 | + SecRuleEngine On |
| 11 | + SecDebugLog $ENV{DEBUG_LOG} |
| 12 | + SecDebugLogLevel 9 |
| 13 | + |
| 14 | + SecRequestBodyAccess On |
| 15 | + SecRequestBodyLimit 1000000 |
| 16 | + SecRequestBodyInMemoryLimit 1000000 |
| 17 | + |
| 18 | + SecPcreMatchLimit 100 |
| 19 | + SecPcreMatchLimitRecursion 100 |
| 20 | + |
| 21 | + SecRule ARGS "!\@rx (?:(.{2,})\\1{32,})" "phase:2,deny,id:500060" |
| 22 | + SecRule TX:MSC_PCRE_LIMITS_EXCEEDED "\@streq 1" "phase:2,pass,log,msg:'PCRE limits flagged',id:500061" |
| 23 | + ), |
| 24 | + match_log => { |
| 25 | + debug => [ qr/PCRE limits exceeded/, 1 ], |
| 26 | + error => [ qr/PCRE limits flagged/, 1 ], |
| 27 | + -error => [ qr/Access denied/, 1 ], |
| 28 | + }, |
| 29 | + match_response => { |
| 30 | + status => qr/^200$/, |
| 31 | + }, |
| 32 | + request => new HTTP::Request( |
| 33 | + POST => "http://$ENV{SERVER_NAME}:$ENV{SERVER_PORT}/index.html", |
| 34 | + [ |
| 35 | + "Content-Type" => "application/x-www-form-urlencoded", |
| 36 | + ], |
| 37 | + "test=" . (("a" x 64) . "b") x 64 . "d", |
| 38 | + ), |
| 39 | +}, |
| 40 | +{ |
| 41 | + type => "misc", |
| 42 | + comment => "PCRE limits exceeded - negated rx still checks the remaining targets", |
| 43 | + conf => qq( |
| 44 | + SecRuleEngine On |
| 45 | + SecDebugLog $ENV{DEBUG_LOG} |
| 46 | + SecDebugLogLevel 9 |
| 47 | + |
| 48 | + SecRequestBodyAccess On |
| 49 | + SecRequestBodyLimit 1000000 |
| 50 | + SecRequestBodyInMemoryLimit 1000000 |
| 51 | + |
| 52 | + SecPcreMatchLimit 100 |
| 53 | + SecPcreMatchLimitRecursion 100 |
| 54 | + |
| 55 | + SecRule ARGS "!\@rx (?:(.{2,})\\1{32,})" "phase:2,deny,log,id:500062" |
| 56 | + ), |
| 57 | + match_log => { |
| 58 | + debug => [ qr/PCRE limits exceeded/, 1 ], |
| 59 | + error => [ qr/against "ARGS:other" required/, 1 ], |
| 60 | + -error => [ qr/against "ARGS:test" required/, 1 ], |
| 61 | + }, |
| 62 | + match_response => { |
| 63 | + status => qr/^403$/, |
| 64 | + }, |
| 65 | + request => new HTTP::Request( |
| 66 | + POST => "http://$ENV{SERVER_NAME}:$ENV{SERVER_PORT}/index.html", |
| 67 | + [ |
| 68 | + "Content-Type" => "application/x-www-form-urlencoded", |
| 69 | + ], |
| 70 | + "test=" . (("a" x 64) . "b") x 64 . "d" . "&other=x", |
| 71 | + ), |
| 72 | +}, |
| 73 | +{ |
| 74 | + type => "misc", |
| 75 | + comment => "PCRE limits exceeded - rx does not match", |
| 76 | + conf => qq( |
| 77 | + SecRuleEngine On |
| 78 | + SecDebugLog $ENV{DEBUG_LOG} |
| 79 | + SecDebugLogLevel 9 |
| 80 | + |
| 81 | + SecRequestBodyAccess On |
| 82 | + SecRequestBodyLimit 1000000 |
| 83 | + SecRequestBodyInMemoryLimit 1000000 |
| 84 | + |
| 85 | + SecPcreMatchLimit 100 |
| 86 | + SecPcreMatchLimitRecursion 100 |
| 87 | + |
| 88 | + SecRule ARGS "\@rx (?:(.{2,})\\1{32,})" "phase:2,deny,id:500063" |
| 89 | + ), |
| 90 | + match_log => { |
| 91 | + debug => [ qr/PCRE limits exceeded/, 1 ], |
| 92 | + -error => [ qr/Access denied/, 1 ], |
| 93 | + }, |
| 94 | + match_response => { |
| 95 | + status => qr/^200$/, |
| 96 | + }, |
| 97 | + request => new HTTP::Request( |
| 98 | + POST => "http://$ENV{SERVER_NAME}:$ENV{SERVER_PORT}/index.html", |
| 99 | + [ |
| 100 | + "Content-Type" => "application/x-www-form-urlencoded", |
| 101 | + ], |
| 102 | + "test=" . (("a" x 64) . "b") x 64 . "d", |
| 103 | + ), |
| 104 | +}, |
| 105 | +{ |
| 106 | + type => "misc", |
| 107 | + comment => "Invalid expanded pattern - negated rx does not match, MSC_PCRE_ERROR is set", |
| 108 | + conf => qq( |
| 109 | + SecRuleEngine On |
| 110 | + SecDebugLog $ENV{DEBUG_LOG} |
| 111 | + SecDebugLogLevel 9 |
| 112 | + |
| 113 | + SecRule ARGS:x "!\@rx %{ARGS.patt}" "phase:2,deny,id:500064" |
| 114 | + SecRule TX:MSC_PCRE_ERROR "\@streq 1" "phase:2,pass,log,msg:'PCRE error flagged',id:500065" |
| 115 | + ), |
| 116 | + match_log => { |
| 117 | + debug => [ qr/Error compiling pattern/, 1 ], |
| 118 | + error => [ qr/PCRE error flagged/, 1 ], |
| 119 | + -error => [ qr/Access denied/, 1 ], |
| 120 | + }, |
| 121 | + match_response => { |
| 122 | + status => qr/^200$/, |
| 123 | + }, |
| 124 | + request => new HTTP::Request( |
| 125 | + GET => "http://$ENV{SERVER_NAME}:$ENV{SERVER_PORT}/index.html?x=a&patt=x%28", |
| 126 | + ), |
| 127 | +}, |
| 128 | +{ |
| 129 | + type => "misc", |
| 130 | + comment => "Invalid expanded pattern - TX:/^MSC_/ rule blocks the request", |
| 131 | + conf => qq( |
| 132 | + SecRuleEngine On |
| 133 | + SecDebugLog $ENV{DEBUG_LOG} |
| 134 | + SecDebugLogLevel 9 |
| 135 | + |
| 136 | + SecRule ARGS:x "!\@rx %{ARGS.patt}" "phase:2,deny,id:500066" |
| 137 | + SecRule TX:/^MSC_/ "!\@streq 0" "phase:2,t:none,log,deny,msg:'ModSecurity internal error flagged: %{MATCHED_VAR_NAME}',id:500067" |
| 138 | + ), |
| 139 | + match_log => { |
| 140 | + error => [ qr/internal error flagged: TX:MSC_PCRE_ERROR/, 1 ], |
| 141 | + -error => [ qr/against "ARGS:x" required/, 1 ], |
| 142 | + }, |
| 143 | + match_response => { |
| 144 | + status => qr/^403$/, |
| 145 | + }, |
| 146 | + request => new HTTP::Request( |
| 147 | + GET => "http://$ENV{SERVER_NAME}:$ENV{SERVER_PORT}/index.html?x=a&patt=x%28", |
| 148 | + ), |
| 149 | +}, |
0 commit comments