mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-09-30 03:34:29 +03:00
Refactoring on rulesProperties class
Among of other things the merge process was improved to detect if certain properties were set on the origin rule set.
This commit is contained in:
@@ -27,14 +27,14 @@ namespace Parser {
|
||||
Driver::Driver()
|
||||
: trace_scanning(false),
|
||||
trace_parsing(false) {
|
||||
audit_log = new audit_log::AuditLog();
|
||||
audit_log->refCountIncrease();
|
||||
m_auditLog = new audit_log::AuditLog();
|
||||
m_auditLog->refCountIncrease();
|
||||
}
|
||||
|
||||
|
||||
Driver::~Driver() {
|
||||
if (audit_log != NULL) {
|
||||
audit_log->refCountDecreaseAndCheck();
|
||||
if (m_auditLog != NULL) {
|
||||
m_auditLog->refCountDecreaseAndCheck();
|
||||
}
|
||||
delete loc.back();
|
||||
}
|
||||
@@ -52,8 +52,8 @@ int Driver::addSecMarker(std::string marker) {
|
||||
|
||||
int Driver::addSecAction(Rule *rule) {
|
||||
if (rule->phase > ModSecurity::Phases::NUMBER_OF_PHASES) {
|
||||
parserError << "Unknown phase: " << std::to_string(rule->phase);
|
||||
parserError << std::endl;
|
||||
m_parserError << "Unknown phase: " << std::to_string(rule->phase);
|
||||
m_parserError << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -64,8 +64,8 @@ int Driver::addSecAction(Rule *rule) {
|
||||
|
||||
int Driver::addSecRule(Rule *rule) {
|
||||
if (rule->phase > ModSecurity::Phases::NUMBER_OF_PHASES) {
|
||||
parserError << "Unknown phase: " << std::to_string(rule->phase);
|
||||
parserError << std::endl;
|
||||
m_parserError << "Unknown phase: " << std::to_string(rule->phase);
|
||||
m_parserError << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -91,16 +91,16 @@ int Driver::addSecRule(Rule *rule) {
|
||||
* by other rule
|
||||
*/
|
||||
if (rule->rule_id == 0) {
|
||||
parserError << "Rules must have an ID. File: ";
|
||||
parserError << rule->m_fileName << " at line: ";
|
||||
parserError << std::to_string(rule->m_lineNumber) << std::endl;
|
||||
m_parserError << "Rules must have an ID. File: ";
|
||||
m_parserError << rule->m_fileName << " at line: ";
|
||||
m_parserError << std::to_string(rule->m_lineNumber) << std::endl;
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < ModSecurity::Phases::NUMBER_OF_PHASES; i++) {
|
||||
std::vector<Rule *> rules = this->rules[i];
|
||||
for (int j = 0; j < rules.size(); j++) {
|
||||
if (rules[j]->rule_id == rule->rule_id) {
|
||||
parserError << "Rule id: " << std::to_string(rule->rule_id) \
|
||||
m_parserError << "Rule id: " << std::to_string(rule->rule_id) \
|
||||
<< " is duplicated" << std::endl;
|
||||
return false;
|
||||
}
|
||||
@@ -129,8 +129,8 @@ int Driver::parse(const std::string &f, const std::string &ref) {
|
||||
int res = parser.parse();
|
||||
scan_end();
|
||||
|
||||
if (audit_log->init() == false) {
|
||||
parserError << "Problems while initializing the audit logs" \
|
||||
if (m_auditLog->init() == false) {
|
||||
m_parserError << "Problems while initializing the audit logs" \
|
||||
<< std::endl;
|
||||
return false;
|
||||
}
|
||||
@@ -144,7 +144,7 @@ int Driver::parseFile(const std::string &f) {
|
||||
std::string str;
|
||||
|
||||
if (t.is_open() == false) {
|
||||
parserError << "Failed to open the file: " << f << std::endl;
|
||||
m_parserError << "Failed to open the file: " << f << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -166,21 +166,21 @@ void Driver::error(const yy::location& l, const std::string& m) {
|
||||
|
||||
void Driver::error(const yy::location& l, const std::string& m,
|
||||
const std::string& c) {
|
||||
if (parserError.tellp() == 0) {
|
||||
parserError << "Rules error. ";
|
||||
if (m_parserError.tellp() == 0) {
|
||||
m_parserError << "Rules error. ";
|
||||
if (ref.empty() == false) {
|
||||
parserError << "File: " << ref.back() << ". ";
|
||||
m_parserError << "File: " << ref.back() << ". ";
|
||||
}
|
||||
parserError << "Line: " << l.end.line << ". ";
|
||||
parserError << "Column: " << l.end.column - 1 << ". ";
|
||||
m_parserError << "Line: " << l.end.line << ". ";
|
||||
m_parserError << "Column: " << l.end.column - 1 << ". ";
|
||||
}
|
||||
|
||||
if (m.empty() == false) {
|
||||
parserError << "" << m << " ";
|
||||
m_parserError << "" << m << " ";
|
||||
}
|
||||
|
||||
if (c.empty() == false) {
|
||||
parserError << c;
|
||||
m_parserError << c;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -18,6 +18,7 @@ class Driver;
|
||||
}
|
||||
|
||||
#include "modsecurity/modsecurity.h"
|
||||
#include "modsecurity/rules_properties.h"
|
||||
|
||||
#include "actions/accuracy.h"
|
||||
#include "actions/action.h"
|
||||
@@ -328,51 +329,51 @@ audit_log:
|
||||
/* SecAuditLogDirMode */
|
||||
CONFIG_DIR_AUDIT_DIR_MOD
|
||||
{
|
||||
driver.audit_log->setStorageDirMode(strtol($1.c_str(), NULL, 8));
|
||||
driver.m_auditLog->setStorageDirMode(strtol($1.c_str(), NULL, 8));
|
||||
}
|
||||
|
||||
/* SecAuditLogStorageDir */
|
||||
| CONFIG_DIR_AUDIT_DIR
|
||||
{
|
||||
driver.audit_log->setStorageDir($1);
|
||||
driver.m_auditLog->setStorageDir($1);
|
||||
}
|
||||
|
||||
/* SecAuditEngine */
|
||||
| CONFIG_DIR_AUDIT_ENG CONFIG_VALUE_RELEVANT_ONLY
|
||||
{
|
||||
driver.audit_log->setStatus(modsecurity::audit_log::AuditLog::RelevantOnlyAuditLogStatus);
|
||||
driver.m_auditLog->setStatus(modsecurity::audit_log::AuditLog::RelevantOnlyAuditLogStatus);
|
||||
}
|
||||
| CONFIG_DIR_AUDIT_ENG CONFIG_VALUE_OFF
|
||||
{
|
||||
driver.audit_log->setStatus(modsecurity::audit_log::AuditLog::OffAuditLogStatus);
|
||||
driver.m_auditLog->setStatus(modsecurity::audit_log::AuditLog::OffAuditLogStatus);
|
||||
}
|
||||
| CONFIG_DIR_AUDIT_ENG CONFIG_VALUE_ON
|
||||
{
|
||||
driver.audit_log->setStatus(modsecurity::audit_log::AuditLog::OnAuditLogStatus);
|
||||
driver.m_auditLog->setStatus(modsecurity::audit_log::AuditLog::OnAuditLogStatus);
|
||||
}
|
||||
|
||||
/* SecAuditLogFileMode */
|
||||
| CONFIG_DIR_AUDIT_FLE_MOD
|
||||
{
|
||||
driver.audit_log->setFileMode(strtol($1.c_str(), NULL, 8));
|
||||
driver.m_auditLog->setFileMode(strtol($1.c_str(), NULL, 8));
|
||||
}
|
||||
|
||||
/* SecAuditLog2 */
|
||||
| CONFIG_DIR_AUDIT_LOG2
|
||||
{
|
||||
driver.audit_log->setFilePath2($1);
|
||||
driver.m_auditLog->setFilePath2($1);
|
||||
}
|
||||
|
||||
/* SecAuditLogParts */
|
||||
| CONFIG_DIR_AUDIT_LOG_P
|
||||
{
|
||||
driver.audit_log->setParts($1);
|
||||
driver.m_auditLog->setParts($1);
|
||||
}
|
||||
|
||||
/* SecAuditLog */
|
||||
| CONFIG_DIR_AUDIT_LOG
|
||||
{
|
||||
driver.audit_log->setFilePath1($1);
|
||||
driver.m_auditLog->setFilePath1($1);
|
||||
}
|
||||
|
||||
/* SecAuditLogRelevantStatus */
|
||||
@@ -381,51 +382,53 @@ audit_log:
|
||||
std::string relevant_status($1);
|
||||
relevant_status.pop_back();
|
||||
relevant_status.erase(0, 1);
|
||||
driver.audit_log->setRelevantStatus(relevant_status);
|
||||
driver.m_auditLog->setRelevantStatus(relevant_status);
|
||||
}
|
||||
|
||||
/* SecAuditLogType */
|
||||
| CONFIG_DIR_AUDIT_TPE CONFIG_VALUE_SERIAL
|
||||
{
|
||||
driver.audit_log->setType(modsecurity::audit_log::AuditLog::SerialAuditLogType);
|
||||
driver.m_auditLog->setType(modsecurity::audit_log::AuditLog::SerialAuditLogType);
|
||||
}
|
||||
| CONFIG_DIR_AUDIT_TPE CONFIG_VALUE_PARALLEL
|
||||
{
|
||||
driver.audit_log->setType(modsecurity::audit_log::AuditLog::ParallelAuditLogType);
|
||||
driver.m_auditLog->setType(modsecurity::audit_log::AuditLog::ParallelAuditLogType);
|
||||
}
|
||||
| CONFIG_DIR_AUDIT_TPE CONFIG_VALUE_HTTPS
|
||||
{
|
||||
driver.audit_log->setType(modsecurity::audit_log::AuditLog::HttpsAuditLogType);
|
||||
driver.m_auditLog->setType(modsecurity::audit_log::AuditLog::HttpsAuditLogType);
|
||||
}
|
||||
|
||||
/* Upload */
|
||||
| CONFIG_UPDLOAD_KEEP_FILES CONFIG_VALUE_ON
|
||||
{
|
||||
driver.uploadKeepFiles = true;
|
||||
driver.m_uploadKeepFiles = modsecurity::RulesProperties::TrueConfigBoolean;
|
||||
}
|
||||
| CONFIG_UPDLOAD_KEEP_FILES CONFIG_VALUE_OFF
|
||||
{
|
||||
driver.uploadKeepFiles = false;
|
||||
driver.m_uploadKeepFiles = modsecurity::RulesProperties::FalseConfigBoolean;
|
||||
}
|
||||
| CONFIG_UPLOAD_FILE_LIMIT
|
||||
{
|
||||
driver.uploadFileLimit = strtol($1.c_str(), NULL, 10);
|
||||
driver.m_uploadFileLimit.m_set = true;
|
||||
driver.m_uploadFileLimit.m_value = strtol($1.c_str(), NULL, 10);
|
||||
}
|
||||
| CONFIG_UPLOAD_FILE_MODE
|
||||
{
|
||||
driver.uploadFileMode = strtol($1.c_str(), NULL, 8);
|
||||
driver.m_uploadFileMode.m_set = true;
|
||||
driver.m_uploadFileMode.m_value = strtol($1.c_str(), NULL, 8);
|
||||
}
|
||||
| CONFIG_UPLOAD_DIR
|
||||
{
|
||||
driver.uploadDirectory = $1;
|
||||
driver.m_uploadDirectory = $1;
|
||||
}
|
||||
| CONFIG_UPDLOAD_SAVE_TMP_FILES CONFIG_VALUE_ON
|
||||
{
|
||||
driver.tmpSaveUploadedFiles = true;
|
||||
driver.m_tmpSaveUploadedFiles = modsecurity::RulesProperties::TrueConfigBoolean;
|
||||
}
|
||||
| CONFIG_UPDLOAD_SAVE_TMP_FILES CONFIG_VALUE_OFF
|
||||
{
|
||||
driver.tmpSaveUploadedFiles = false;
|
||||
driver.m_tmpSaveUploadedFiles = modsecurity::RulesProperties::FalseConfigBoolean;
|
||||
}
|
||||
;
|
||||
|
||||
@@ -581,35 +584,35 @@ expression:
|
||||
}
|
||||
| CONFIG_DIR_RULE_ENG CONFIG_VALUE_OFF
|
||||
{
|
||||
driver.secRuleEngine = modsecurity::Rules::DisabledRuleEngine;
|
||||
driver.m_secRuleEngine = modsecurity::Rules::DisabledRuleEngine;
|
||||
}
|
||||
| CONFIG_DIR_RULE_ENG CONFIG_VALUE_ON
|
||||
{
|
||||
driver.secRuleEngine = modsecurity::Rules::EnabledRuleEngine;
|
||||
driver.m_secRuleEngine = modsecurity::Rules::EnabledRuleEngine;
|
||||
}
|
||||
| CONFIG_DIR_RULE_ENG CONFIG_VALUE_DETC
|
||||
{
|
||||
driver.secRuleEngine = modsecurity::Rules::DetectionOnlyRuleEngine;
|
||||
driver.m_secRuleEngine = modsecurity::Rules::DetectionOnlyRuleEngine;
|
||||
}
|
||||
| CONFIG_DIR_REQ_BODY CONFIG_VALUE_ON
|
||||
{
|
||||
driver.secRequestBodyAccess = true;
|
||||
driver.m_secRequestBodyAccess = modsecurity::RulesProperties::TrueConfigBoolean;
|
||||
}
|
||||
| CONFIG_DIR_REQ_BODY CONFIG_VALUE_OFF
|
||||
{
|
||||
driver.secRequestBodyAccess = false;
|
||||
driver.m_secRequestBodyAccess = modsecurity::RulesProperties::FalseConfigBoolean;
|
||||
}
|
||||
| CONFIG_DIR_RES_BODY CONFIG_VALUE_ON
|
||||
{
|
||||
driver.secResponseBodyAccess = true;
|
||||
driver.m_secResponseBodyAccess = modsecurity::RulesProperties::TrueConfigBoolean;
|
||||
}
|
||||
| CONFIG_DIR_RES_BODY CONFIG_VALUE_OFF
|
||||
{
|
||||
driver.secResponseBodyAccess = false;
|
||||
driver.m_secResponseBodyAccess = modsecurity::RulesProperties::FalseConfigBoolean;
|
||||
}
|
||||
| CONFIG_COMPONENT_SIG
|
||||
{
|
||||
driver.components.push_back($1);
|
||||
driver.m_components.push_back($1);
|
||||
}
|
||||
| CONFIG_SEC_RULE_REMOVE_BY_ID
|
||||
{
|
||||
@@ -671,43 +674,47 @@ expression:
|
||||
/* Body limits */
|
||||
| CONFIG_DIR_REQ_BODY_LIMIT
|
||||
{
|
||||
driver.requestBodyLimit = atoi($1.c_str());
|
||||
driver.m_requestBodyLimit.m_set = true;
|
||||
driver.m_requestBodyLimit.m_value = atoi($1.c_str());
|
||||
}
|
||||
| CONFIG_DIR_REQ_BODY_NO_FILES_LIMIT
|
||||
{
|
||||
driver.requestBodyNoFilesLimit = atoi($1.c_str());
|
||||
driver.m_requestBodyNoFilesLimit.m_set = true;
|
||||
driver.m_requestBodyNoFilesLimit.m_value = atoi($1.c_str());
|
||||
}
|
||||
| CONFIG_DIR_REQ_BODY_IN_MEMORY_LIMIT
|
||||
{
|
||||
driver.requestBodyInMemoryLimit = atoi($1.c_str());
|
||||
driver.m_requestBodyInMemoryLimit.m_set = true;
|
||||
driver.m_requestBodyInMemoryLimit.m_value = atoi($1.c_str());
|
||||
}
|
||||
| CONFIG_DIR_RES_BODY_LIMIT
|
||||
{
|
||||
driver.responseBodyLimit = atoi($1.c_str());
|
||||
driver.m_responseBodyLimit.m_set = true;
|
||||
driver.m_responseBodyLimit.m_value = atoi($1.c_str());
|
||||
}
|
||||
| CONFIG_DIR_REQ_BODY_LIMIT_ACTION CONFIG_VALUE_PROCESS_PARTIAL
|
||||
{
|
||||
driver.requestBodyLimitAction = modsecurity::Rules::BodyLimitAction::ProcessPartialBodyLimitAction;
|
||||
driver.m_requestBodyLimitAction = modsecurity::Rules::BodyLimitAction::ProcessPartialBodyLimitAction;
|
||||
}
|
||||
| CONFIG_DIR_REQ_BODY_LIMIT_ACTION CONFIG_VALUE_REJECT
|
||||
{
|
||||
driver.requestBodyLimitAction = modsecurity::Rules::BodyLimitAction::RejectBodyLimitAction;
|
||||
driver.m_requestBodyLimitAction = modsecurity::Rules::BodyLimitAction::RejectBodyLimitAction;
|
||||
}
|
||||
| CONFIG_DIR_RES_BODY_LIMIT_ACTION CONFIG_VALUE_PROCESS_PARTIAL
|
||||
{
|
||||
driver.responseBodyLimitAction = modsecurity::Rules::BodyLimitAction::ProcessPartialBodyLimitAction;
|
||||
driver.m_responseBodyLimitAction = modsecurity::Rules::BodyLimitAction::ProcessPartialBodyLimitAction;
|
||||
}
|
||||
| CONFIG_DIR_RES_BODY_LIMIT_ACTION CONFIG_VALUE_REJECT
|
||||
{
|
||||
driver.responseBodyLimitAction = modsecurity::Rules::BodyLimitAction::RejectBodyLimitAction;
|
||||
driver.m_responseBodyLimitAction = modsecurity::Rules::BodyLimitAction::RejectBodyLimitAction;
|
||||
}
|
||||
| CONFIG_SEC_REMOTE_RULES_FAIL_ACTION CONFIG_VALUE_ABORT
|
||||
{
|
||||
driver.remoteRulesActionOnFailed = Rules::OnFailedRemoteRulesAction::AbortOnFailedRemoteRulesAction;
|
||||
driver.m_remoteRulesActionOnFailed = Rules::OnFailedRemoteRulesAction::AbortOnFailedRemoteRulesAction;
|
||||
}
|
||||
| CONFIG_SEC_REMOTE_RULES_FAIL_ACTION CONFIG_VALUE_WARN
|
||||
{
|
||||
driver.remoteRulesActionOnFailed = Rules::OnFailedRemoteRulesAction::WarnOnFailedRemoteRulesAction;
|
||||
driver.m_remoteRulesActionOnFailed = Rules::OnFailedRemoteRulesAction::WarnOnFailedRemoteRulesAction;
|
||||
}
|
||||
| CONFIG_DIR_PCRE_MATCH_LIMIT_RECURSION
|
||||
| CONFIG_DIR_PCRE_MATCH_LIMIT
|
||||
@@ -724,11 +731,11 @@ expression:
|
||||
}
|
||||
| CONFIG_XML_EXTERNAL_ENTITY CONFIG_VALUE_OFF
|
||||
{
|
||||
driver.secXMLExternalEntity = false;
|
||||
driver.m_secXMLExternalEntity = modsecurity::RulesProperties::FalseConfigBoolean;
|
||||
}
|
||||
| CONFIG_XML_EXTERNAL_ENTITY CONFIG_VALUE_ON
|
||||
{
|
||||
driver.secXMLExternalEntity = true;
|
||||
driver.m_secXMLExternalEntity = modsecurity::RulesProperties::TrueConfigBoolean;
|
||||
}
|
||||
| CONGIG_DIR_SEC_TMP_DIR
|
||||
| CONGIG_DIR_SEC_DATA_DIR
|
||||
@@ -949,7 +956,7 @@ act:
|
||||
$$ = Action::instantiate($1);
|
||||
|
||||
if ($$->init(&error) == false) {
|
||||
driver.parserError << error;
|
||||
driver.m_parserError << error;
|
||||
YYERROR;
|
||||
}
|
||||
}
|
||||
@@ -1067,7 +1074,7 @@ act:
|
||||
SetSID *setSID = new SetSID($1);
|
||||
|
||||
if (setSID->init(&error) == false) {
|
||||
driver.parserError << error;
|
||||
driver.m_parserError << error;
|
||||
YYERROR;
|
||||
}
|
||||
|
||||
@@ -1079,7 +1086,7 @@ act:
|
||||
SetUID *setUID = new SetUID($1);
|
||||
|
||||
if (setUID->init(&error) == false) {
|
||||
driver.parserError << error;
|
||||
driver.m_parserError << error;
|
||||
YYERROR;
|
||||
}
|
||||
|
||||
@@ -1091,7 +1098,7 @@ act:
|
||||
SetVar *setVar = new SetVar($1);
|
||||
|
||||
if (setVar->init(&error) == false) {
|
||||
driver.parserError << error;
|
||||
driver.m_parserError << error;
|
||||
YYERROR;
|
||||
}
|
||||
|
||||
|
@@ -540,10 +540,10 @@ CONFIG_DIR_UNICODE_MAP_FILE (?i:SecUnicodeMapFile)
|
||||
|
||||
if (ret == false) {
|
||||
BEGIN(INITIAL);
|
||||
if (driver.remoteRulesActionOnFailed == Rules::OnFailedRemoteRulesAction::WarnOnFailedRemoteRulesAction) {
|
||||
if (driver.m_remoteRulesActionOnFailed == Rules::OnFailedRemoteRulesAction::WarnOnFailedRemoteRulesAction) {
|
||||
/** TODO: Implement the server logging mechanism. */
|
||||
}
|
||||
if (driver.remoteRulesActionOnFailed == Rules::OnFailedRemoteRulesAction::AbortOnFailedRemoteRulesAction) {
|
||||
if (driver.m_remoteRulesActionOnFailed == Rules::OnFailedRemoteRulesAction::AbortOnFailedRemoteRulesAction) {
|
||||
driver.error (*driver.loc.back(), "", yytext + std::string(" - Failed to download: ") + c.error);
|
||||
throw yy::seclang_parser::syntax_error(*driver.loc.back(), "");
|
||||
}
|
||||
|
Reference in New Issue
Block a user