Skip to content

Commit fea6e6d

Browse files
authored
Merge pull request #2901 from airween/v3/pcrelimittx
Set TX:MSC_PCRE_LIMITS_EXCEEDED variable is limits exceeded
2 parents 2cb6344 + 4403a16 commit fea6e6d

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

Diff for: src/operators/rx.cc

+2
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ bool Rx::evaluate(Transaction *transaction, RuleWithActions *rule,
7474
if (regex_result == Utils::RegexResult::ErrorMatchLimit) {
7575
regex_error_str = "MATCH_LIMIT";
7676
transaction->m_variableMscPcreLimitsExceeded.set("1", transaction->m_variableOffset);
77+
transaction->m_collections.m_tx_collection->storeOrUpdateFirst("MSC_PCRE_LIMITS_EXCEEDED", "1");
78+
ms_dbg_a(transaction, 7, "Set TX.MSC_PCRE_LIMITS_EXCEEDED to 1");
7779
}
7880

7981
ms_dbg_a(transaction, 1, "rx: regex error '" + regex_error_str + "' for pattern '" + re->pattern + "'");

Diff for: src/operators/rx_global.cc

+2
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ bool RxGlobal::evaluate(Transaction *transaction, RuleWithActions *rule,
6868
if (regex_result == Utils::RegexResult::ErrorMatchLimit) {
6969
regex_error_str = "MATCH_LIMIT";
7070
transaction->m_variableMscPcreLimitsExceeded.set("1", transaction->m_variableOffset);
71+
transaction->m_collections.m_tx_collection->storeOrUpdateFirst("MSC_PCRE_LIMITS_EXCEEDED", "1");
72+
ms_dbg_a(transaction, 7, "Set TX.MSC_PCRE_LIMITS_EXCEEDED to 1");
7173
}
7274

7375
ms_dbg_a(transaction, 1, "rxGlobal: regex error '" + regex_error_str + "' for pattern '" + re->pattern + "'");

Diff for: test/test-cases/regression/operator-rx.json

+45
Original file line numberDiff line numberDiff line change
@@ -217,5 +217,50 @@
217217
"SecRule ARGS:rxtest \"@rx (w+)+$\" \"id:1,phase:1,pass,t:trim,block\"",
218218
"SecRule MSC_PCRE_LIMITS_EXCEEDED \"@streq 1\" \"id:2,phase:1,pass,t:trim,block\""
219219
]
220+
},
221+
{
222+
"enabled":1,
223+
"version_min":300000,
224+
"title":"Testing Operator :: @rx with PCRE match limits exceeded",
225+
"client":{
226+
"ip":"200.249.12.31",
227+
"port":123
228+
},
229+
"server":{
230+
"ip":"200.249.12.31",
231+
"port":80
232+
},
233+
"request":{
234+
"headers":{
235+
"Host":"localhost",
236+
"User-Agent":"curl/7.38.0",
237+
"Accept":"*/*",
238+
"Content-Length": "27",
239+
"Content-Type": "application/x-www-form-urlencoded"
240+
},
241+
"uri":"/?rxtest=wwwwwwwwwwwwwwwwwwwwwowwwwwwwwwww",
242+
"method":"HEAD",
243+
"body": [ ]
244+
},
245+
"response":{
246+
"headers":{
247+
"Date":"Mon, 13 Jul 2015 20:02:41 GMT",
248+
"Last-Modified":"Sun, 26 Oct 2014 22:33:37 GMT",
249+
"Content-Type":"text/html"
250+
},
251+
"body":[
252+
"no need."
253+
]
254+
},
255+
"expected":{
256+
"debug_log":"rx: regex error 'MATCH_LIMIT' for pattern",
257+
"error_log":"Matched \"Operator `StrEq' with parameter `1' against variable `TX:MSC_PCRE_LIMITS_EXCEEDED'"
258+
},
259+
"rules":[
260+
"SecRuleEngine On",
261+
"SecPcreMatchLimit 2",
262+
"SecRule ARGS:rxtest \"@rx (w+)+$\" \"id:1,phase:1,pass,t:trim,block\"",
263+
"SecRule TX:MSC_PCRE_LIMITS_EXCEEDED \"@streq 1\" \"id:2,phase:1,pass,t:trim,block\""
264+
]
220265
}
221266
]

0 commit comments

Comments
 (0)