Skip to content

Commit 931397f

Browse files
authored
Merge pull request owasp-modsecurity#3553 from meirdev/v3/add-is-interrupted-to-json-log
Add is_interrupted flag in the audit JSON log
2 parents 84783d0 + 1fd14c6 commit 931397f

3 files changed

Lines changed: 114 additions & 0 deletions

File tree

headers/modsecurity/transaction.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,14 @@ class Transaction : public TransactionAnchoredVariables, public TransactionSecMa
594594
std::vector<ModSecurityIntervention> m_actions;
595595
ModSecurityIntervention m_it;
596596

597+
/**
598+
* Sticky flag: set to true the first time the connector consumes a
599+
* disruptive intervention via Transaction::intervention(). Unlike
600+
* m_it.disruptive, this is NOT cleared by intervention::reset(), so
601+
* it remains a reliable signal at audit-log time.
602+
*/
603+
bool m_isInterrupted = false;
604+
597605
/**
598606
* Holds the creation time stamp, using std::time.
599607
*

src/transaction.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,6 +1366,7 @@ int Transaction::processLogging() {
13661366
bool Transaction::intervention(ModSecurityIntervention *it) {
13671367
const auto disruptive = m_it.disruptive;
13681368
if (m_it.disruptive) {
1369+
m_isInterrupted = true;
13691370
if (m_it.url) {
13701371
it->url = strdup(m_it.url);
13711372
} else {
@@ -1595,6 +1596,10 @@ std::string Transaction::toJSON(int parts) {
15951596
LOGFY_ADD_NUM("host_port", m_serverPort);
15961597
LOGFY_ADD("unique_id", m_id);
15971598

1599+
yajl_gen_string(g, reinterpret_cast<const unsigned char*>("is_interrupted"),
1600+
strlen("is_interrupted"));
1601+
yajl_gen_bool(g, m_isInterrupted);
1602+
15981603
/* request */
15991604
yajl_gen_string(g, reinterpret_cast<const unsigned char*>("request"),
16001605
strlen("request"));

test/test-cases/regression/auditlog.json

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,5 +782,106 @@
782782
"SecAuditLogType Serial",
783783
"SecAuditLogRelevantStatus \"^(?:5|4(?!04))\""
784784
]
785+
},
786+
{
787+
"enabled": 1,
788+
"version_min": 300000,
789+
"version_max": 0,
790+
"title": "auditlog : is_interrupted is true when a disruptive rule blocks the request",
791+
"client": {
792+
"ip": "200.249.12.31",
793+
"port": 2313
794+
},
795+
"server": {
796+
"ip": "200.249.12.31",
797+
"port": 80
798+
},
799+
"request": {
800+
"headers": {
801+
"Host": "www.modsecurity.org",
802+
"Content-Length": "0"
803+
},
804+
"uri": "/test.pl?param1=test",
805+
"method": "GET",
806+
"http_version": 1.1,
807+
"body": [
808+
""
809+
]
810+
},
811+
"response": {
812+
"headers": {
813+
"Content-Type": "plain/text\n\r",
814+
"Content-Length": "4"
815+
},
816+
"body": [
817+
"test"
818+
]
819+
},
820+
"expected": {
821+
"audit_log": "\"is_interrupted\":true",
822+
"http_code": 403
823+
},
824+
"rules": [
825+
"SecRuleEngine On",
826+
"SecRule ARGS \"@contains test\" \"id:1900,phase:1,deny,auditlog\"",
827+
"SecAuditEngine RelevantOnly",
828+
"SecAuditLogFormat JSON",
829+
"SecAuditLogParts ABCFHZ",
830+
"SecAuditLog /tmp/audit_test_is_interrupted_true.log",
831+
"SecAuditLogDirMode 0766",
832+
"SecAuditLogFileMode 0600",
833+
"SecAuditLogType Serial",
834+
"SecAuditLogRelevantStatus \"^(?:5|4(?!04))\""
835+
]
836+
},
837+
{
838+
"enabled": 1,
839+
"version_min": 300000,
840+
"version_max": 0,
841+
"title": "auditlog : is_interrupted is false when SecRuleEngine is DetectionOnly",
842+
"client": {
843+
"ip": "200.249.12.31",
844+
"port": 2313
845+
},
846+
"server": {
847+
"ip": "200.249.12.31",
848+
"port": 80
849+
},
850+
"request": {
851+
"headers": {
852+
"Host": "www.modsecurity.org",
853+
"Content-Length": "0"
854+
},
855+
"uri": "/test.pl?param1=test",
856+
"method": "GET",
857+
"http_version": 1.1,
858+
"body": [
859+
""
860+
]
861+
},
862+
"response": {
863+
"headers": {
864+
"Content-Type": "plain/text\n\r",
865+
"Content-Length": "4"
866+
},
867+
"body": [
868+
"test"
869+
]
870+
},
871+
"expected": {
872+
"audit_log": "\"is_interrupted\":false",
873+
"http_code": 200
874+
},
875+
"rules": [
876+
"SecRuleEngine DetectionOnly",
877+
"SecRule ARGS \"@contains test\" \"id:1901,phase:1,deny,auditlog\"",
878+
"SecAuditEngine On",
879+
"SecAuditLogFormat JSON",
880+
"SecAuditLogParts ABCFHZ",
881+
"SecAuditLog /tmp/audit_test_is_interrupted_false.log",
882+
"SecAuditLogDirMode 0766",
883+
"SecAuditLogFileMode 0600",
884+
"SecAuditLogType Serial"
885+
]
785886
}
786887
]

0 commit comments

Comments
 (0)