mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-08-14 05:45:59 +03:00
Refactoring on Transaction class: adding comments and renaming variables
This commit is contained in:
parent
6f1e6f37d7
commit
4db5cc7d26
@ -24,7 +24,7 @@ namespace modsecurity {
|
||||
namespace actions {
|
||||
|
||||
bool AuditLog::evaluate(Rule *rule, Transaction *transaction) {
|
||||
transaction->save_in_auditlog = true;
|
||||
transaction->m_toBeSavedInAuditlogs = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -38,7 +38,7 @@ bool Block::evaluate(Rule *rule, Transaction *transaction) {
|
||||
#endif
|
||||
for (Action *a : rule->actions_runtime_pos) {
|
||||
if (a->isDisruptive() == true) {
|
||||
transaction->actions.push_back(a);
|
||||
transaction->m_actions.push_back(a);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
@ -36,7 +36,7 @@ CtlAuditLogParts::CtlAuditLogParts(std::string action)
|
||||
}
|
||||
|
||||
bool CtlAuditLogParts::evaluate(Rule *rule, Transaction *transaction) {
|
||||
transaction->auditLogModifier.push_back(
|
||||
transaction->m_auditLogModifier.push_back(
|
||||
std::make_pair(mPartsAction, mParts));
|
||||
return true;
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ bool Deny::evaluate(Rule *rule, Transaction *transaction) {
|
||||
#ifndef NO_LOGS
|
||||
transaction->debug(8, "Running action deny");
|
||||
#endif
|
||||
transaction->actions.push_back(this);
|
||||
transaction->m_actions.push_back(this);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,7 @@ namespace modsecurity {
|
||||
namespace actions {
|
||||
|
||||
bool Log::evaluate(Rule *rule, Transaction *transaction) {
|
||||
transaction->save_in_auditlog = true;
|
||||
transaction->m_toBeSavedInAuditlogs = true;
|
||||
/* FIXME: transaction->serverLog("Something...."); */
|
||||
transaction->debug(9, "Saving transaction to logs");
|
||||
return true;
|
||||
|
@ -39,7 +39,7 @@ bool LogData::evaluate(Rule *rule, Transaction *transaction) {
|
||||
#ifndef NO_LOGS
|
||||
transaction->debug(9, "Saving msg: " + msg);
|
||||
#endif
|
||||
transaction->rulesMessages.push_back(msg);
|
||||
transaction->m_rulesMessages.push_back(msg);
|
||||
transaction->serverLog(msg);
|
||||
return true;
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ bool Msg::evaluate(Rule *rule, Transaction *transaction) {
|
||||
#ifndef NO_LOGS
|
||||
transaction->debug(9, "Saving msg: " + msg);
|
||||
#endif
|
||||
transaction->rulesMessages.push_back(msg);
|
||||
transaction->m_rulesMessages.push_back(msg);
|
||||
transaction->serverLog(msg);
|
||||
return true;
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ namespace modsecurity {
|
||||
namespace actions {
|
||||
|
||||
bool NoAuditLog::evaluate(Rule *rule, Transaction *transaction) {
|
||||
transaction->do_not_save_in_auditlog = true;
|
||||
transaction->m_toNotBeSavedInAuditLogs = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,7 @@ Pass::Pass(std::string action)
|
||||
|
||||
|
||||
bool Pass::evaluate(Rule *rule, Transaction *transaction) {
|
||||
transaction->actions.clear();
|
||||
transaction->m_actions.clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,7 @@ Redirect::Redirect(const std::string& action)
|
||||
|
||||
bool Redirect::evaluate(Rule *rule, Transaction *transaction) {
|
||||
m_urlExpanded = MacroExpansion::expand(m_url, transaction);
|
||||
transaction->actions.push_back(this);
|
||||
transaction->m_actions.push_back(this);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -54,11 +54,11 @@ bool Severity::evaluate(Rule *rule, Transaction *transaction) {
|
||||
#ifndef NO_LOGS
|
||||
transaction->debug(9, "This rule severity is: " + \
|
||||
std::to_string(this->m_severity) + " current transaction is: " + \
|
||||
std::to_string(transaction->highest_severity));
|
||||
std::to_string(transaction->m_highestSeverityAction));
|
||||
#endif
|
||||
|
||||
if (transaction->highest_severity > this->m_severity) {
|
||||
transaction->highest_severity = this->m_severity;
|
||||
if (transaction->m_highestSeverityAction > this->m_severity) {
|
||||
transaction->m_highestSeverityAction = this->m_severity;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ Status::Status(std::string action)
|
||||
|
||||
|
||||
bool Status::evaluate(Rule *rule, Transaction *transaction) {
|
||||
transaction->actions.push_back(this);
|
||||
transaction->m_actions.push_back(this);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -39,7 +39,7 @@ bool Tag::evaluate(Rule *rule, Transaction *transaction) {
|
||||
#ifndef NO_LOGS
|
||||
transaction->debug(9, "Rule tag: " + tag);
|
||||
#endif
|
||||
transaction->ruleTags.push_back(tag);
|
||||
transaction->m_ruleTags.push_back(tag);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -225,8 +225,8 @@ bool AuditLog::saveIfRelevant(Transaction *transaction) {
|
||||
|
||||
|
||||
bool AuditLog::saveIfRelevant(Transaction *transaction, int parts) {
|
||||
if (this->isRelevant(transaction->httpCodeReturned) == false &&
|
||||
transaction->save_in_auditlog == false) {
|
||||
if (this->isRelevant(transaction->m_httpCodeReturned) == false &&
|
||||
transaction->m_toBeSavedInAuditlogs == false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -235,7 +235,7 @@ bool AuditLog::saveIfRelevant(Transaction *transaction, int parts) {
|
||||
* we won't save it.
|
||||
*
|
||||
*/
|
||||
if (transaction->do_not_save_in_auditlog == true) {
|
||||
if (transaction->m_toNotBeSavedInAuditLogs == true) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,7 @@ std::string AuditLogWriter::file_name(const std::string& unique_id) {
|
||||
*
|
||||
*/
|
||||
bool AuditLogWriter::write(Transaction *transaction, int parts) {
|
||||
std::cout << transaction->to_json(0) << std::endl;
|
||||
std::cout << transaction->toJSON(0) << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -92,23 +92,23 @@ bool AuditLogWriterParallel::init() {
|
||||
bool AuditLogWriterParallel::write(Transaction *transaction, int parts) {
|
||||
FILE *fp;
|
||||
int fd;
|
||||
std::string log = transaction->to_json(parts);
|
||||
std::string fileName = logFilePath(&transaction->timeStamp,
|
||||
std::string log = transaction->toJSON(parts);
|
||||
std::string fileName = logFilePath(&transaction->m_timeStamp,
|
||||
YearMonthDayDirectory | YearMonthDayAndTimeDirectory
|
||||
| YearMonthDayAndTimeFileName);
|
||||
|
||||
std::string logPath = m_audit->m_storage_dir;
|
||||
fileName = logPath + fileName + "-" + transaction->id;
|
||||
fileName = logPath + fileName + "-" + transaction->m_id;
|
||||
|
||||
if (logPath.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
createDir((logPath +
|
||||
logFilePath(&transaction->timeStamp, YearMonthDayDirectory)).c_str(),
|
||||
logFilePath(&transaction->m_timeStamp, YearMonthDayDirectory)).c_str(),
|
||||
m_audit->directoryPermission);
|
||||
createDir((logPath +
|
||||
logFilePath(&transaction->timeStamp, YearMonthDayDirectory
|
||||
logFilePath(&transaction->m_timeStamp, YearMonthDayDirectory
|
||||
| YearMonthDayAndTimeDirectory)).c_str(),
|
||||
m_audit->directoryPermission);
|
||||
|
||||
|
@ -19,26 +19,27 @@
|
||||
#include <yajl/yajl_tree.h>
|
||||
#include <yajl/yajl_gen.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <ctime>
|
||||
#include <iostream>
|
||||
#include <unordered_map>
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
#include <iomanip>
|
||||
#include <set>
|
||||
#include <cstdio>
|
||||
#include <ctime>
|
||||
#include <fstream>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <set>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "modsecurity/modsecurity.h"
|
||||
#include "modsecurity/intervention.h"
|
||||
#include "actions/action.h"
|
||||
#include "actions/deny.h"
|
||||
#include "src/utils.h"
|
||||
#include "modsecurity/intervention.h"
|
||||
#include "modsecurity/modsecurity.h"
|
||||
#include "request_body_processor/multipart.h"
|
||||
#include "src/audit_log.h"
|
||||
#include "src/unique_id.h"
|
||||
#include "request_body_processor/multipart.h"
|
||||
#include "src/utils.h"
|
||||
|
||||
using modsecurity::actions::Action;
|
||||
using modsecurity::RequestBodyProcessor::Multipart;
|
||||
@ -89,7 +90,7 @@ Transaction::Transaction(ModSecurity *ms, Rules *rules, void *logCbData)
|
||||
m_clientPort(0),
|
||||
m_serverPort(0),
|
||||
m_uri(""),
|
||||
m_protocol(""),
|
||||
m_method(""),
|
||||
m_httpVersion(""),
|
||||
m_rules(rules),
|
||||
m_toBeSavedInAuditlogs(false),
|
||||
@ -107,7 +108,7 @@ Transaction::Transaction(ModSecurity *ms, Rules *rules, void *logCbData)
|
||||
m_responseHeadersNames(NULL),
|
||||
m_responseContentType(NULL),
|
||||
m_marker(""),
|
||||
start(cpu_seconds()),
|
||||
m_creationTimeStamp(cpu_seconds()),
|
||||
m_logCbData(logCbData),
|
||||
m_ms(ms) {
|
||||
m_id = std::to_string(this->m_timeStamp) + \
|
||||
@ -235,7 +236,7 @@ int Transaction::processConnection(const char *client, int cPort,
|
||||
*
|
||||
* @param transaction ModSecurity transaction.
|
||||
* @param uri Uri.
|
||||
* @param protocol Protocol (GET, POST, PUT).
|
||||
* @param method Method (GET, POST, PUT).
|
||||
* @param http_version Http version (1.0, 1.2, 2.0).
|
||||
*
|
||||
* @returns If the operation was successful or not.
|
||||
@ -243,14 +244,14 @@ int Transaction::processConnection(const char *client, int cPort,
|
||||
* @retval false Operation failed.
|
||||
*
|
||||
*/
|
||||
int Transaction::processURI(const char *uri, const char *protocol,
|
||||
int Transaction::processURI(const char *uri, const char *method,
|
||||
const char *http_version) {
|
||||
|
||||
#ifndef NO_LOGS
|
||||
debug(4, "Starting phase URI. (SecRules 0 + 1/2)");
|
||||
#endif
|
||||
|
||||
m_protocol = protocol;
|
||||
m_method = method;
|
||||
m_httpVersion = http_version;
|
||||
m_uri = uri;
|
||||
std::string uri_s(uri);
|
||||
@ -259,7 +260,7 @@ int Transaction::processURI(const char *uri, const char *protocol,
|
||||
size_t pos = m_uri_decoded.find("?");
|
||||
size_t pos_raw = uri_s.find("?");
|
||||
|
||||
m_collections.store("REQUEST_LINE", std::string(protocol) + " " +
|
||||
m_collections.store("REQUEST_LINE", std::string(method) + " " +
|
||||
std::string(uri) + " HTTP/" + std::string(http_version));
|
||||
|
||||
if (pos_raw != std::string::npos) {
|
||||
@ -282,7 +283,7 @@ int Transaction::processURI(const char *uri, const char *protocol,
|
||||
path_info.length() - offset);
|
||||
m_collections.store("REQUEST_BASENAME", basename);
|
||||
}
|
||||
m_collections.store("REQUEST_METHOD", protocol);
|
||||
m_collections.store("REQUEST_METHOD", method);
|
||||
m_collections.store("REQUEST_PROTOCOL",
|
||||
"HTTP/" + std::string(http_version));
|
||||
|
||||
@ -1257,7 +1258,7 @@ std::string Transaction::toOldAuditLogFormatIndex(const std::string &filename,
|
||||
ss << tstr << " ";
|
||||
|
||||
ss << "\"";
|
||||
ss << this->m_protocol << " ";
|
||||
ss << this->m_method << " ";
|
||||
ss << this->m_uri << " ";
|
||||
ss << "HTTP/" << m_httpVersion;
|
||||
ss << "\" ";
|
||||
@ -1304,7 +1305,7 @@ std::string Transaction::toOldAuditLogFormat(int parts,
|
||||
|
||||
if (parts & AuditLog::BAuditLogPart) {
|
||||
audit_log << "--" << trailer << "-" << "B--" << std::endl;
|
||||
audit_log << this->m_protocol << " " << this->m_uri << " " << "HTTP/";
|
||||
audit_log << this->m_method << " " << this->m_uri << " " << "HTTP/";
|
||||
audit_log << this->m_httpVersion << std::endl;
|
||||
|
||||
for (auto h : m_collections.m_transient) {
|
||||
@ -1410,7 +1411,7 @@ std::string Transaction::toJSON(int parts) {
|
||||
strlen("request"));
|
||||
yajl_gen_map_open(g);
|
||||
|
||||
LOGFY_ADD("protocol", m_protocol);
|
||||
LOGFY_ADD("protocol", m_method);
|
||||
LOGFY_ADD_INT("http_version", m_httpVersion);
|
||||
LOGFY_ADD("uri", this->m_uri);
|
||||
|
||||
|
@ -31,7 +31,7 @@ void Duration::evaluateInternal(Transaction *transaction,
|
||||
std::vector<const transaction::Variable *> *l) {
|
||||
std::string res;
|
||||
|
||||
double e = cpu_seconds() - transaction->start;
|
||||
double e = cpu_seconds() - transaction->m_creationTimeStamp;
|
||||
|
||||
res = std::to_string(e);
|
||||
|
||||
|
@ -29,7 +29,7 @@ namespace Variables {
|
||||
void HighestSeverity::evaluateInternal(Transaction *transaction,
|
||||
std::vector<const transaction::Variable *> *l) {
|
||||
l->push_back(new transaction::Variable("HIGHEST_SEVERITY",
|
||||
std::to_string(transaction->highest_severity)));
|
||||
std::to_string(transaction->m_highestSeverityAction)));
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user