Skip to content

Commit e555d66

Browse files
author
Felipe Zimmerle
committed
Limits [request|response] body size while saving audit logs
As highlighted at #1519 those may contains binary data which is not a null terminated string.
1 parent 4909713 commit e555d66

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
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+
- Limits [request|response] body size while saving audit logs
6+
[Issue: #1519 - Lasse Karstensen/@lkarsten and Felipe Zimmerle/@zimmerle]
57
- Makes parallel logging to work when SELinux is enabled.
68
[Issue: #1562 - David Buckle/@met3or]
79
- Adds possibility to run the pm operator inside a mutex to avoid concurrent

headers/modsecurity/transaction.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@ typedef struct Rules_t Rules;
4848
#include "modsecurity/collection/collection.h"
4949
#include "modsecurity/variable_origin.h"
5050

51+
#define LOGFY_ADD_N(a, b, c) \
52+
yajl_gen_string(g, reinterpret_cast<const unsigned char*>(a), strlen(a)); \
53+
if (b == NULL) { \
54+
yajl_gen_string(g, reinterpret_cast<const unsigned char*>(""), \
55+
strlen("")); \
56+
} else { \
57+
yajl_gen_string(g, reinterpret_cast<const unsigned char*>(b), \
58+
c); \
59+
}
60+
5161

5262
#define LOGFY_ADD(a, b) \
5363
yajl_gen_string(g, reinterpret_cast<const unsigned char*>(a), strlen(a)); \

src/transaction.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,8 +1549,7 @@ std::string Transaction::toJSON(int parts) {
15491549
LOGFY_ADD("uri", this->m_uri);
15501550

15511551
if (parts & audit_log::AuditLog::CAuditLogPart) {
1552-
// FIXME: check for the binary content size.
1553-
LOGFY_ADD("body", this->m_requestBody.str().c_str());
1552+
LOGFY_ADD_N("body", this->m_requestBody.str().c_str(), this->m_requestBody.size());
15541553
}
15551554

15561555
/* request headers */
@@ -1580,7 +1579,7 @@ std::string Transaction::toJSON(int parts) {
15801579
yajl_gen_map_open(g);
15811580

15821581
if (parts & audit_log::AuditLog::GAuditLogPart) {
1583-
LOGFY_ADD("body", this->m_responseBody.str().c_str());
1582+
LOGFY_ADD_N("body", this->m_responseBody.str().c_str(), this->m_responseBody.size());
15841583
}
15851584
LOGFY_ADD_NUM("http_code", m_httpCodeReturned);
15861585

0 commit comments

Comments
 (0)