From 2f5dac5c4cbd41ecb4c07bfc01ba02effff98d62 Mon Sep 17 00:00:00 2001 From: Eduardo Arias Date: Mon, 19 Aug 2024 11:26:56 -0700 Subject: [PATCH] Simplified initialization of Transformation's action_kind - Some of the Transformation classes would initialize their Action's action_kind using the default (using Transformation constructor without an action_kind parameter). - Others, however, would use that constructor and initialize action_kind manually in their constructor, but setting the default value (RunTimeBeforeMatchAttemptKind = 1), which was redundant. - Removed unused Transformation constructor to specify action_kind. - Converted Action::Kind into an 'enum class' to require using the enum constants (instead of integer values, which are difficult to track in the codebase and change) --- headers/modsecurity/actions/action.h | 70 +++++++++---------- src/actions/accuracy.h | 2 +- src/actions/audit_log.h | 2 +- src/actions/capture.h | 2 +- src/actions/chain.h | 2 +- src/actions/ctl/audit_engine.h | 2 +- src/actions/ctl/audit_log_parts.h | 2 +- src/actions/ctl/request_body_access.h | 2 +- src/actions/ctl/request_body_processor_json.h | 2 +- .../ctl/request_body_processor_urlencoded.h | 2 +- src/actions/ctl/request_body_processor_xml.h | 2 +- src/actions/ctl/rule_engine.h | 2 +- src/actions/ctl/rule_remove_by_id.h | 2 +- src/actions/ctl/rule_remove_by_tag.h | 2 +- src/actions/ctl/rule_remove_target_by_id.h | 2 +- src/actions/ctl/rule_remove_target_by_tag.h | 2 +- src/actions/data/status.h | 4 +- src/actions/disruptive/allow.h | 2 +- src/actions/disruptive/redirect.h | 4 +- src/actions/expire_var.h | 2 +- src/actions/init_col.h | 2 +- src/actions/log.h | 2 +- src/actions/log_data.h | 4 +- src/actions/maturity.h | 2 +- src/actions/msg.h | 4 +- src/actions/multi_match.h | 2 +- src/actions/no_audit_log.h | 2 +- src/actions/no_log.h | 2 +- src/actions/phase.h | 2 +- src/actions/rev.h | 2 +- src/actions/rule_id.h | 2 +- src/actions/set_env.h | 2 +- src/actions/set_rsc.h | 2 +- src/actions/set_sid.h | 2 +- src/actions/set_uid.h | 2 +- src/actions/skip.h | 2 +- src/actions/skip_after.h | 2 +- src/actions/tag.h | 2 +- src/actions/transformations/base64_decode.h | 3 +- .../transformations/base64_decode_ext.h | 3 +- src/actions/transformations/base64_encode.h | 3 +- src/actions/transformations/cmd_line.h | 3 +- .../transformations/compress_whitespace.cc | 5 -- .../transformations/compress_whitespace.h | 2 +- src/actions/transformations/css_decode.h | 3 +- .../transformations/escape_seq_decode.cc | 6 -- .../transformations/escape_seq_decode.h | 2 +- src/actions/transformations/hex_decode.h | 3 +- src/actions/transformations/hex_encode.cc | 4 -- src/actions/transformations/hex_encode.h | 2 +- .../transformations/html_entity_decode.h | 3 +- src/actions/transformations/js_decode.h | 3 +- src/actions/transformations/length.cc | 5 -- src/actions/transformations/length.h | 2 +- src/actions/transformations/lower_case.cc | 4 -- src/actions/transformations/lower_case.h | 2 +- src/actions/transformations/md5.h | 3 +- src/actions/transformations/normalise_path.cc | 5 -- src/actions/transformations/normalise_path.h | 2 +- .../transformations/normalise_path_win.h | 3 +- .../transformations/parity_even_7bit.h | 3 +- src/actions/transformations/parity_odd_7bit.h | 3 +- .../transformations/parity_zero_7bit.h | 3 +- src/actions/transformations/remove_comments.h | 3 +- .../transformations/remove_comments_char.cc | 4 -- .../transformations/remove_comments_char.h | 2 +- src/actions/transformations/remove_nulls.h | 3 +- .../transformations/remove_whitespace.cc | 5 -- .../transformations/remove_whitespace.h | 2 +- .../transformations/replace_comments.cc | 6 -- .../transformations/replace_comments.h | 2 +- src/actions/transformations/replace_nulls.cc | 4 -- src/actions/transformations/replace_nulls.h | 2 +- src/actions/transformations/sha1.cc | 5 +- src/actions/transformations/sha1.h | 2 +- src/actions/transformations/sql_hex_decode.h | 3 +- src/actions/transformations/transformation.h | 5 +- src/actions/transformations/trim.cc | 6 -- src/actions/transformations/trim.h | 4 +- src/actions/transformations/trim_left.cc | 9 +-- src/actions/transformations/trim_left.h | 5 +- src/actions/transformations/trim_right.cc | 8 +-- src/actions/transformations/trim_right.h | 5 +- src/actions/transformations/upper_case.cc | 4 -- src/actions/transformations/upper_case.h | 2 +- src/actions/transformations/url_decode.cc | 5 -- src/actions/transformations/url_decode.h | 2 +- src/actions/transformations/url_decode_uni.h | 3 +- src/actions/transformations/url_encode.cc | 6 -- src/actions/transformations/url_encode.h | 2 +- src/actions/transformations/utf8_to_unicode.h | 3 +- src/actions/ver.h | 2 +- src/parser/seclang-parser.cc | 4 +- src/parser/seclang-parser.yy | 4 +- src/rule_with_actions.cc | 8 +-- src/rules_exceptions.cc | 6 +- 96 files changed, 131 insertions(+), 237 deletions(-) diff --git a/headers/modsecurity/actions/action.h b/headers/modsecurity/actions/action.h index b1839fe7..24f0da6d 100644 --- a/headers/modsecurity/actions/action.h +++ b/headers/modsecurity/actions/action.h @@ -32,15 +32,47 @@ namespace actions { class Action { public: + /** + * + * Define the action kind regarding to the execution time. + * + * + */ + enum class Kind { + /** + * + * Action that are executed while loading the configuration. For instance + * the rule ID or the rule phase. + * + */ + ConfigurationKind, + /** + * + * Those are actions that demands to be executed before call the operator. + * For instance the tranformations. + * + * + */ + RunTimeBeforeMatchAttemptKind, + /** + * + * Actions that are executed after the execution of the operator, only if + * the operator returned Match (or True). For instance the disruptive + * actions. + * + */ + RunTimeOnlyIfMatchKind, + }; + explicit Action(const std::string& _action) : m_isNone(false), temporaryAction(false), - action_kind(2), + action_kind(Kind::RunTimeOnlyIfMatchKind), m_name(nullptr), m_parser_payload("") { set_name_and_payload(_action); } - explicit Action(const std::string& _action, int kind) + explicit Action(const std::string& _action, Kind kind) : m_isNone(false), temporaryAction(false), action_kind(kind), @@ -100,41 +132,9 @@ class Action { bool m_isNone; bool temporaryAction; - int action_kind; + Kind action_kind; std::shared_ptr m_name; std::string m_parser_payload; - - /** - * - * Define the action kind regarding to the execution time. - * - * - */ - enum Kind { - /** - * - * Action that are executed while loading the configuration. For instance - * the rule ID or the rule phase. - * - */ - ConfigurationKind, - /** - * - * Those are actions that demands to be executed before call the operator. - * For instance the tranformations. - * - * - */ - RunTimeBeforeMatchAttemptKind, - /** - * - * Actions that are executed after the execution of the operator, only if - * the operator returned Match (or True). For instance the disruptive - * actions. - * - */ - RunTimeOnlyIfMatchKind, - }; }; diff --git a/src/actions/accuracy.h b/src/actions/accuracy.h index f787af19..bbcdba58 100644 --- a/src/actions/accuracy.h +++ b/src/actions/accuracy.h @@ -30,7 +30,7 @@ namespace actions { class Accuracy : public Action { public: explicit Accuracy(const std::string &action) - : Action(action, ConfigurationKind), + : Action(action, Kind::ConfigurationKind), m_accuracy(0) { } bool evaluate(RuleWithActions *rule, Transaction *transaction) override; diff --git a/src/actions/audit_log.h b/src/actions/audit_log.h index d870de2a..cde74387 100644 --- a/src/actions/audit_log.h +++ b/src/actions/audit_log.h @@ -33,7 +33,7 @@ namespace actions { class AuditLog : public Action { public: explicit AuditLog(const std::string &action) - : Action(action, RunTimeOnlyIfMatchKind) { } + : Action(action) { } bool evaluate(RuleWithActions *rule, Transaction *transaction, std::shared_ptr rm) override; diff --git a/src/actions/capture.h b/src/actions/capture.h index 33207439..0b072ece 100644 --- a/src/actions/capture.h +++ b/src/actions/capture.h @@ -29,7 +29,7 @@ namespace actions { class Capture : public Action { public: explicit Capture(const std::string &action) - : Action(action, RunTimeOnlyIfMatchKind) { } + : Action(action) { } bool evaluate(RuleWithActions *rule, Transaction *transaction) override; }; diff --git a/src/actions/chain.h b/src/actions/chain.h index c5642baa..3b04f17e 100644 --- a/src/actions/chain.h +++ b/src/actions/chain.h @@ -33,7 +33,7 @@ namespace actions { class Chain : public Action { public: explicit Chain(const std::string &action) - : Action(action, ConfigurationKind) { } + : Action(action, Kind::ConfigurationKind) { } bool evaluate(RuleWithActions *rule, Transaction *transaction) override; }; diff --git a/src/actions/ctl/audit_engine.h b/src/actions/ctl/audit_engine.h index 03e0cb4c..b822a667 100644 --- a/src/actions/ctl/audit_engine.h +++ b/src/actions/ctl/audit_engine.h @@ -34,7 +34,7 @@ namespace ctl { class AuditEngine : public Action { public: explicit AuditEngine(const std::string &action) - : Action(action, RunTimeOnlyIfMatchKind), + : Action(action), m_auditEngine(audit_log::AuditLog::AuditLogStatus::NotSetLogStatus) { } bool init(std::string *error) override; diff --git a/src/actions/ctl/audit_log_parts.h b/src/actions/ctl/audit_log_parts.h index f4980780..0eb7c6b2 100644 --- a/src/actions/ctl/audit_log_parts.h +++ b/src/actions/ctl/audit_log_parts.h @@ -29,7 +29,7 @@ namespace ctl { class AuditLogParts : public Action { public: explicit AuditLogParts(const std::string &action) - : Action(action, RunTimeOnlyIfMatchKind), + : Action(action), mPartsAction(0), mParts("") { } diff --git a/src/actions/ctl/request_body_access.h b/src/actions/ctl/request_body_access.h index afe3b3d4..1dcc88c5 100644 --- a/src/actions/ctl/request_body_access.h +++ b/src/actions/ctl/request_body_access.h @@ -30,7 +30,7 @@ namespace ctl { class RequestBodyAccess : public Action { public: explicit RequestBodyAccess(const std::string &action) - : Action(action, RunTimeOnlyIfMatchKind), + : Action(action), m_request_body_access(false) { } bool init(std::string *error) override; diff --git a/src/actions/ctl/request_body_processor_json.h b/src/actions/ctl/request_body_processor_json.h index 48125597..9d726b17 100644 --- a/src/actions/ctl/request_body_processor_json.h +++ b/src/actions/ctl/request_body_processor_json.h @@ -29,7 +29,7 @@ namespace ctl { class RequestBodyProcessorJSON : public Action { public: explicit RequestBodyProcessorJSON(const std::string &action) - : Action(action, RunTimeOnlyIfMatchKind) { } + : Action(action) { } bool evaluate(RuleWithActions *rule, Transaction *transaction) override; }; diff --git a/src/actions/ctl/request_body_processor_urlencoded.h b/src/actions/ctl/request_body_processor_urlencoded.h index 5b5557d4..0277664a 100644 --- a/src/actions/ctl/request_body_processor_urlencoded.h +++ b/src/actions/ctl/request_body_processor_urlencoded.h @@ -29,7 +29,7 @@ namespace ctl { class RequestBodyProcessorURLENCODED : public Action { public: explicit RequestBodyProcessorURLENCODED(const std::string &action) - : Action(action, RunTimeOnlyIfMatchKind) { } + : Action(action) { } bool evaluate(RuleWithActions *rule, Transaction *transaction) override; }; diff --git a/src/actions/ctl/request_body_processor_xml.h b/src/actions/ctl/request_body_processor_xml.h index 9084d1d9..5bd15edd 100644 --- a/src/actions/ctl/request_body_processor_xml.h +++ b/src/actions/ctl/request_body_processor_xml.h @@ -29,7 +29,7 @@ namespace ctl { class RequestBodyProcessorXML : public Action { public: explicit RequestBodyProcessorXML(const std::string &action) - : Action(action, RunTimeOnlyIfMatchKind) { } + : Action(action) { } bool evaluate(RuleWithActions *rule, Transaction *transaction) override; }; diff --git a/src/actions/ctl/rule_engine.h b/src/actions/ctl/rule_engine.h index fca5d39b..7aef4232 100644 --- a/src/actions/ctl/rule_engine.h +++ b/src/actions/ctl/rule_engine.h @@ -31,7 +31,7 @@ namespace ctl { class RuleEngine : public Action { public: explicit RuleEngine(const std::string &action) - : Action(action, RunTimeOnlyIfMatchKind), + : Action(action), m_ruleEngine(RulesSetProperties::PropertyNotSetRuleEngine) { } bool init(std::string *error) override; diff --git a/src/actions/ctl/rule_remove_by_id.h b/src/actions/ctl/rule_remove_by_id.h index e0f0902b..f731db31 100644 --- a/src/actions/ctl/rule_remove_by_id.h +++ b/src/actions/ctl/rule_remove_by_id.h @@ -30,7 +30,7 @@ namespace ctl { class RuleRemoveById : public Action { public: explicit RuleRemoveById(const std::string &action) - : Action(action, RunTimeOnlyIfMatchKind) { } + : Action(action) { } bool init(std::string *error) override; bool evaluate(RuleWithActions *rule, Transaction *transaction) override; diff --git a/src/actions/ctl/rule_remove_by_tag.h b/src/actions/ctl/rule_remove_by_tag.h index 5689b7b1..e85cdbfa 100644 --- a/src/actions/ctl/rule_remove_by_tag.h +++ b/src/actions/ctl/rule_remove_by_tag.h @@ -30,7 +30,7 @@ namespace ctl { class RuleRemoveByTag : public Action { public: explicit RuleRemoveByTag(const std::string &action) - : Action(action, RunTimeOnlyIfMatchKind), + : Action(action), m_tag("") { } bool init(std::string *error) override; diff --git a/src/actions/ctl/rule_remove_target_by_id.h b/src/actions/ctl/rule_remove_target_by_id.h index d71e4fc2..92b7286d 100644 --- a/src/actions/ctl/rule_remove_target_by_id.h +++ b/src/actions/ctl/rule_remove_target_by_id.h @@ -30,7 +30,7 @@ namespace ctl { class RuleRemoveTargetById : public Action { public: explicit RuleRemoveTargetById(const std::string &action) - : Action(action, RunTimeOnlyIfMatchKind), + : Action(action), m_id(0), m_target("") { } diff --git a/src/actions/ctl/rule_remove_target_by_tag.h b/src/actions/ctl/rule_remove_target_by_tag.h index 7863e5a5..b4e21239 100644 --- a/src/actions/ctl/rule_remove_target_by_tag.h +++ b/src/actions/ctl/rule_remove_target_by_tag.h @@ -30,7 +30,7 @@ namespace ctl { class RuleRemoveTargetByTag : public Action { public: explicit RuleRemoveTargetByTag(const std::string &action) - : Action(action, RunTimeOnlyIfMatchKind) { } + : Action(action) { } bool init(std::string *error) override; bool evaluate(RuleWithActions *rule, Transaction *transaction) override; diff --git a/src/actions/data/status.h b/src/actions/data/status.h index d792247d..566a927e 100644 --- a/src/actions/data/status.h +++ b/src/actions/data/status.h @@ -33,8 +33,8 @@ namespace data { class Status : public Action { public: - explicit Status(const std::string &action) : Action(action, 2), - m_status(0) { } + explicit Status(const std::string &action) + : Action(action), m_status(0) { } bool init(std::string *error) override; bool evaluate(RuleWithActions *rule, Transaction *transaction, diff --git a/src/actions/disruptive/allow.h b/src/actions/disruptive/allow.h index d9a716ce..a6d538a4 100644 --- a/src/actions/disruptive/allow.h +++ b/src/actions/disruptive/allow.h @@ -54,7 +54,7 @@ enum AllowType : int { class Allow : public Action { public: explicit Allow(const std::string &action) - : Action(action, RunTimeOnlyIfMatchKind), + : Action(action), m_allowType(NoneAllowType) { } diff --git a/src/actions/disruptive/redirect.h b/src/actions/disruptive/redirect.h index 46b5d51a..72ecf98e 100644 --- a/src/actions/disruptive/redirect.h +++ b/src/actions/disruptive/redirect.h @@ -37,12 +37,12 @@ namespace disruptive { class Redirect : public Action { public: explicit Redirect(const std::string &action) - : Action(action, RunTimeOnlyIfMatchKind), + : Action(action), m_status(0), m_string(nullptr) { } explicit Redirect(std::unique_ptr z) - : Action("redirert", RunTimeOnlyIfMatchKind), + : Action("redirert"), m_status(0), m_string(std::move(z)) { } diff --git a/src/actions/expire_var.h b/src/actions/expire_var.h index 1b1537bb..f0ca7496 100644 --- a/src/actions/expire_var.h +++ b/src/actions/expire_var.h @@ -36,7 +36,7 @@ class ExpireVar : public Action { explicit ExpireVar(const std::string &action) : Action(action) { } explicit ExpireVar(std::unique_ptr z) - : Action("expirevar", RunTimeOnlyIfMatchKind), + : Action("expirevar"), m_string(std::move(z)) { } bool evaluate(RuleWithActions *rule, Transaction *transaction) override; diff --git a/src/actions/init_col.h b/src/actions/init_col.h index 16d7ace9..f5a9263b 100644 --- a/src/actions/init_col.h +++ b/src/actions/init_col.h @@ -35,7 +35,7 @@ class InitCol : public Action { explicit InitCol(const std::string &action) : Action(action) { } InitCol(const std::string &action, std::unique_ptr z) - : Action(action, RunTimeOnlyIfMatchKind), + : Action(action), m_string(std::move(z)) { } bool evaluate(RuleWithActions *rule, Transaction *transaction) override; diff --git a/src/actions/log.h b/src/actions/log.h index 736d4a13..d2cb5cd2 100644 --- a/src/actions/log.h +++ b/src/actions/log.h @@ -31,7 +31,7 @@ namespace actions { class Log : public Action { public: explicit Log(const std::string &action) - : Action(action, RunTimeOnlyIfMatchKind) { } + : Action(action) { } bool evaluate(RuleWithActions *rule, Transaction *transaction, std::shared_ptr rm) override; diff --git a/src/actions/log_data.h b/src/actions/log_data.h index da2fbf4d..6e618f2a 100644 --- a/src/actions/log_data.h +++ b/src/actions/log_data.h @@ -33,10 +33,10 @@ namespace actions { class LogData : public Action { public: explicit LogData(const std::string &action) - : Action(action, RunTimeOnlyIfMatchKind) { } + : Action(action) { } explicit LogData(std::unique_ptr z) - : Action("logdata", RunTimeOnlyIfMatchKind), + : Action("logdata"), m_string(std::move(z)) { } bool evaluate(RuleWithActions *rule, Transaction *transaction, diff --git a/src/actions/maturity.h b/src/actions/maturity.h index dd185efa..3f873af4 100644 --- a/src/actions/maturity.h +++ b/src/actions/maturity.h @@ -30,7 +30,7 @@ namespace actions { class Maturity : public Action { public: explicit Maturity(const std::string &action) - : Action(action, ConfigurationKind), + : Action(action, Kind::ConfigurationKind), m_maturity(0) { } bool evaluate(RuleWithActions *rule, Transaction *transaction) override; diff --git a/src/actions/msg.h b/src/actions/msg.h index 61661194..c75e6d6e 100644 --- a/src/actions/msg.h +++ b/src/actions/msg.h @@ -34,10 +34,10 @@ namespace actions { class Msg : public Action { public: explicit Msg(const std::string &action) - : Action(action, RunTimeOnlyIfMatchKind) { } + : Action(action) { } explicit Msg(std::unique_ptr z) - : Action("msg", RunTimeOnlyIfMatchKind), + : Action("msg"), m_string(std::move(z)) { } bool evaluate(RuleWithActions *rule, Transaction *transaction, diff --git a/src/actions/multi_match.h b/src/actions/multi_match.h index b0fd2c76..71fe288f 100644 --- a/src/actions/multi_match.h +++ b/src/actions/multi_match.h @@ -33,7 +33,7 @@ namespace actions { class MultiMatch : public Action { public: explicit MultiMatch(const std::string &action) - : Action(action, RunTimeOnlyIfMatchKind) { } + : Action(action) { } bool evaluate(RuleWithActions *rule, Transaction *transaction) override; }; diff --git a/src/actions/no_audit_log.h b/src/actions/no_audit_log.h index dbd5d098..6deb5e4a 100644 --- a/src/actions/no_audit_log.h +++ b/src/actions/no_audit_log.h @@ -33,7 +33,7 @@ namespace actions { class NoAuditLog : public Action { public: explicit NoAuditLog(const std::string &action) - : Action(action, RunTimeOnlyIfMatchKind) { } + : Action(action) { } bool evaluate(RuleWithActions *rule, Transaction *transaction, std::shared_ptr rm) override; diff --git a/src/actions/no_log.h b/src/actions/no_log.h index 87d4e305..193a64ea 100644 --- a/src/actions/no_log.h +++ b/src/actions/no_log.h @@ -31,7 +31,7 @@ namespace actions { class NoLog : public Action { public: explicit NoLog(const std::string &action) - : Action(action, RunTimeOnlyIfMatchKind) { } + : Action(action) { } bool evaluate(RuleWithActions *rule, Transaction *transaction, std::shared_ptr rm) override; diff --git a/src/actions/phase.h b/src/actions/phase.h index 0fada3c3..7c814584 100644 --- a/src/actions/phase.h +++ b/src/actions/phase.h @@ -32,7 +32,7 @@ namespace actions { class Phase : public Action { public: - explicit Phase(const std::string &action) : Action(action, ConfigurationKind), + explicit Phase(const std::string &action) : Action(action, Kind::ConfigurationKind), m_phase(0), m_secRulesPhase(0) { } diff --git a/src/actions/rev.h b/src/actions/rev.h index 9e3c1bfb..a023b425 100644 --- a/src/actions/rev.h +++ b/src/actions/rev.h @@ -29,7 +29,7 @@ namespace actions { class Rev : public Action { public: - explicit Rev(const std::string &action) : Action(action, ConfigurationKind) { } + explicit Rev(const std::string &action) : Action(action, Kind::ConfigurationKind) { } bool evaluate(RuleWithActions *rule, Transaction *transaction) override; bool init(std::string *error) override; diff --git a/src/actions/rule_id.h b/src/actions/rule_id.h index 2e26f87f..8f16c95e 100644 --- a/src/actions/rule_id.h +++ b/src/actions/rule_id.h @@ -33,7 +33,7 @@ namespace actions { class RuleId : public Action { public: explicit RuleId(const std::string &action) - : Action(action, ConfigurationKind), + : Action(action, Kind::ConfigurationKind), m_ruleId(0) { } bool init(std::string *error) override; diff --git a/src/actions/set_env.h b/src/actions/set_env.h index 33ccfc33..cc24c285 100644 --- a/src/actions/set_env.h +++ b/src/actions/set_env.h @@ -36,7 +36,7 @@ class SetENV : public Action { : Action(_action) { } explicit SetENV(std::unique_ptr z) - : Action("setenv", RunTimeOnlyIfMatchKind), + : Action("setenv"), m_string(std::move(z)) { } bool evaluate(RuleWithActions *rule, Transaction *transaction) override; diff --git a/src/actions/set_rsc.h b/src/actions/set_rsc.h index 5913b7c7..7830ee92 100644 --- a/src/actions/set_rsc.h +++ b/src/actions/set_rsc.h @@ -36,7 +36,7 @@ class SetRSC : public Action { : Action(_action) { } explicit SetRSC(std::unique_ptr z) - : Action("setsrc", RunTimeOnlyIfMatchKind), + : Action("setsrc"), m_string(std::move(z)) { } bool evaluate(RuleWithActions *rule, Transaction *transaction) override; diff --git a/src/actions/set_sid.h b/src/actions/set_sid.h index 64f8f3cc..dca45433 100644 --- a/src/actions/set_sid.h +++ b/src/actions/set_sid.h @@ -36,7 +36,7 @@ class SetSID : public Action { : Action(_action) { } explicit SetSID(std::unique_ptr z) - : Action("setsid", RunTimeOnlyIfMatchKind), + : Action("setsid"), m_string(std::move(z)) { } bool evaluate(RuleWithActions *rule, Transaction *transaction) override; diff --git a/src/actions/set_uid.h b/src/actions/set_uid.h index b8c3a0db..76893999 100644 --- a/src/actions/set_uid.h +++ b/src/actions/set_uid.h @@ -36,7 +36,7 @@ class SetUID : public Action { : Action(_action) { } explicit SetUID(std::unique_ptr z) - : Action("setuid", RunTimeOnlyIfMatchKind), + : Action("setuid"), m_string(std::move(z)) { } bool evaluate(RuleWithActions *rule, Transaction *transaction) override; diff --git a/src/actions/skip.h b/src/actions/skip.h index 71e5d7aa..ee24abe7 100644 --- a/src/actions/skip.h +++ b/src/actions/skip.h @@ -30,7 +30,7 @@ namespace actions { class Skip : public Action { public: explicit Skip(const std::string &action) - : Action(action, RunTimeOnlyIfMatchKind), + : Action(action), m_skip_next(0) { } bool init(std::string *error) override; diff --git a/src/actions/skip_after.h b/src/actions/skip_after.h index f7e0680d..39b2c269 100644 --- a/src/actions/skip_after.h +++ b/src/actions/skip_after.h @@ -31,7 +31,7 @@ namespace actions { class SkipAfter : public Action { public: explicit SkipAfter(const std::string &action) - : Action(action, RunTimeOnlyIfMatchKind), + : Action(action), m_skipName(std::make_shared(m_parser_payload)) { } bool evaluate(RuleWithActions *rule, Transaction *transaction) override; diff --git a/src/actions/tag.h b/src/actions/tag.h index 75369f5f..bf3988b5 100644 --- a/src/actions/tag.h +++ b/src/actions/tag.h @@ -33,7 +33,7 @@ namespace actions { class Tag : public Action { public: explicit Tag(std::unique_ptr z) - : Action("tag", RunTimeOnlyIfMatchKind), + : Action("tag"), m_string(std::move(z)) { } std::string getName(Transaction *transaction); diff --git a/src/actions/transformations/base64_decode.h b/src/actions/transformations/base64_decode.h index 3527bd5e..8c97dbe8 100644 --- a/src/actions/transformations/base64_decode.h +++ b/src/actions/transformations/base64_decode.h @@ -22,8 +22,7 @@ namespace modsecurity::actions::transformations { class Base64Decode : public Transformation { public: - explicit Base64Decode(const std::string &action) - : Transformation(action) { } + using Transformation::Transformation; bool transform(std::string &value, const Transaction *trans) const override; }; diff --git a/src/actions/transformations/base64_decode_ext.h b/src/actions/transformations/base64_decode_ext.h index 8f1f069e..66b0678f 100644 --- a/src/actions/transformations/base64_decode_ext.h +++ b/src/actions/transformations/base64_decode_ext.h @@ -22,8 +22,7 @@ namespace modsecurity::actions::transformations { class Base64DecodeExt : public Transformation { public: - explicit Base64DecodeExt(const std::string &action) - : Transformation(action) { } + using Transformation::Transformation; bool transform(std::string &value, const Transaction *trans) const override; }; diff --git a/src/actions/transformations/base64_encode.h b/src/actions/transformations/base64_encode.h index 7b3ac25e..3c1d96f1 100644 --- a/src/actions/transformations/base64_encode.h +++ b/src/actions/transformations/base64_encode.h @@ -22,8 +22,7 @@ namespace modsecurity::actions::transformations { class Base64Encode : public Transformation { public: - explicit Base64Encode(const std::string &action) - : Transformation(action) { } + using Transformation::Transformation; bool transform(std::string &value, const Transaction *trans) const override; }; diff --git a/src/actions/transformations/cmd_line.h b/src/actions/transformations/cmd_line.h index 9ba5c6b2..27672b60 100644 --- a/src/actions/transformations/cmd_line.h +++ b/src/actions/transformations/cmd_line.h @@ -22,8 +22,7 @@ namespace modsecurity::actions::transformations { class CmdLine : public Transformation { public: - explicit CmdLine(const std::string &action) - : Transformation(action) { } + using Transformation::Transformation; bool transform(std::string &value, const Transaction *trans) const override; }; diff --git a/src/actions/transformations/compress_whitespace.cc b/src/actions/transformations/compress_whitespace.cc index 065b4ee0..a9b31c96 100644 --- a/src/actions/transformations/compress_whitespace.cc +++ b/src/actions/transformations/compress_whitespace.cc @@ -19,11 +19,6 @@ namespace modsecurity::actions::transformations { -CompressWhitespace::CompressWhitespace(const std::string &action) - : Transformation(action) { - this->action_kind = 1; -} - bool CompressWhitespace::transform(std::string &value, const Transaction *trans) const { bool inWhiteSpace = false; diff --git a/src/actions/transformations/compress_whitespace.h b/src/actions/transformations/compress_whitespace.h index bf90b0ba..8f74a3c1 100644 --- a/src/actions/transformations/compress_whitespace.h +++ b/src/actions/transformations/compress_whitespace.h @@ -22,7 +22,7 @@ namespace modsecurity::actions::transformations { class CompressWhitespace : public Transformation { public: - explicit CompressWhitespace(const std::string &action); + using Transformation::Transformation; bool transform(std::string &value, const Transaction *trans) const override; }; diff --git a/src/actions/transformations/css_decode.h b/src/actions/transformations/css_decode.h index 67535a9a..c9b451f8 100644 --- a/src/actions/transformations/css_decode.h +++ b/src/actions/transformations/css_decode.h @@ -22,8 +22,7 @@ namespace modsecurity::actions::transformations { class CssDecode : public Transformation { public: - explicit CssDecode(const std::string &action) - : Transformation(action) { } + using Transformation::Transformation; bool transform(std::string &value, const Transaction *trans) const override; }; diff --git a/src/actions/transformations/escape_seq_decode.cc b/src/actions/transformations/escape_seq_decode.cc index 29006144..2cc413e7 100644 --- a/src/actions/transformations/escape_seq_decode.cc +++ b/src/actions/transformations/escape_seq_decode.cc @@ -20,12 +20,6 @@ namespace modsecurity::actions::transformations { -EscapeSeqDecode::EscapeSeqDecode(const std::string &action) - : Transformation(action) { - this->action_kind = 1; -} - - static inline int ansi_c_sequences_decode_inplace(std::string &value) { auto d = reinterpret_cast(value.data()); const unsigned char* input = d; diff --git a/src/actions/transformations/escape_seq_decode.h b/src/actions/transformations/escape_seq_decode.h index 6a240715..71976fe1 100644 --- a/src/actions/transformations/escape_seq_decode.h +++ b/src/actions/transformations/escape_seq_decode.h @@ -22,7 +22,7 @@ namespace modsecurity::actions::transformations { class EscapeSeqDecode : public Transformation { public: - explicit EscapeSeqDecode(const std::string &action); + using Transformation::Transformation; bool transform(std::string &value, const Transaction *trans) const override; }; diff --git a/src/actions/transformations/hex_decode.h b/src/actions/transformations/hex_decode.h index 158f91aa..1ee6a1b7 100644 --- a/src/actions/transformations/hex_decode.h +++ b/src/actions/transformations/hex_decode.h @@ -22,8 +22,7 @@ namespace modsecurity::actions::transformations { class HexDecode : public Transformation { public: - explicit HexDecode(const std::string &action) - : Transformation(action) { } + using Transformation::Transformation; bool transform(std::string &value, const Transaction *trans) const override; }; diff --git a/src/actions/transformations/hex_encode.cc b/src/actions/transformations/hex_encode.cc index a0719726..689a132f 100644 --- a/src/actions/transformations/hex_encode.cc +++ b/src/actions/transformations/hex_encode.cc @@ -20,10 +20,6 @@ namespace modsecurity::actions::transformations { -HexEncode::HexEncode(const std::string &action) - : Transformation(action) { - this->action_kind = 1; -} bool HexEncode::transform(std::string &value, const Transaction *trans) const { if (value.empty()) return false; diff --git a/src/actions/transformations/hex_encode.h b/src/actions/transformations/hex_encode.h index 3bb744b5..9037a514 100644 --- a/src/actions/transformations/hex_encode.h +++ b/src/actions/transformations/hex_encode.h @@ -22,7 +22,7 @@ namespace modsecurity::actions::transformations { class HexEncode : public Transformation { public: - explicit HexEncode(const std::string &action); + using Transformation::Transformation; bool transform(std::string &value, const Transaction *trans) const override; }; diff --git a/src/actions/transformations/html_entity_decode.h b/src/actions/transformations/html_entity_decode.h index 5c17333a..499f8f2f 100644 --- a/src/actions/transformations/html_entity_decode.h +++ b/src/actions/transformations/html_entity_decode.h @@ -22,8 +22,7 @@ namespace modsecurity::actions::transformations { class HtmlEntityDecode : public Transformation { public: - explicit HtmlEntityDecode(const std::string &action) - : Transformation(action) { } + using Transformation::Transformation; bool transform(std::string &value, const Transaction *trans) const override; }; diff --git a/src/actions/transformations/js_decode.h b/src/actions/transformations/js_decode.h index 94156426..840577cb 100644 --- a/src/actions/transformations/js_decode.h +++ b/src/actions/transformations/js_decode.h @@ -22,8 +22,7 @@ namespace modsecurity::actions::transformations { class JsDecode : public Transformation { public: - explicit JsDecode(const std::string &action) - : Transformation(action) { } + using Transformation::Transformation; bool transform(std::string &value, const Transaction *trans) const override; }; diff --git a/src/actions/transformations/length.cc b/src/actions/transformations/length.cc index 10aadfe8..ac98914c 100644 --- a/src/actions/transformations/length.cc +++ b/src/actions/transformations/length.cc @@ -19,11 +19,6 @@ namespace modsecurity::actions::transformations { -Length::Length(const std::string &action) - : Transformation(action) { - this->action_kind = 1; -} - bool Length::transform(std::string &value, const Transaction *trans) const { value = std::to_string(value.size()); return true; diff --git a/src/actions/transformations/length.h b/src/actions/transformations/length.h index e7b6b081..39465238 100644 --- a/src/actions/transformations/length.h +++ b/src/actions/transformations/length.h @@ -22,7 +22,7 @@ namespace modsecurity::actions::transformations { class Length : public Transformation { public: - explicit Length(const std::string &action); + using Transformation::Transformation; bool transform(std::string &value, const Transaction *trans) const override; }; diff --git a/src/actions/transformations/lower_case.cc b/src/actions/transformations/lower_case.cc index 080429d9..0238b5a4 100644 --- a/src/actions/transformations/lower_case.cc +++ b/src/actions/transformations/lower_case.cc @@ -22,10 +22,6 @@ namespace modsecurity::actions::transformations { -LowerCase::LowerCase(const std::string &a) - : Transformation(a) { -} - bool LowerCase::transform(std::string &value, const Transaction *trans) const { return convert(value, [](auto c) { return std::tolower(c); }); diff --git a/src/actions/transformations/lower_case.h b/src/actions/transformations/lower_case.h index 7bdf2d84..192b2aa3 100644 --- a/src/actions/transformations/lower_case.h +++ b/src/actions/transformations/lower_case.h @@ -24,7 +24,7 @@ namespace modsecurity::actions::transformations { class LowerCase : public Transformation { public: - explicit LowerCase(const std::string &action); + using Transformation::Transformation; bool transform(std::string &value, const Transaction *trans) const override; diff --git a/src/actions/transformations/md5.h b/src/actions/transformations/md5.h index 9d5a15f8..d1813c5f 100644 --- a/src/actions/transformations/md5.h +++ b/src/actions/transformations/md5.h @@ -22,8 +22,7 @@ namespace modsecurity::actions::transformations { class Md5 : public Transformation { public: - explicit Md5(const std::string &action) - : Transformation(action) { } + using Transformation::Transformation; bool transform(std::string &value, const Transaction *trans) const override; }; diff --git a/src/actions/transformations/normalise_path.cc b/src/actions/transformations/normalise_path.cc index dd2b64d2..91c04027 100644 --- a/src/actions/transformations/normalise_path.cc +++ b/src/actions/transformations/normalise_path.cc @@ -19,11 +19,6 @@ namespace modsecurity::actions::transformations { -NormalisePath::NormalisePath(const std::string &action) - : Transformation(action) { - this->action_kind = 1; -} - bool NormalisePath::transform(std::string &value, const Transaction *trans) const { return normalize_path_inplace(value, false); } diff --git a/src/actions/transformations/normalise_path.h b/src/actions/transformations/normalise_path.h index 248def7f..a1ef8918 100644 --- a/src/actions/transformations/normalise_path.h +++ b/src/actions/transformations/normalise_path.h @@ -22,7 +22,7 @@ namespace modsecurity::actions::transformations { class NormalisePath : public Transformation { public: - explicit NormalisePath(const std::string &action); + using Transformation::Transformation; bool transform(std::string &value, const Transaction *trans) const override; diff --git a/src/actions/transformations/normalise_path_win.h b/src/actions/transformations/normalise_path_win.h index af312693..0cf11260 100644 --- a/src/actions/transformations/normalise_path_win.h +++ b/src/actions/transformations/normalise_path_win.h @@ -22,8 +22,7 @@ namespace modsecurity::actions::transformations { class NormalisePathWin : public Transformation { public: - explicit NormalisePathWin(const std::string &action) - : Transformation(action) { } + using Transformation::Transformation; bool transform(std::string &value, const Transaction *trans) const override; }; diff --git a/src/actions/transformations/parity_even_7bit.h b/src/actions/transformations/parity_even_7bit.h index 786f72e4..8e107a5d 100644 --- a/src/actions/transformations/parity_even_7bit.h +++ b/src/actions/transformations/parity_even_7bit.h @@ -22,8 +22,7 @@ namespace modsecurity::actions::transformations { class ParityEven7bit : public Transformation { public: - explicit ParityEven7bit(const std::string &action) - : Transformation(action) { } + using Transformation::Transformation; bool transform(std::string &value, const Transaction *trans) const override; diff --git a/src/actions/transformations/parity_odd_7bit.h b/src/actions/transformations/parity_odd_7bit.h index d0a1583c..0b9164b9 100644 --- a/src/actions/transformations/parity_odd_7bit.h +++ b/src/actions/transformations/parity_odd_7bit.h @@ -22,8 +22,7 @@ namespace modsecurity::actions::transformations { class ParityOdd7bit : public Transformation { public: - explicit ParityOdd7bit(const std::string &action) - : Transformation(action) { } + using Transformation::Transformation; bool transform(std::string &value, const Transaction *trans) const override; }; diff --git a/src/actions/transformations/parity_zero_7bit.h b/src/actions/transformations/parity_zero_7bit.h index c7f27d74..aa9d1bf3 100644 --- a/src/actions/transformations/parity_zero_7bit.h +++ b/src/actions/transformations/parity_zero_7bit.h @@ -22,8 +22,7 @@ namespace modsecurity::actions::transformations { class ParityZero7bit : public Transformation { public: - explicit ParityZero7bit(const std::string &action) - : Transformation(action) { } + using Transformation::Transformation; bool transform(std::string &value, const Transaction *trans) const override; }; diff --git a/src/actions/transformations/remove_comments.h b/src/actions/transformations/remove_comments.h index 67f0ff5b..948536cb 100644 --- a/src/actions/transformations/remove_comments.h +++ b/src/actions/transformations/remove_comments.h @@ -22,8 +22,7 @@ namespace modsecurity::actions::transformations { class RemoveComments : public Transformation { public: - explicit RemoveComments(const std::string &action) - : Transformation(action) { } + using Transformation::Transformation; bool transform(std::string &value, const Transaction *trans) const override; }; diff --git a/src/actions/transformations/remove_comments_char.cc b/src/actions/transformations/remove_comments_char.cc index 2eeb86f6..7e666db3 100644 --- a/src/actions/transformations/remove_comments_char.cc +++ b/src/actions/transformations/remove_comments_char.cc @@ -18,10 +18,6 @@ namespace modsecurity::actions::transformations { -RemoveCommentsChar::RemoveCommentsChar(const std::string &action) - : Transformation(action) { - this->action_kind = 1; -} bool RemoveCommentsChar::transform(std::string &value, const Transaction *trans) const { char *d = value.data(); diff --git a/src/actions/transformations/remove_comments_char.h b/src/actions/transformations/remove_comments_char.h index 2066fd65..d11b0148 100644 --- a/src/actions/transformations/remove_comments_char.h +++ b/src/actions/transformations/remove_comments_char.h @@ -22,7 +22,7 @@ namespace modsecurity::actions::transformations { class RemoveCommentsChar : public Transformation { public: - explicit RemoveCommentsChar(const std::string &action); + using Transformation::Transformation; bool transform(std::string &value, const Transaction *trans) const override; }; diff --git a/src/actions/transformations/remove_nulls.h b/src/actions/transformations/remove_nulls.h index 163f9ddf..67c90ee0 100644 --- a/src/actions/transformations/remove_nulls.h +++ b/src/actions/transformations/remove_nulls.h @@ -24,8 +24,7 @@ namespace modsecurity::actions::transformations { class RemoveNulls : public Transformation { public: - explicit RemoveNulls(const std::string &action) - : Transformation(action) { } + using Transformation::Transformation; bool transform(std::string &value, const Transaction *trans) const override; diff --git a/src/actions/transformations/remove_whitespace.cc b/src/actions/transformations/remove_whitespace.cc index 934f1d29..f7047f47 100644 --- a/src/actions/transformations/remove_whitespace.cc +++ b/src/actions/transformations/remove_whitespace.cc @@ -20,11 +20,6 @@ namespace modsecurity::actions::transformations { -RemoveWhitespace::RemoveWhitespace(const std::string &action) - : Transformation(action) { - this->action_kind = 1; -} - bool RemoveWhitespace::transform(std::string &value, const Transaction *trans) const { const char nonBreakingSpaces = 0xa0; const char nonBreakingSpaces2 = 0xc2; diff --git a/src/actions/transformations/remove_whitespace.h b/src/actions/transformations/remove_whitespace.h index a9925f8e..b95a508b 100644 --- a/src/actions/transformations/remove_whitespace.h +++ b/src/actions/transformations/remove_whitespace.h @@ -22,7 +22,7 @@ namespace modsecurity::actions::transformations { class RemoveWhitespace : public Transformation { public: - explicit RemoveWhitespace(const std::string &action); + using Transformation::Transformation; bool transform(std::string &value, const Transaction *trans) const override; }; diff --git a/src/actions/transformations/replace_comments.cc b/src/actions/transformations/replace_comments.cc index a6bab972..78ae786c 100644 --- a/src/actions/transformations/replace_comments.cc +++ b/src/actions/transformations/replace_comments.cc @@ -59,12 +59,6 @@ static inline bool inplace(std::string &value) { } -ReplaceComments::ReplaceComments(const std::string &action) - : Transformation(action) { - this->action_kind = 1; -} - - bool ReplaceComments::transform(std::string &value, const Transaction *trans) const { return inplace(value); } diff --git a/src/actions/transformations/replace_comments.h b/src/actions/transformations/replace_comments.h index 95e5e854..db206e53 100644 --- a/src/actions/transformations/replace_comments.h +++ b/src/actions/transformations/replace_comments.h @@ -22,7 +22,7 @@ namespace modsecurity::actions::transformations { class ReplaceComments : public Transformation { public: - explicit ReplaceComments(const std::string &action); + using Transformation::Transformation; bool transform(std::string &value, const Transaction *trans) const override; }; diff --git a/src/actions/transformations/replace_nulls.cc b/src/actions/transformations/replace_nulls.cc index 479f2f5a..9792da5d 100644 --- a/src/actions/transformations/replace_nulls.cc +++ b/src/actions/transformations/replace_nulls.cc @@ -18,10 +18,6 @@ namespace modsecurity::actions::transformations { -ReplaceNulls::ReplaceNulls(const std::string &action) - : Transformation(action) { - this->action_kind = 1; -} bool ReplaceNulls::transform(std::string &value, const Transaction *trans) const { bool changed = false; diff --git a/src/actions/transformations/replace_nulls.h b/src/actions/transformations/replace_nulls.h index ad206ae4..a01077c7 100644 --- a/src/actions/transformations/replace_nulls.h +++ b/src/actions/transformations/replace_nulls.h @@ -22,7 +22,7 @@ namespace modsecurity::actions::transformations { class ReplaceNulls : public Transformation { public: - explicit ReplaceNulls(const std::string &action); + using Transformation::Transformation; bool transform(std::string &value, const Transaction *trans) const override; }; diff --git a/src/actions/transformations/sha1.cc b/src/actions/transformations/sha1.cc index af1eda41..38863345 100644 --- a/src/actions/transformations/sha1.cc +++ b/src/actions/transformations/sha1.cc @@ -20,14 +20,11 @@ namespace modsecurity::actions::transformations { -Sha1::Sha1(const std::string &action) - : Transformation(action) { - this->action_kind = 1; -} bool Sha1::transform(std::string &value, const Transaction *trans) const { value = Utils::Sha1::digest(value); return true; } + } // namespace modsecurity::actions::transformations diff --git a/src/actions/transformations/sha1.h b/src/actions/transformations/sha1.h index 263ed978..f7776411 100644 --- a/src/actions/transformations/sha1.h +++ b/src/actions/transformations/sha1.h @@ -22,7 +22,7 @@ namespace modsecurity::actions::transformations { class Sha1 : public Transformation { public: - explicit Sha1(const std::string &action); + using Transformation::Transformation; bool transform(std::string &value, const Transaction *trans) const override; }; diff --git a/src/actions/transformations/sql_hex_decode.h b/src/actions/transformations/sql_hex_decode.h index 44f45d17..0acb1cff 100644 --- a/src/actions/transformations/sql_hex_decode.h +++ b/src/actions/transformations/sql_hex_decode.h @@ -22,8 +22,7 @@ namespace modsecurity::actions::transformations { class SqlHexDecode : public Transformation { public: - explicit SqlHexDecode(const std::string &action) - : Transformation(action) { } + using Transformation::Transformation; bool transform(std::string &value, const Transaction *trans) const override; }; diff --git a/src/actions/transformations/transformation.h b/src/actions/transformations/transformation.h index 3677dcef..1d0ea99a 100644 --- a/src/actions/transformations/transformation.h +++ b/src/actions/transformations/transformation.h @@ -23,10 +23,7 @@ namespace modsecurity::actions::transformations { class Transformation : public Action { public: explicit Transformation(const std::string& _action) - : Action(_action, RunTimeBeforeMatchAttemptKind) { } - - explicit Transformation(const std::string& _action, int kind) - : Action(_action, kind) { } + : Action(_action, Kind::RunTimeBeforeMatchAttemptKind) { } static Transformation* instantiate(std::string a); diff --git a/src/actions/transformations/trim.cc b/src/actions/transformations/trim.cc index bc90b4ec..2056b256 100644 --- a/src/actions/transformations/trim.cc +++ b/src/actions/transformations/trim.cc @@ -55,12 +55,6 @@ bool Trim::trim(std::string &s) { } -Trim::Trim(const std::string &action) - : Transformation(action) { - this->action_kind = 1; -} - - bool Trim::transform(std::string &value, const Transaction *trans) const { return trim(value); } diff --git a/src/actions/transformations/trim.h b/src/actions/transformations/trim.h index 0e3d26f6..e436f5bf 100644 --- a/src/actions/transformations/trim.h +++ b/src/actions/transformations/trim.h @@ -22,12 +22,10 @@ namespace modsecurity::actions::transformations { class Trim : public Transformation { public: - explicit Trim(const std::string &action); + using Transformation::Transformation; bool transform(std::string &value, const Transaction *trans) const override; - protected: - static bool ltrim(std::string &s); static bool rtrim(std::string &s); static bool trim(std::string &s); diff --git a/src/actions/transformations/trim_left.cc b/src/actions/transformations/trim_left.cc index 10276acf..2ce70149 100644 --- a/src/actions/transformations/trim_left.cc +++ b/src/actions/transformations/trim_left.cc @@ -14,19 +14,14 @@ */ #include "trim_left.h" +#include "trim.h" namespace modsecurity::actions::transformations { - -TrimLeft::TrimLeft(const std::string &action) - : Trim(action) { - this->action_kind = 1; -} - bool TrimLeft::transform(std::string &value, const Transaction *trans) const { - return ltrim(value); + return Trim::ltrim(value); } diff --git a/src/actions/transformations/trim_left.h b/src/actions/transformations/trim_left.h index 5d5a0a57..8acf1fe5 100644 --- a/src/actions/transformations/trim_left.h +++ b/src/actions/transformations/trim_left.h @@ -17,13 +17,12 @@ #define SRC_ACTIONS_TRANSFORMATIONS_TRIM_LEFT_H_ #include "transformation.h" -#include "trim.h" namespace modsecurity::actions::transformations { -class TrimLeft : public Trim { +class TrimLeft : public Transformation { public: - explicit TrimLeft(const std::string &action); + using Transformation::Transformation; bool transform(std::string &value, const Transaction *trans) const override; }; diff --git a/src/actions/transformations/trim_right.cc b/src/actions/transformations/trim_right.cc index aa38c348..e6536786 100644 --- a/src/actions/transformations/trim_right.cc +++ b/src/actions/transformations/trim_right.cc @@ -14,18 +14,14 @@ */ #include "trim_right.h" +#include "trim.h" namespace modsecurity::actions::transformations { -TrimRight::TrimRight(const std::string &action) - : Trim(action) { - this->action_kind = 1; -} - bool TrimRight::transform(std::string &value, const Transaction *trans) const { - return rtrim(value); + return Trim::rtrim(value); } diff --git a/src/actions/transformations/trim_right.h b/src/actions/transformations/trim_right.h index eb13fb20..7e31795a 100644 --- a/src/actions/transformations/trim_right.h +++ b/src/actions/transformations/trim_right.h @@ -17,13 +17,12 @@ #define SRC_ACTIONS_TRANSFORMATIONS_TRIM_RIGHT_H_ #include "transformation.h" -#include "trim.h" namespace modsecurity::actions::transformations { -class TrimRight : public Trim { +class TrimRight : public Transformation { public: - explicit TrimRight(const std::string &action); + using Transformation::Transformation; bool transform(std::string &value, const Transaction *trans) const override; }; diff --git a/src/actions/transformations/upper_case.cc b/src/actions/transformations/upper_case.cc index f811bcbb..2b3978c7 100644 --- a/src/actions/transformations/upper_case.cc +++ b/src/actions/transformations/upper_case.cc @@ -24,10 +24,6 @@ namespace modsecurity::actions::transformations { -UpperCase::UpperCase(const std::string &a) - : Transformation(a) { -} - bool UpperCase::transform(std::string &value, const Transaction *trans) const { return LowerCase::convert(value, [](auto c) { return std::toupper(c); }); diff --git a/src/actions/transformations/upper_case.h b/src/actions/transformations/upper_case.h index 70c806b0..87a1df8a 100644 --- a/src/actions/transformations/upper_case.h +++ b/src/actions/transformations/upper_case.h @@ -22,7 +22,7 @@ namespace modsecurity::actions::transformations { class UpperCase : public Transformation { public: - explicit UpperCase(const std::string &action); + using Transformation::Transformation; bool transform(std::string &value, const Transaction *trans) const override; }; diff --git a/src/actions/transformations/url_decode.cc b/src/actions/transformations/url_decode.cc index c67e9fa6..dbc7bf9f 100644 --- a/src/actions/transformations/url_decode.cc +++ b/src/actions/transformations/url_decode.cc @@ -21,11 +21,6 @@ namespace modsecurity::actions::transformations { -UrlDecode::UrlDecode(const std::string &action) - : Transformation(action) { - this->action_kind = 1; -} - bool UrlDecode::transform(std::string &value, const Transaction *trans) const { int invalid_count; return utils::urldecode_nonstrict_inplace(value, invalid_count); diff --git a/src/actions/transformations/url_decode.h b/src/actions/transformations/url_decode.h index 5c5c2662..cc73c9c3 100644 --- a/src/actions/transformations/url_decode.h +++ b/src/actions/transformations/url_decode.h @@ -22,7 +22,7 @@ namespace modsecurity::actions::transformations { class UrlDecode : public Transformation { public: - explicit UrlDecode(const std::string &action); + using Transformation::Transformation; bool transform(std::string &value, const Transaction *trans) const override; }; diff --git a/src/actions/transformations/url_decode_uni.h b/src/actions/transformations/url_decode_uni.h index 8dbac462..046f251a 100644 --- a/src/actions/transformations/url_decode_uni.h +++ b/src/actions/transformations/url_decode_uni.h @@ -22,8 +22,7 @@ namespace modsecurity::actions::transformations { class UrlDecodeUni : public Transformation { public: - explicit UrlDecodeUni(const std::string &action) - : Transformation(action) { } + using Transformation::Transformation; bool transform(std::string &value, const Transaction *trans) const override; }; diff --git a/src/actions/transformations/url_encode.cc b/src/actions/transformations/url_encode.cc index 36fef771..2692a2d3 100644 --- a/src/actions/transformations/url_encode.cc +++ b/src/actions/transformations/url_encode.cc @@ -20,12 +20,6 @@ namespace modsecurity::actions::transformations { -UrlEncode::UrlEncode(const std::string &action) - : Transformation(action) { - this->action_kind = 1; -} - - static inline bool url_enc(std::string &value) { const auto len = value.size() * 3 + 1; std::string ret(len, {}); diff --git a/src/actions/transformations/url_encode.h b/src/actions/transformations/url_encode.h index 4f3ffe73..e112fb57 100644 --- a/src/actions/transformations/url_encode.h +++ b/src/actions/transformations/url_encode.h @@ -22,7 +22,7 @@ namespace modsecurity::actions::transformations { class UrlEncode : public Transformation { public: - explicit UrlEncode(const std::string &action); + using Transformation::Transformation; bool transform(std::string &value, const Transaction *trans) const override; }; diff --git a/src/actions/transformations/utf8_to_unicode.h b/src/actions/transformations/utf8_to_unicode.h index bbb6cdc4..af125338 100644 --- a/src/actions/transformations/utf8_to_unicode.h +++ b/src/actions/transformations/utf8_to_unicode.h @@ -22,8 +22,7 @@ namespace modsecurity::actions::transformations { class Utf8ToUnicode : public Transformation { public: - explicit Utf8ToUnicode(const std::string &action) - : Transformation(action) { } + using Transformation::Transformation; bool transform(std::string &value, const Transaction *trans) const override; }; diff --git a/src/actions/ver.h b/src/actions/ver.h index 364d567b..8bce189c 100644 --- a/src/actions/ver.h +++ b/src/actions/ver.h @@ -29,7 +29,7 @@ namespace actions { class Ver : public Action { public: - explicit Ver(const std::string &action) : Action(action, ConfigurationKind) { } + explicit Ver(const std::string &action) : Action(action, Kind::ConfigurationKind) { } bool evaluate(RuleWithActions *rule, Transaction *transaction) override; diff --git a/src/parser/seclang-parser.cc b/src/parser/seclang-parser.cc index 767b8b22..fbce5704 100644 --- a/src/parser/seclang-parser.cc +++ b/src/parser/seclang-parser.cc @@ -2424,8 +2424,8 @@ namespace yy { definedPhase = phase->m_phase; secRuleDefinedPhase = phase->m_secRulesPhase; delete phase; - } else if (a->action_kind == actions::Action::RunTimeOnlyIfMatchKind || - a->action_kind == actions::Action::RunTimeBeforeMatchAttemptKind) { + } else if (a->action_kind == actions::Action::Kind::RunTimeOnlyIfMatchKind || + a->action_kind == actions::Action::Kind::RunTimeBeforeMatchAttemptKind) { actions::transformations::None *none = dynamic_cast(a); if (none != NULL) { driver.error(yystack_[2].location, "The transformation none is not suitable to be part of the SecDefaultActions"); diff --git a/src/parser/seclang-parser.yy b/src/parser/seclang-parser.yy index f6610951..41583768 100644 --- a/src/parser/seclang-parser.yy +++ b/src/parser/seclang-parser.yy @@ -1199,8 +1199,8 @@ expression: definedPhase = phase->m_phase; secRuleDefinedPhase = phase->m_secRulesPhase; delete phase; - } else if (a->action_kind == actions::Action::RunTimeOnlyIfMatchKind || - a->action_kind == actions::Action::RunTimeBeforeMatchAttemptKind) { + } else if (a->action_kind == actions::Action::Kind::RunTimeOnlyIfMatchKind || + a->action_kind == actions::Action::Kind::RunTimeBeforeMatchAttemptKind) { actions::transformations::None *none = dynamic_cast(a); if (none != NULL) { driver.error(@0, "The transformation none is not suitable to be part of the SecDefaultActions"); diff --git a/src/rule_with_actions.cc b/src/rule_with_actions.cc index 7aa0e649..1cde8005 100644 --- a/src/rule_with_actions.cc +++ b/src/rule_with_actions.cc @@ -89,11 +89,11 @@ RuleWithActions::RuleWithActions( if (actions) { for (Action *a : *actions) { switch (a->action_kind) { - case Action::ConfigurationKind: + case Action::Kind::ConfigurationKind: a->evaluate(this, NULL); delete a; break; - case Action::RunTimeOnlyIfMatchKind: + case Action::Kind::RunTimeOnlyIfMatchKind: if (dynamic_cast(a)) { m_containsCaptureAction = true; delete a; @@ -247,7 +247,7 @@ void RuleWithActions::executeActionsAfterFullMatch(Transaction *trans, bool disruptiveAlreadyExecuted = false; for (const auto &a : trans->m_rules->m_defaultActions[getPhase()]) { // cppcheck-suppress ctunullpointer - if (a.get()->action_kind != actions::Action::RunTimeOnlyIfMatchKind) { + if (a.get()->action_kind != actions::Action::Kind::RunTimeOnlyIfMatchKind) { continue; } if (!a.get()->isDisruptive()) { @@ -374,7 +374,7 @@ void RuleWithActions::executeTransformations( if (none == 0) { for (auto &a : trans->m_rules->m_defaultActions[getPhase()]) { if (a->action_kind \ - != actions::Action::RunTimeBeforeMatchAttemptKind) { + != actions::Action::Kind::RunTimeBeforeMatchAttemptKind) { continue; } diff --git a/src/rules_exceptions.cc b/src/rules_exceptions.cc index 1349866d..71cf28c2 100644 --- a/src/rules_exceptions.cc +++ b/src/rules_exceptions.cc @@ -36,15 +36,15 @@ bool RulesExceptions::loadUpdateActionById(double id, std::string *error) { for (auto &a : *actions) { - if (a->action_kind == actions::Action::ConfigurationKind) { + if (a->action_kind == actions::Action::Kind::ConfigurationKind) { std::cout << "General failure, action: " << a->m_name; std::cout << " has not expected to be used with UpdateActionByID."; std::cout << std::endl; } else if (a->action_kind - == actions::Action::RunTimeBeforeMatchAttemptKind) { + == actions::Action::Kind::RunTimeBeforeMatchAttemptKind) { m_action_pre_update_target_by_id.emplace(std::pair>(id , std::move(a))); - } else if (a->action_kind == actions::Action::RunTimeOnlyIfMatchKind) { + } else if (a->action_kind == actions::Action::Kind::RunTimeOnlyIfMatchKind) { m_action_pos_update_target_by_id.emplace(std::pair>(id , std::move(a))); } else {