Skip to content

Commit 39fb75c

Browse files
author
Felipe Zimmerle
committed
Having disruptive msgs as disruptive [instead of warnings] on audit log
Issue #1592
1 parent 30797a4 commit 39fb75c

File tree

4 files changed

+38
-1
lines changed

4 files changed

+38
-1
lines changed

CHANGES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
v3.0.????? - ?
33
---------------------------
44

5+
- Having disruptive msgs as disruptive [instead of warnings] on audit log
6+
[Issue #1592 - @zimmerle, @nobodysz]
57
- Parser: Pipes are no longer welcomed inside regex dict element selection.
68
[Issue #1591 - @zimmerle, @slabber]
79
- Avoids unicode initialization on every rules object

headers/modsecurity/rule_message.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ class RuleMessage {
6868
std::string noClientErrorLog() {
6969
return RuleMessage::noClientErrorLog(this);
7070
}
71+
std::string noClientErrorLog(bool disrupt) {
72+
return RuleMessage::noClientErrorLog(this, disrupt);
73+
}
7174
std::string errorLogTail() {
7275
return RuleMessage::errorLogTail(this);
7376
}
@@ -76,6 +79,7 @@ class RuleMessage {
7679
}
7780
static std::string disruptiveErrorLog(const RuleMessage *rm);
7881
static std::string noClientErrorLog(const RuleMessage *rm);
82+
static std::string noClientErrorLog(const RuleMessage *rm, bool disrupt);
7983
static std::string errorLogTail(const RuleMessage *rm);
8084
static std::string errorLog(const RuleMessage *rm);
8185
static std::string log(const RuleMessage *rm);

src/rule_message.cc

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,33 @@ std::string RuleMessage::disruptiveErrorLog(const RuleMessage *rm) {
5353
return modsecurity::utils::string::toHexIfNeeded(msg);
5454
}
5555

56+
std::string RuleMessage::noClientErrorLog(const RuleMessage *rm, bool disruptive) {
57+
std::string msg;
58+
if (disruptive == false) {
59+
return RuleMessage::noClientErrorLog(rm);
60+
}
61+
62+
msg.append("Message: ");
63+
msg.append(rm->m_disruptiveMessage);
64+
msg.append(rm->m_match);
65+
msg.append(" [file \"" + std::string(rm->m_ruleFile) + "\"]");
66+
msg.append(" [line \"" + std::to_string(rm->m_ruleLine) + "\"]");
67+
msg.append(" [id \"" + std::to_string(rm->m_ruleId) + "\"]");
68+
msg.append(" [rev \"" + rm->m_rev + "\"]");
69+
msg.append(" [msg \"" + rm->m_message + "\"]");
70+
msg.append(" [data \"" + rm->m_data + "\"]");
71+
msg.append(" [severity \"" +
72+
std::to_string(rm->m_severity) + "\"]");
73+
msg.append(" [ver \"" + rm->m_ver + "\"]");
74+
msg.append(" [maturity \"" + std::to_string(rm->m_maturity) + "\"]");
75+
msg.append(" [accuracy \"" + std::to_string(rm->m_accuracy) + "\"]");
76+
for (auto &a : rm->m_tags) {
77+
msg.append(" [tag \"" + a + "\"]");
78+
}
79+
msg.append(" [ref \"" + rm->m_reference + "\"]");
80+
81+
return modsecurity::utils::string::toHexIfNeeded(msg);
82+
}
5683

5784
std::string RuleMessage::noClientErrorLog(const RuleMessage *rm) {
5885
std::string msg;

src/transaction.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1485,7 +1485,11 @@ std::string Transaction::toOldAuditLogFormat(int parts,
14851485
if (parts & audit_log::AuditLog::HAuditLogPart) {
14861486
audit_log << "--" << trailer << "-" << "H--" << std::endl;
14871487
for (auto a : m_rulesMessages) {
1488-
audit_log << a.noClientErrorLog() << std::endl;
1488+
if (a.m_isDisruptive == true) {
1489+
audit_log << a.noClientErrorLog(true) << std::endl;
1490+
} else {
1491+
audit_log << a.noClientErrorLog() << std::endl;
1492+
}
14891493
}
14901494
audit_log << std::endl;
14911495
/** TODO: write audit_log H part. */

0 commit comments

Comments
 (0)