mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-09-29 11:16:33 +03:00
Refactoring: Splits Rule into Rule and RuleWithActions
This commit is contained in:
@@ -32,6 +32,7 @@
|
||||
namespace modsecurity {
|
||||
class Transaction;
|
||||
class Rule;
|
||||
class RuleWithActions;
|
||||
|
||||
namespace actions {
|
||||
|
||||
@@ -59,8 +60,8 @@ class Action {
|
||||
|
||||
virtual std::string evaluate(const std::string &exp,
|
||||
Transaction *transaction);
|
||||
virtual bool evaluate(Rule *rule, Transaction *transaction);
|
||||
virtual bool evaluate(Rule *rule, Transaction *transaction,
|
||||
virtual bool evaluate(RuleWithActions *rule, Transaction *transaction);
|
||||
virtual bool evaluate(RuleWithActions *rule, Transaction *transaction,
|
||||
std::shared_ptr<RuleMessage> ruleMessage) {
|
||||
return evaluate(rule, transaction);
|
||||
}
|
||||
|
@@ -60,6 +60,8 @@ using TransformationResults = std::list<TransformationResult>;
|
||||
using Transformation = actions::transformations::Transformation;
|
||||
using Transformations = std::vector<Transformation *>;
|
||||
|
||||
using Actions = std::vector<actions::Action *>;
|
||||
|
||||
using Tags = std::vector<actions::Tag *>;
|
||||
using SetVars = std::vector<actions::SetVar *>;
|
||||
using MatchActions = std::vector<actions::Action *>;
|
||||
@@ -137,49 +139,21 @@ class RuleMarker : public RuleBase {
|
||||
};
|
||||
|
||||
|
||||
class Rule : public RuleBase {
|
||||
class RuleWithActions : public RuleBase {
|
||||
public:
|
||||
Rule(operators::Operator *op,
|
||||
variables::Variables *variables,
|
||||
std::vector<actions::Action *> *actions,
|
||||
Transformations *transformations,
|
||||
std::unique_ptr<std::string> fileName,
|
||||
int lineNumber);
|
||||
explicit Rule(const std::string &marker,
|
||||
std::unique_ptr<std::string> fileName,
|
||||
int lineNumber);
|
||||
virtual ~Rule();
|
||||
RuleWithActions(
|
||||
Actions *a,
|
||||
Transformations *t,
|
||||
std::unique_ptr<std::string> fileName,
|
||||
int lineNumber);
|
||||
|
||||
virtual bool evaluate(Transaction *transaction,
|
||||
std::shared_ptr<RuleMessage> rm) override;
|
||||
~RuleWithActions();
|
||||
|
||||
void organizeActions(std::vector<actions::Action *> *actions);
|
||||
void cleanUpActions();
|
||||
void executeAction(Transaction *trans,
|
||||
bool containsBlock, std::shared_ptr<RuleMessage> ruleMessage,
|
||||
actions::Action *a, bool context);
|
||||
|
||||
|
||||
void getVariablesExceptions(Transaction *t,
|
||||
variables::Variables *exclusion, variables::Variables *addition);
|
||||
inline void getFinalVars(variables::Variables *vars,
|
||||
variables::Variables *eclusion, Transaction *trans);
|
||||
void executeActionsAfterFullMatch(Transaction *trasn,
|
||||
bool containsDisruptive, std::shared_ptr<RuleMessage> ruleMessage);
|
||||
|
||||
bool executeOperatorAt(Transaction *trasn, const std::string &key,
|
||||
std::string value, std::shared_ptr<RuleMessage> rm);
|
||||
void executeActionsIndependentOfChainedRuleResult(Transaction *trasn,
|
||||
bool *b, std::shared_ptr<RuleMessage> ruleMessage);
|
||||
static inline void updateMatchedVars(Transaction *trasn, const std::string &key,
|
||||
const std::string &value);
|
||||
static inline void cleanMatchedVars(Transaction *trasn);
|
||||
|
||||
std::vector<actions::Action *> getActionsByName(const std::string& name,
|
||||
Transaction *t);
|
||||
bool containsTag(const std::string& name, Transaction *t);
|
||||
bool containsMsg(const std::string& name, Transaction *t);
|
||||
|
||||
bool containsBlock,
|
||||
std::shared_ptr<RuleMessage> ruleMessage,
|
||||
actions::Action *a,
|
||||
bool context);
|
||||
|
||||
void executeTransformations(
|
||||
Transaction *trasn, const std::string &value, TransformationResults &ret);
|
||||
@@ -191,15 +165,22 @@ class Rule : public RuleBase {
|
||||
std::string *path,
|
||||
int *nth) const;
|
||||
|
||||
void executeActionsIndependentOfChainedRuleResult(Transaction *trasn,
|
||||
bool *b, std::shared_ptr<RuleMessage> ruleMessage);
|
||||
void executeActionsAfterFullMatch(Transaction *trasn,
|
||||
bool containsDisruptive, std::shared_ptr<RuleMessage> ruleMessage);
|
||||
|
||||
|
||||
inline bool isUnconditional() const { return m_operator == NULL; }
|
||||
std::vector<actions::Action *> getActionsByName(const std::string& name,
|
||||
Transaction *t);
|
||||
bool containsTag(const std::string& name, Transaction *t);
|
||||
bool containsMsg(const std::string& name, Transaction *t);
|
||||
|
||||
inline bool isChained() const { return m_isChained == true; }
|
||||
inline bool hasCaptureAction() const { return m_containsCaptureAction == true; }
|
||||
inline void setChained(bool b) { m_isChained = b; }
|
||||
inline bool hasDisruptiveAction() const { return m_disruptiveAction != NULL; }
|
||||
|
||||
inline bool hasBlockAction() const { return m_containsStaticBlockAction == true; }
|
||||
inline bool hasMultimatch() const { return m_containsMultiMatchAction == true; }
|
||||
|
||||
inline bool hasLogData() const { return m_logData != NULL; }
|
||||
std::string logData(Transaction *t);
|
||||
@@ -208,27 +189,14 @@ class Rule : public RuleBase {
|
||||
inline bool hasSeverity() const { return m_severity != NULL; }
|
||||
int severity() const;
|
||||
|
||||
std::string getOperatorName() const;
|
||||
|
||||
int64_t m_ruleId;
|
||||
|
||||
virtual std::string getReference() override {
|
||||
return std::to_string(m_ruleId);
|
||||
}
|
||||
|
||||
std::unique_ptr<Rule> m_chainedRuleChild;
|
||||
Rule *m_chainedRuleParent;
|
||||
|
||||
std::string m_marker;
|
||||
std::string m_rev;
|
||||
std::string m_ver;
|
||||
int m_accuracy;
|
||||
int m_maturity;
|
||||
|
||||
private:
|
||||
modsecurity::variables::Variables *m_variables;
|
||||
operators::Operator *m_operator;
|
||||
int64_t m_ruleId;
|
||||
|
||||
private:
|
||||
/* actions */
|
||||
actions::Action *m_disruptiveAction;
|
||||
actions::LogData *m_logData;
|
||||
@@ -245,11 +213,51 @@ class Rule : public RuleBase {
|
||||
bool m_containsMultiMatchAction:1;
|
||||
bool m_containsStaticBlockAction:1;
|
||||
bool m_isChained:1;
|
||||
bool m_isSecMarker:1;
|
||||
};
|
||||
|
||||
|
||||
class Rule : public RuleWithActions {
|
||||
public:
|
||||
Rule(operators::Operator *op,
|
||||
variables::Variables *variables,
|
||||
std::vector<actions::Action *> *actions,
|
||||
Transformations *transformations,
|
||||
std::unique_ptr<std::string> fileName,
|
||||
int lineNumber);
|
||||
|
||||
virtual ~Rule();
|
||||
|
||||
bool evaluate(Transaction *transaction,
|
||||
std::shared_ptr<RuleMessage> rm) override;
|
||||
|
||||
void getVariablesExceptions(Transaction *t,
|
||||
variables::Variables *exclusion, variables::Variables *addition);
|
||||
inline void getFinalVars(variables::Variables *vars,
|
||||
variables::Variables *eclusion, Transaction *trans);
|
||||
|
||||
bool executeOperatorAt(Transaction *trasn, const std::string &key,
|
||||
std::string value, std::shared_ptr<RuleMessage> rm);
|
||||
|
||||
static void updateMatchedVars(Transaction *trasn, const std::string &key,
|
||||
const std::string &value);
|
||||
static void cleanMatchedVars(Transaction *trasn);
|
||||
|
||||
inline bool isUnconditional() const { return m_operator == NULL; }
|
||||
|
||||
std::string getOperatorName() const;
|
||||
|
||||
virtual std::string getReference() override {
|
||||
return std::to_string(m_ruleId);
|
||||
}
|
||||
|
||||
std::unique_ptr<Rule> m_chainedRuleChild;
|
||||
Rule *m_chainedRuleParent;
|
||||
|
||||
private:
|
||||
modsecurity::variables::Variables *m_variables;
|
||||
operators::Operator *m_operator;
|
||||
|
||||
bool m_unconditional:1;
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
} // namespace modsecurity
|
||||
|
Reference in New Issue
Block a user