Skip to content

Commit 202a15b

Browse files
author
Felipe Zimmerle
committed
Changes the behavior of the default sec actions
Fix #1629
1 parent 61c956e commit 202a15b

File tree

5 files changed

+27
-26
lines changed

5 files changed

+27
-26
lines changed

CHANGES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
v3.0.3 - YYYY-MMM-DD (to be released)
22
-------------------------------------
33

4+
- Changes the behavior of the default sec actions
5+
[Issue #1629 - @mirkodziadzka-avi, @zimmerle, @victorhora]
46
- Refactoring on {global,ip,resources,session,tx,user} collections
57
[Issue #1754, #1778 - @LeeShan87, @zimmerle, @victorhora, @wwd5613,
68
@sobigboy]

src/rule.cc

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -241,15 +241,14 @@ void Rule::updateRulesVariable(Transaction *trans) {
241241

242242

243243
void Rule::executeActionsIndependentOfChainedRuleResult(Transaction *trans,
244-
bool *containsDisruptive, std::shared_ptr<RuleMessage> ruleMessage) {
244+
bool *containsBlock, std::shared_ptr<RuleMessage> ruleMessage) {
245245
for (Action *a : this->m_actionsRuntimePos) {
246246
if (a->isDisruptive() == true) {
247-
if (a->m_name == "pass") {
247+
if (a->m_name == "block") {
248248
#ifndef NO_LOGS
249-
trans->debug(9, "Rule contains a `pass' action");
249+
trans->debug(9, "Rule contains a `block' action");
250+
*containsBlock = true;
250251
#endif
251-
} else {
252-
*containsDisruptive = true;
253252
}
254253
} else {
255254
if (a->m_name == "setvar" || a->m_name == "msg"
@@ -661,7 +660,7 @@ std::vector<std::unique_ptr<VariableValue>> Rule::getFinalVars(
661660

662661

663662
void Rule::executeActionsAfterFullMatch(Transaction *trans,
664-
bool containsDisruptive, std::shared_ptr<RuleMessage> ruleMessage) {
663+
bool containsBlock, std::shared_ptr<RuleMessage> ruleMessage) {
665664

666665
for (Action *a : trans->m_rules->m_defaultActions[this->m_phase]) {
667666
if (a->action_kind != actions::Action::RunTimeOnlyIfMatchKind) {
@@ -677,11 +676,11 @@ void Rule::executeActionsAfterFullMatch(Transaction *trans,
677676
continue;
678677
}
679678

680-
if (containsDisruptive) {
679+
if (!containsBlock) {
681680
#ifndef NO_LOGS
682681
trans->debug(4, "(SecDefaultAction) ignoring " \
683682
"action: " + a->m_name + \
684-
" (rule contains a disruptive action)");
683+
" (rule does not cotains block)");
685684
#endif
686685
continue;
687686
}
@@ -690,15 +689,15 @@ void Rule::executeActionsAfterFullMatch(Transaction *trans,
690689
#ifndef NO_LOGS
691690
trans->debug(4, "(SecDefaultAction) " \
692691
"Running action: " + a->m_name + \
693-
" (rule does not contain a disruptive action)");
692+
".");
694693
#endif
695694
a->evaluate(this, trans, ruleMessage);
696695
continue;
697696
}
698697

699698
#ifndef NO_LOGS
700699
trans->debug(4, "(SecDefaultAction) Not running action: " \
701-
+ a->m_name + ". Rule does not contain a disruptive action,"\
700+
+ a->m_name + ". Rule contains 'block',"\
702701
+ " but SecRuleEngine is not On.");
703702
#endif
704703
}
@@ -736,7 +735,7 @@ bool Rule::evaluate(Transaction *trans,
736735
bool globalRet = false;
737736
std::vector<Variable *> *variables = this->m_variables;
738737
bool recursiveGlobalRet;
739-
bool containsDisruptive = false;
738+
bool containsBlock = false;
740739
std::vector<std::unique_ptr<VariableValue>> finalVars;
741740
std::string eparam;
742741

@@ -756,7 +755,7 @@ bool Rule::evaluate(Transaction *trans,
756755
+ ") Executing unconditional rule...");
757756
#endif
758757
executeActionsIndependentOfChainedRuleResult(trans,
759-
&containsDisruptive, ruleMessage);
758+
&containsBlock, ruleMessage);
760759
goto end_exec;
761760
}
762761

@@ -827,7 +826,7 @@ bool Rule::evaluate(Transaction *trans,
827826
ruleMessage->m_reference.append(*valueTemp.second);
828827
updateMatchedVars(trans, key, value);
829828
executeActionsIndependentOfChainedRuleResult(trans,
830-
&containsDisruptive, ruleMessage);
829+
&containsBlock, ruleMessage);
831830
globalRet = true;
832831
}
833832
}
@@ -870,7 +869,7 @@ bool Rule::evaluate(Transaction *trans,
870869
return false;
871870

872871
end_exec:
873-
executeActionsAfterFullMatch(trans, containsDisruptive, ruleMessage);
872+
executeActionsAfterFullMatch(trans, containsBlock, ruleMessage);
874873
if (m_ruleId != 0 && ruleMessage->m_saveMessage != false) {
875874
trans->serverLog(ruleMessage);
876875
trans->m_rulesMessages.push_back(*ruleMessage);

test/test-cases/regression/action-disruptive.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,27 @@
44
"version_min":300000,
55
"title":"Testing Disruptive actions (1/n)",
66
"expected":{
7-
"debug_log": " Running action: deny",
7+
"debug_log": "Running action deny",
88
"http_code":403
99
},
1010
"rules":[
1111
"SecRuleEngine On",
1212
"SecDefaultAction \"phase:2,deny,status:404\"",
13-
"SecAction \"id:'900001',phase:request,nolog,status:403,t:none\""
13+
"SecAction \"id:'900001',phase:request,nolog,status:403,t:none,block\""
1414
]
1515
},
1616
{
1717
"enabled":1,
1818
"version_min":300000,
1919
"title":"Testing Disruptive actions (2/n)",
2020
"expected":{
21-
"debug_log": " Running action: deny",
21+
"debug_log": "Running action deny",
2222
"http_code":404
2323
},
2424
"rules":[
2525
"SecRuleEngine On",
2626
"SecDefaultAction \"phase:2,deny,status:404\"",
27-
"SecAction \"id:'1',phase:request,nolog,t:none\""
27+
"SecAction \"id:'1',phase:request,nolog,t:none,block\""
2828
]
2929
},
3030
{

test/test-cases/regression/config-secdefaultaction.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,8 @@
278278
"rules":[
279279
"SecRuleEngine On",
280280
"SecDefaultAction \"phase:2,log,auditlog,status:302,redirect:'http://www.google.com'\"",
281-
"SecRule REQUEST_HEADERS \"@contains PHPSESSID\" \"phase:2,id:1\"",
282-
"SecRule TX \"@contains to_test\" \"id:2,t:lowercase,t:none\""
281+
"SecRule REQUEST_HEADERS \"@contains PHPSESSID\" \"phase:2,id:1,block\"",
282+
"SecRule TX \"@contains to_test\" \"id:2,t:lowercase,t:none,block\""
283283
]
284284
}
285285
]

test/test-cases/regression/secruleengine.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
"version_min":300000,
55
"title":"Testing Disruptive actions (1/n)",
66
"expected":{
7-
"debug_log": " Running action: deny",
7+
"debug_log": " Running action deny",
88
"http_code":403
99
},
1010
"rules":[
1111
"SecRuleEngine On",
1212
"SecRuleEngine On",
1313
"SecDefaultAction \"phase:2,deny,status:404\"",
14-
"SecAction \"id:'900001',phase:request,nolog,status:403,t:none\""
14+
"SecAction \"id:'900001',phase:request,nolog,status:403,t:none,block\""
1515
]
1616
},
1717
{
@@ -26,7 +26,7 @@
2626
"SecRuleEngine On",
2727
"SecRuleEngine Off",
2828
"SecDefaultAction \"phase:2,deny,status:404\"",
29-
"SecAction \"id:'1',phase:request,nolog,t:none\""
29+
"SecAction \"id:'1',phase:request,nolog,t:none,block\""
3030
]
3131
},
3232
{
@@ -41,7 +41,7 @@
4141
"SecRuleEngine On",
4242
"SecRuleEngine DetectionOnly",
4343
"SecDefaultAction \"phase:2,deny,status:404\"",
44-
"SecAction \"id:'1',phase:request,nolog,nolog,block,t:none\""
44+
"SecAction \"id:'1',phase:request,nolog,nolog,block,t:none,block\""
4545
]
4646
},
4747
{
@@ -56,7 +56,7 @@
5656
"SecRuleEngine On",
5757
"SecRuleEngine Off",
5858
"SecDefaultAction \"phase:2,deny,status:404\"",
59-
"SecAction \"id:'1',phase:request,nolog,t:none\""
59+
"SecAction \"id:'1',phase:request,nolog,t:none,block\""
6060
]
6161
},
6262
{
@@ -71,7 +71,7 @@
7171
"SecRuleEngine On",
7272
"SecRuleEngine Off",
7373
"SecDefaultAction \"phase:2,deny,status:404\"",
74-
"SecAction \"id:'1',phase:request,nolog,block,t:none\""
74+
"SecAction \"id:'1',phase:request,nolog,block,t:none,block\""
7575
]
7676
}
7777
]

0 commit comments

Comments
 (0)