Skip to content

Commit ecd7316

Browse files
committed
Adjustments on the error log
i/o operations are expensive. Making sure that they were not being executed/printed more than necessary.
1 parent 2fe6adc commit ecd7316

File tree

6 files changed

+29
-16
lines changed

6 files changed

+29
-16
lines changed

src/rule_with_actions.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,10 +236,12 @@ void RuleWithActions::executeActionsAfterFullMatch(Transaction *trans) const {
236236
}
237237
}
238238
if (!disruptiveAlreadyExecuted && m_actionDisruptiveAction != nullptr) {
239+
trans->messageGetLast()->setRule(this);
239240
executeAction(trans,
240241
m_actionDisruptiveAction.get(), false);
241242
} else if (!disruptiveAlreadyExecuted && hasBlockAction()
242243
&& m_defaultActions.m_actionDisruptiveAction != nullptr) {
244+
trans->messageGetLast()->setRule(this);
243245
executeAction(trans,
244246
m_defaultActions.m_actionDisruptiveAction.get(), false);
245247
}

src/rule_with_actions.h

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -294,25 +294,27 @@ class RuleWithActions : public Rule, public RuleWithActionsProperties {
294294
return false;
295295
}
296296

297+
if (!hasDisruptiveAction() && !hasBlockAction()) {
298+
return false;
299+
}
300+
297301
return true;
298302
}
299303

300-
301304
inline bool isItToBeAuditLogged() const noexcept {
302-
if (!isItToBeLogged() && !m_containsAuditLogAction
303-
&& !m_defaultActions.m_containsAuditLogAction) {
304-
return false;
305+
if (m_containsAuditLogAction) {
306+
return true;
305307
}
306308

307-
if (m_containsNoAuditLogAction) {
308-
return false;
309+
if (m_defaultActions.m_containsAuditLogAction && !m_containsNoAuditLogAction) {
310+
return true;
309311
}
310312

311-
if (m_defaultActions.m_containsAuditLogAction && !m_containsAuditLogAction) {
312-
return false;
313+
if (isItToBeLogged()) {
314+
return true;
313315
}
314316

315-
return true;
317+
return false;
316318
}
317319

318320

src/transaction.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,12 @@ void TransactionRuleMessageManagement::logMatchLastRuleOnTheChain(const RuleWith
7272

7373
rm->setRule(rule);
7474

75-
if (rule->hasDisruptiveAction() && rule->isItToBeLogged() &&
76-
(m_transaction->getRuleEngineState() == RulesSet::DetectionOnlyRuleEngine)) {
75+
if (rule->isItToBeLogged() &&
76+
(m_transaction->getRuleEngineState() == RulesSet::EnabledRuleEngine)) {
7777
/* error */
7878
// The error goes over the disruptive massage. We don't need it here.
7979
//m_transaction->serverLog(rm);
80-
} else if (rule->hasBlockAction() && rule->isItToBeLogged()) {
80+
} else if (rule->isItToBeLogged()) {
8181
/* Log as warning. */
8282
m_transaction->serverLog(rm);
8383
}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,13 @@
277277
},
278278
"rules":[
279279
"SecRuleEngine On",
280-
"SecAuditEngine On",
280+
"SecAuditEngine RelevantOnly",
281+
"SecAuditLogParts ABCFHZ",
282+
"SecAuditLog /tmp/test/modsec_audit_auditlog_1.log",
283+
"SecAuditLogDirMode 0766",
284+
"SecAuditLogFileMode 0666",
285+
"SecAuditLogType Serial",
286+
"SecAuditLogRelevantStatus \"^(?:3|4(?!04))\"",
281287
"SecDefaultAction \"phase:2,log,auditlog,status:302,redirect:'http://www.google.com'\"",
282288
"SecRule REQUEST_HEADERS \"@contains PHPSESSID\" \"phase:2,id:1,block\"",
283289
"SecRule TX \"@contains to_test\" \"id:2,t:lowercase,t:none,block\""

test/test-cases/regression/issue-1528.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,13 @@
2727
},
2828
"expected": {
2929
"debug_log": "Rule returned 1",
30-
"error_log": "Matched \"Operator `Rx' with parameter `\\^attack\\$'"
30+
"error_log": "Matched \"Operator `Rx' with parameter `\\^attack\\$'",
31+
"http_code": 403
3132
},
3233
"rules": [
3334
"SecRuleEngine On",
3435
"SecAction \"id:1, setvar:tx.bad_value=attack\"",
35-
"SecRule ARGS:param \"@rx ^%{tx.bad_value}$\" \"id:2,log\""
36+
"SecRule ARGS:param \"@rx ^%{tx.bad_value}$\" \"id:2,log,deny\""
3637
]
3738
}
3839
]

test/test-cases/regression/issue-1844.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,12 @@
8585
]
8686
},
8787
"expected":{
88-
"error_log":"line \"55\""
88+
"error_log":"line \"55\"",
89+
"http_code": 403
8990
},
9091
"rules":[
9192
"SecRuleEngine On",
93+
"SecDefaultAction \"phase:2,deny\"",
9294
"SecRule WEBAPPID \"@contains test2\" \"id:1,phase:3,pass,t:trim\"",
9395
"Include test-cases/data/big-file.conf"
9496
]

0 commit comments

Comments
 (0)