mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-11-19 02:40:35 +03:00
actions: Compute the rule association during rules load
This commit is contained in:
87
src/actions/action_with_run_time_string.h
Normal file
87
src/actions/action_with_run_time_string.h
Normal file
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* ModSecurity, http://www.modsecurity.org/
|
||||
* Copyright (c) 2015 - 2020 Trustwave Holdings, Inc. (http://www.trustwave.com/)
|
||||
*
|
||||
* You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* If any of the files related to licensing are missing or if you have any
|
||||
* other questions related to licensing please contact Trustwave Holdings, Inc.
|
||||
* directly using the email address security@modsecurity.org.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "modsecurity/actions/action.h"
|
||||
#include "src/run_time_string.h"
|
||||
|
||||
#ifndef SRC_ACTIONS_ACTION_WITH_RUN_TIME_STRING_H_
|
||||
#define SRC_ACTIONS_ACTION_WITH_RUN_TIME_STRING_H_
|
||||
|
||||
namespace modsecurity {
|
||||
namespace actions {
|
||||
|
||||
class ActionWithRunTimeString : public Action {
|
||||
public:
|
||||
ActionWithRunTimeString(
|
||||
const std::string &name,
|
||||
int king,
|
||||
std::unique_ptr<RunTimeString> string)
|
||||
: Action(name, king),
|
||||
m_string(std::move(string))
|
||||
{ };
|
||||
|
||||
ActionWithRunTimeString(const std::string &name,
|
||||
std::unique_ptr<RunTimeString> string)
|
||||
: Action(name),
|
||||
m_string(std::move(string))
|
||||
{ };
|
||||
|
||||
ActionWithRunTimeString(const std::string &name,
|
||||
int king)
|
||||
: Action(name, king),
|
||||
m_string(nullptr)
|
||||
{ };
|
||||
|
||||
ActionWithRunTimeString(const std::string &name)
|
||||
: Action(name),
|
||||
m_string(nullptr)
|
||||
{ };
|
||||
|
||||
ActionWithRunTimeString(const ActionWithRunTimeString &a)
|
||||
: Action(a),
|
||||
m_string(a.m_string?std::unique_ptr<RunTimeString>(new RunTimeString(*a.m_string.get())):nullptr)
|
||||
{ };
|
||||
|
||||
ActionWithRunTimeString& operator=(const ActionWithRunTimeString& a)
|
||||
{
|
||||
m_string = std::unique_ptr<RunTimeString>(new RunTimeString(*a.m_string.get()));
|
||||
return *this;
|
||||
}
|
||||
|
||||
virtual void populate(RuleWithActions *rule) {
|
||||
if (m_string) {
|
||||
m_string->populate(rule);
|
||||
}
|
||||
}
|
||||
|
||||
std::string getEvaluatedRunTimeString(Transaction *transaction) const noexcept {
|
||||
return (m_string == nullptr)?"":m_string->evaluate(transaction);
|
||||
}
|
||||
|
||||
bool hasRunTimeString() const noexcept {
|
||||
return m_string != nullptr;
|
||||
}
|
||||
|
||||
virtual ActionWithRunTimeString* clone() = 0;
|
||||
|
||||
private:
|
||||
std::unique_ptr<RunTimeString> m_string;
|
||||
};
|
||||
|
||||
|
||||
} // namespace actions
|
||||
} // namespace modsecurity
|
||||
|
||||
#endif // SRC_ACTIONS_ACTION_WITH_RUN_TIME_STRING_H_
|
||||
@@ -35,7 +35,7 @@ bool Redirect::init(std::string *error) {
|
||||
|
||||
|
||||
bool Redirect::execute(RuleWithActions *rule, Transaction *transaction) {
|
||||
std::string m_urlExpanded(m_string->evaluate(transaction));
|
||||
std::string m_urlExpanded(getEvaluatedRunTimeString(transaction));
|
||||
/* if it was changed before, lets keep it. */
|
||||
if (transaction->m_it.status == 200
|
||||
|| (!(transaction->m_it.status <= 307 && transaction->m_it.status >= 301))) {
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
#include "modsecurity/actions/action.h"
|
||||
#include "modsecurity/rule_message.h"
|
||||
#include "src/run_time_string.h"
|
||||
#include "src/actions/action_with_run_time_string.h"
|
||||
|
||||
#ifndef SRC_ACTIONS_DISRUPTIVE_REDIRECT_H_
|
||||
#define SRC_ACTIONS_DISRUPTIVE_REDIRECT_H_
|
||||
@@ -34,25 +34,33 @@ namespace actions {
|
||||
namespace disruptive {
|
||||
|
||||
|
||||
class Redirect : public Action {
|
||||
class Redirect : public ActionWithRunTimeString {
|
||||
public:
|
||||
explicit Redirect(const std::string &action)
|
||||
: Action(action, RunTimeOnlyIfMatchKind),
|
||||
m_status(0),
|
||||
m_string(nullptr) { }
|
||||
explicit Redirect(std::unique_ptr<RunTimeString> runTimeString)
|
||||
: ActionWithRunTimeString(
|
||||
"redirert",
|
||||
RunTimeOnlyIfMatchKind,
|
||||
std::move(runTimeString)),
|
||||
m_status(0)
|
||||
{ };
|
||||
|
||||
explicit Redirect(std::unique_ptr<RunTimeString> z)
|
||||
: Action("redirert", RunTimeOnlyIfMatchKind),
|
||||
m_status(0),
|
||||
m_string(std::move(z)) { }
|
||||
explicit Redirect(const Redirect &action)
|
||||
: ActionWithRunTimeString(action),
|
||||
m_status(action.m_status)
|
||||
{ };
|
||||
|
||||
bool init(std::string *error) override;
|
||||
|
||||
bool execute(RuleWithActions *rule, Transaction *transaction) override;
|
||||
bool init(std::string *error) override;
|
||||
|
||||
bool isDisruptive() override { return true; }
|
||||
|
||||
virtual ActionWithRunTimeString *clone() override {
|
||||
return new Redirect(*this);
|
||||
}
|
||||
|
||||
private:
|
||||
int m_status;
|
||||
std::unique_ptr<RunTimeString> m_string;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ bool InitCol::init(std::string *error) {
|
||||
|
||||
|
||||
bool InitCol::execute(RuleWithActions *rule, Transaction *t) {
|
||||
std::string collectionName(m_string->evaluate(t));
|
||||
std::string collectionName(getEvaluatedRunTimeString(t));
|
||||
|
||||
if (m_collection_key == "ip") {
|
||||
t->m_collections.m_ip_collection_key = collectionName;
|
||||
|
||||
@@ -18,31 +18,43 @@
|
||||
#include <memory>
|
||||
|
||||
#include "modsecurity/actions/action.h"
|
||||
#include "src/run_time_string.h"
|
||||
#include "src/actions/action_with_run_time_string.h"
|
||||
|
||||
#ifndef SRC_ACTIONS_INIT_COL_H_
|
||||
#define SRC_ACTIONS_INIT_COL_H_
|
||||
|
||||
class Transaction;
|
||||
|
||||
namespace modsecurity {
|
||||
class Transaction;
|
||||
namespace actions {
|
||||
|
||||
|
||||
class InitCol : public Action {
|
||||
class InitCol : public ActionWithRunTimeString {
|
||||
public:
|
||||
explicit InitCol(const std::string &action) : Action(action) { }
|
||||
InitCol(
|
||||
const std::string &action,
|
||||
std::unique_ptr<RunTimeString> runTimeString
|
||||
) : ActionWithRunTimeString(
|
||||
action,
|
||||
std::move(runTimeString)
|
||||
)
|
||||
{ };
|
||||
|
||||
InitCol(const std::string &action, std::unique_ptr<RunTimeString> z)
|
||||
: Action(action, RunTimeOnlyIfMatchKind),
|
||||
m_string(std::move(z)) { }
|
||||
InitCol(const InitCol &action)
|
||||
: ActionWithRunTimeString(action),
|
||||
m_collection_key(action.m_collection_key)
|
||||
{ };
|
||||
|
||||
bool init(std::string *error) override;
|
||||
|
||||
bool execute(RuleWithActions *rule, Transaction *transaction) override;
|
||||
bool init(std::string *error) override;
|
||||
|
||||
virtual ActionWithRunTimeString *clone() override {
|
||||
return new InitCol(*this);
|
||||
}
|
||||
|
||||
private:
|
||||
std::string m_collection_key;
|
||||
std::shared_ptr<RunTimeString> m_string;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -30,16 +30,11 @@ namespace actions {
|
||||
|
||||
|
||||
bool LogData::execute(RuleWithActions *rule, Transaction *transaction) {
|
||||
transaction->messageGetLast()->m_data = data(transaction);
|
||||
transaction->messageGetLast()->m_data = getEvaluatedRunTimeString(transaction);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string LogData::data(Transaction *transaction) {
|
||||
std::string a(m_string->evaluate(transaction));
|
||||
return a;
|
||||
}
|
||||
|
||||
|
||||
} // namespace actions
|
||||
} // namespace modsecurity
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
#include <utility>
|
||||
|
||||
#include "modsecurity/actions/action.h"
|
||||
#include "src/run_time_string.h"
|
||||
#include "src/actions/action_with_run_time_string.h"
|
||||
|
||||
#ifndef SRC_ACTIONS_LOG_DATA_H_
|
||||
#define SRC_ACTIONS_LOG_DATA_H_
|
||||
@@ -30,20 +30,25 @@ class Transaction;
|
||||
namespace actions {
|
||||
|
||||
|
||||
class LogData : public Action {
|
||||
class LogData : public ActionWithRunTimeString {
|
||||
public:
|
||||
explicit LogData(const std::string &action)
|
||||
: Action(action, RunTimeOnlyIfMatchKind) { }
|
||||
explicit LogData(std::unique_ptr<RunTimeString> runTimeString)
|
||||
: ActionWithRunTimeString(
|
||||
"logdata",
|
||||
RunTimeOnlyIfMatchKind,
|
||||
std::move(runTimeString)
|
||||
)
|
||||
{ };
|
||||
|
||||
explicit LogData(std::unique_ptr<RunTimeString> z)
|
||||
: Action("logdata", RunTimeOnlyIfMatchKind),
|
||||
m_string(std::move(z)) { }
|
||||
explicit LogData(const LogData &data)
|
||||
: ActionWithRunTimeString(data)
|
||||
{ };
|
||||
|
||||
bool execute(RuleWithActions *rule, Transaction *transaction) override;
|
||||
|
||||
std::string data(Transaction *Transaction);
|
||||
|
||||
std::shared_ptr<RunTimeString> m_string;
|
||||
virtual ActionWithRunTimeString *clone() override {
|
||||
return new LogData(*this);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ namespace actions {
|
||||
|
||||
|
||||
bool Msg::execute(RuleWithActions *rule, Transaction *transaction) {
|
||||
std::string msg = data(transaction);
|
||||
std::string msg = getEvaluatedRunTimeString(transaction);
|
||||
transaction->messageGetLast()->m_message = msg;
|
||||
ms_dbg_a(transaction, 9, "Saving msg: " + msg);
|
||||
|
||||
@@ -55,11 +55,5 @@ bool Msg::execute(RuleWithActions *rule, Transaction *transaction) {
|
||||
}
|
||||
|
||||
|
||||
std::string Msg::data(Transaction *t) {
|
||||
std::string a(m_string->evaluate(t));
|
||||
return a;
|
||||
}
|
||||
|
||||
|
||||
} // namespace actions
|
||||
} // namespace modsecurity
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
#include "modsecurity/actions/action.h"
|
||||
#include "modsecurity/rule_message.h"
|
||||
#include "src/run_time_string.h"
|
||||
#include "src/actions/action_with_run_time_string.h"
|
||||
|
||||
#ifndef SRC_ACTIONS_MSG_H_
|
||||
#define SRC_ACTIONS_MSG_H_
|
||||
@@ -31,19 +31,25 @@ class Transaction;
|
||||
namespace actions {
|
||||
|
||||
|
||||
class Msg : public Action {
|
||||
class Msg : public ActionWithRunTimeString {
|
||||
public:
|
||||
explicit Msg(const std::string &action)
|
||||
: Action(action, RunTimeOnlyIfMatchKind) { }
|
||||
explicit Msg(std::unique_ptr<RunTimeString> runTimeString)
|
||||
: ActionWithRunTimeString(
|
||||
"msg",
|
||||
RunTimeOnlyIfMatchKind,
|
||||
std::move(runTimeString)
|
||||
)
|
||||
{ };
|
||||
|
||||
explicit Msg(std::unique_ptr<RunTimeString> z)
|
||||
: Action("msg", RunTimeOnlyIfMatchKind),
|
||||
m_string(std::move(z)) { }
|
||||
explicit Msg(const Msg &action)
|
||||
: ActionWithRunTimeString(action)
|
||||
{ };
|
||||
|
||||
bool execute(RuleWithActions *rule, Transaction *transaction) override;
|
||||
|
||||
std::string data(Transaction *Transaction);
|
||||
std::shared_ptr<RunTimeString> m_string;
|
||||
virtual ActionWithRunTimeString *clone() override {
|
||||
return new Msg(*this);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -28,13 +28,8 @@ namespace modsecurity {
|
||||
namespace actions {
|
||||
|
||||
|
||||
bool SetENV::init(std::string *error) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool SetENV::execute(RuleWithActions *rule, Transaction *t) {
|
||||
std::string colNameExpanded(m_string->evaluate(t));
|
||||
std::string colNameExpanded(getEvaluatedRunTimeString(t));
|
||||
|
||||
ms_dbg_a(t, 8, "Setting envoriment variable: "
|
||||
+ colNameExpanded + ".");
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
#include <memory>
|
||||
|
||||
#include "modsecurity/actions/action.h"
|
||||
#include "src/run_time_string.h"
|
||||
#include "src/actions/action_with_run_time_string.h"
|
||||
|
||||
#ifndef SRC_ACTIONS_SET_ENV_H_
|
||||
#define SRC_ACTIONS_SET_ENV_H_
|
||||
@@ -30,20 +30,25 @@ class Transaction;
|
||||
namespace actions {
|
||||
|
||||
|
||||
class SetENV : public Action {
|
||||
class SetENV : public ActionWithRunTimeString {
|
||||
public:
|
||||
explicit SetENV(const std::string &_action)
|
||||
: Action(_action) { }
|
||||
explicit SetENV(std::unique_ptr<RunTimeString> runTimeString)
|
||||
: ActionWithRunTimeString(
|
||||
"setenv",
|
||||
RunTimeOnlyIfMatchKind,
|
||||
std::move(runTimeString)
|
||||
)
|
||||
{ };
|
||||
|
||||
explicit SetENV(std::unique_ptr<RunTimeString> z)
|
||||
: Action("setenv", RunTimeOnlyIfMatchKind),
|
||||
m_string(std::move(z)) { }
|
||||
explicit SetENV(const SetENV &action)
|
||||
: ActionWithRunTimeString(action)
|
||||
{ };
|
||||
|
||||
bool execute(RuleWithActions *rule, Transaction *transaction) override;
|
||||
bool init(std::string *error) override;
|
||||
|
||||
private:
|
||||
std::shared_ptr<RunTimeString> m_string;
|
||||
virtual ActionWithRunTimeString *clone() override {
|
||||
return new SetENV(*this);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -26,13 +26,8 @@ namespace modsecurity {
|
||||
namespace actions {
|
||||
|
||||
|
||||
bool SetRSC::init(std::string *error) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool SetRSC::execute(RuleWithActions *rule, Transaction *t) {
|
||||
std::string colNameExpanded(m_string->evaluate(t));
|
||||
std::string colNameExpanded(getEvaluatedRunTimeString(t));
|
||||
ms_dbg_a(t, 8, "RESOURCE initiated with value: \'"
|
||||
+ colNameExpanded + "\'.");
|
||||
|
||||
@@ -42,5 +37,6 @@ bool SetRSC::execute(RuleWithActions *rule, Transaction *t) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
} // namespace actions
|
||||
} // namespace modsecurity
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
#include <memory>
|
||||
|
||||
#include "modsecurity/actions/action.h"
|
||||
#include "src/run_time_string.h"
|
||||
#include "src/actions/action_with_run_time_string.h"
|
||||
|
||||
#ifndef SRC_ACTIONS_SET_RSC_H_
|
||||
#define SRC_ACTIONS_SET_RSC_H_
|
||||
@@ -30,20 +30,25 @@ class Transaction;
|
||||
namespace actions {
|
||||
|
||||
|
||||
class SetRSC : public Action {
|
||||
class SetRSC : public ActionWithRunTimeString {
|
||||
public:
|
||||
explicit SetRSC(const std::string &_action)
|
||||
: Action(_action) { }
|
||||
explicit SetRSC(std::unique_ptr<RunTimeString> runTimeString)
|
||||
: ActionWithRunTimeString(
|
||||
"setsrc",
|
||||
RunTimeOnlyIfMatchKind,
|
||||
std::move(runTimeString)
|
||||
)
|
||||
{ };
|
||||
|
||||
explicit SetRSC(std::unique_ptr<RunTimeString> z)
|
||||
: Action("setsrc", RunTimeOnlyIfMatchKind),
|
||||
m_string(std::move(z)) { }
|
||||
explicit SetRSC(const SetRSC &action)
|
||||
: ActionWithRunTimeString(action)
|
||||
{ };
|
||||
|
||||
bool execute(RuleWithActions *rule, Transaction *transaction) override;
|
||||
bool init(std::string *error) override;
|
||||
|
||||
private:
|
||||
std::shared_ptr<RunTimeString> m_string;
|
||||
virtual ActionWithRunTimeString *clone() override {
|
||||
return new SetRSC(*this);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -26,13 +26,8 @@ namespace modsecurity {
|
||||
namespace actions {
|
||||
|
||||
|
||||
bool SetSID::init(std::string *error) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool SetSID::execute(RuleWithActions *rule, Transaction *t) {
|
||||
std::string colNameExpanded(m_string->evaluate(t));
|
||||
std::string colNameExpanded(getEvaluatedRunTimeString(t));
|
||||
ms_dbg_a(t, 8, "Session ID initiated with value: \'"
|
||||
+ colNameExpanded + "\'.");
|
||||
|
||||
@@ -42,5 +37,6 @@ bool SetSID::execute(RuleWithActions *rule, Transaction *t) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
} // namespace actions
|
||||
} // namespace modsecurity
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
#include <memory>
|
||||
|
||||
#include "modsecurity/actions/action.h"
|
||||
#include "src/run_time_string.h"
|
||||
#include "src/actions/action_with_run_time_string.h"
|
||||
|
||||
#ifndef SRC_ACTIONS_SET_SID_H_
|
||||
#define SRC_ACTIONS_SET_SID_H_
|
||||
@@ -30,20 +30,25 @@ class Transaction;
|
||||
namespace actions {
|
||||
|
||||
|
||||
class SetSID : public Action {
|
||||
class SetSID : public ActionWithRunTimeString {
|
||||
public:
|
||||
explicit SetSID(const std::string &_action)
|
||||
: Action(_action) { }
|
||||
explicit SetSID(std::unique_ptr<RunTimeString> runTimeString)
|
||||
: ActionWithRunTimeString(
|
||||
"setsid",
|
||||
RunTimeOnlyIfMatchKind,
|
||||
std::move(runTimeString)
|
||||
)
|
||||
{ };
|
||||
|
||||
explicit SetSID(std::unique_ptr<RunTimeString> z)
|
||||
: Action("setsid", RunTimeOnlyIfMatchKind),
|
||||
m_string(std::move(z)) { }
|
||||
SetSID(const SetSID &action)
|
||||
: ActionWithRunTimeString(action)
|
||||
{ };
|
||||
|
||||
bool execute(RuleWithActions *rule, Transaction *transaction) override;
|
||||
bool init(std::string *error) override;
|
||||
|
||||
private:
|
||||
std::shared_ptr<RunTimeString> m_string;
|
||||
virtual ActionWithRunTimeString *clone() override {
|
||||
return new SetSID(*this);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -26,13 +26,8 @@ namespace modsecurity {
|
||||
namespace actions {
|
||||
|
||||
|
||||
bool SetUID::init(std::string *error) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool SetUID::execute(RuleWithActions *rule, Transaction *t) {
|
||||
std::string colNameExpanded(m_string->evaluate(t));
|
||||
std::string colNameExpanded(getEvaluatedRunTimeString(t));
|
||||
ms_dbg_a(t, 8, "User collection initiated with value: \'"
|
||||
+ colNameExpanded + "\'.");
|
||||
|
||||
@@ -42,5 +37,6 @@ bool SetUID::execute(RuleWithActions *rule, Transaction *t) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
} // namespace actions
|
||||
} // namespace modsecurity
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
#include <utility>
|
||||
|
||||
#include "modsecurity/actions/action.h"
|
||||
#include "src/run_time_string.h"
|
||||
#include "src/actions/action_with_run_time_string.h"
|
||||
|
||||
#ifndef SRC_ACTIONS_SET_UID_H_
|
||||
#define SRC_ACTIONS_SET_UID_H_
|
||||
@@ -30,20 +30,26 @@ class Transaction;
|
||||
namespace actions {
|
||||
|
||||
|
||||
class SetUID : public Action {
|
||||
class SetUID : public ActionWithRunTimeString {
|
||||
public:
|
||||
explicit SetUID(const std::string &_action)
|
||||
: Action(_action) { }
|
||||
explicit SetUID(std::unique_ptr<RunTimeString> runTimeString)
|
||||
: ActionWithRunTimeString(
|
||||
"setuid",
|
||||
RunTimeOnlyIfMatchKind,
|
||||
std::move(runTimeString)
|
||||
)
|
||||
{ };
|
||||
|
||||
explicit SetUID(std::unique_ptr<RunTimeString> z)
|
||||
: Action("setuid", RunTimeOnlyIfMatchKind),
|
||||
m_string(std::move(z)) { }
|
||||
explicit SetUID(const SetUID &action)
|
||||
: ActionWithRunTimeString(action)
|
||||
{ };
|
||||
|
||||
bool execute(RuleWithActions *rule, Transaction *transaction) override;
|
||||
bool init(std::string *error) override;
|
||||
|
||||
private:
|
||||
std::shared_ptr<RunTimeString> m_string;
|
||||
virtual ActionWithRunTimeString *clone() override {
|
||||
return new SetUID(*this);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -46,8 +46,8 @@ bool SetVar::execute(RuleWithActions *rule, Transaction *t) {
|
||||
std::string targetValue;
|
||||
std::string resolvedPre;
|
||||
|
||||
if (m_string) {
|
||||
resolvedPre = m_string->evaluate(t, rule);
|
||||
if (hasRunTimeString()) {
|
||||
resolvedPre = getEvaluatedRunTimeString(t);
|
||||
}
|
||||
|
||||
std::string m_variableNameExpanded;
|
||||
@@ -66,17 +66,17 @@ bool SetVar::execute(RuleWithActions *rule, Transaction *t) {
|
||||
variables::User_DynamicElement *user = dynamic_cast<
|
||||
variables::User_DynamicElement *> (v);
|
||||
if (tx) {
|
||||
m_variableNameExpanded = tx->m_string->evaluate(t, rule);
|
||||
m_variableNameExpanded = tx->evaluateRunTimeString(t);
|
||||
} else if (session) {
|
||||
m_variableNameExpanded = session->m_string->evaluate(t, rule);
|
||||
m_variableNameExpanded = session->evaluateRunTimeString(t);
|
||||
} else if (ip) {
|
||||
m_variableNameExpanded = ip->m_string->evaluate(t, rule);
|
||||
m_variableNameExpanded = ip->evaluateRunTimeString(t);
|
||||
} else if (resource) {
|
||||
m_variableNameExpanded = resource->m_string->evaluate(t, rule);
|
||||
m_variableNameExpanded = resource->evaluateRunTimeString(t);
|
||||
} else if (global) {
|
||||
m_variableNameExpanded = global->m_string->evaluate(t, rule);
|
||||
m_variableNameExpanded = global->evaluateRunTimeString(t);
|
||||
} else if (user) {
|
||||
m_variableNameExpanded = user->m_string->evaluate(t, rule);
|
||||
m_variableNameExpanded = user->evaluateRunTimeString(t);
|
||||
} else {
|
||||
m_variableNameExpanded = m_variable->m_name;
|
||||
}
|
||||
@@ -114,8 +114,7 @@ bool SetVar::execute(RuleWithActions *rule, Transaction *t) {
|
||||
|
||||
try {
|
||||
std::vector<const VariableValue *> l;
|
||||
RuleWithOperator *rr = dynamic_cast<RuleWithOperator *>(rule);
|
||||
m_variable->evaluate(t, rr, &l);
|
||||
m_variable->evaluate(t, &l);
|
||||
if (l.size() == 0) {
|
||||
value = 0;
|
||||
} else {
|
||||
|
||||
@@ -18,7 +18,8 @@
|
||||
#include <utility>
|
||||
|
||||
#include "modsecurity/actions/action.h"
|
||||
#include "src/run_time_string.h"
|
||||
#include "src/actions/action_with_run_time_string.h"
|
||||
#include "src/variables/variable_with_runtime_string.h"
|
||||
|
||||
#ifndef SRC_ACTIONS_SET_VAR_H_
|
||||
#define SRC_ACTIONS_SET_VAR_H_
|
||||
@@ -42,29 +43,63 @@ enum SetVarOperation {
|
||||
unsetOperation,
|
||||
};
|
||||
|
||||
class SetVar : public Action {
|
||||
class SetVar : public ActionWithRunTimeString {
|
||||
public:
|
||||
SetVar(SetVarOperation operation,
|
||||
std::unique_ptr<modsecurity::variables::Variable> variable,
|
||||
std::unique_ptr<RunTimeString> predicate)
|
||||
: Action("setvar"),
|
||||
: ActionWithRunTimeString("setvar", std::move(predicate)),
|
||||
m_operation(operation),
|
||||
m_variable(std::move(variable)),
|
||||
m_string(std::move(predicate)) { }
|
||||
m_variable(std::move(variable))
|
||||
{ };
|
||||
|
||||
|
||||
SetVar(SetVarOperation operation,
|
||||
std::unique_ptr<modsecurity::variables::Variable> variable)
|
||||
: Action("setvar"),
|
||||
: ActionWithRunTimeString("setvar"),
|
||||
m_operation(operation),
|
||||
m_variable(std::move(variable)) { }
|
||||
m_variable(std::move(variable))
|
||||
{ };
|
||||
|
||||
|
||||
SetVar(const SetVar &var)
|
||||
: ActionWithRunTimeString(var),
|
||||
m_operation(var.m_operation),
|
||||
m_variable(var.m_variable)
|
||||
{
|
||||
variables::RuleVariable *rv = dynamic_cast<variables::RuleVariable *>(m_variable.get());
|
||||
if (rv != nullptr) {
|
||||
auto nrv = rv->clone();
|
||||
rv = dynamic_cast<variables::RuleVariable *>(nrv);
|
||||
rv->populate(nullptr);
|
||||
m_variable = std::unique_ptr<variables::Variable>(nrv);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
bool execute(RuleWithActions *rule, Transaction *transaction) override;
|
||||
bool init(std::string *error) override;
|
||||
|
||||
void populate(RuleWithActions *rule) override {
|
||||
ActionWithRunTimeString::populate(rule);
|
||||
variables::RuleVariable *rulev = dynamic_cast<variables::RuleVariable *>(m_variable.get());
|
||||
if (rulev != nullptr) {
|
||||
rulev->populate(rule);
|
||||
}
|
||||
variables::VariableWithRunTimeString *rulev2 = dynamic_cast<variables::VariableWithRunTimeString *>(m_variable.get());
|
||||
if (rulev2 != nullptr) {
|
||||
rulev2->populate(rule);
|
||||
}
|
||||
}
|
||||
|
||||
virtual ActionWithRunTimeString *clone() override {
|
||||
return new SetVar(*this);
|
||||
}
|
||||
|
||||
private:
|
||||
SetVarOperation m_operation;
|
||||
std::shared_ptr<modsecurity::variables::Variable> m_variable;
|
||||
std::shared_ptr<RunTimeString> m_string;
|
||||
};
|
||||
|
||||
} // namespace actions
|
||||
|
||||
@@ -50,14 +50,8 @@ namespace modsecurity {
|
||||
namespace actions {
|
||||
|
||||
|
||||
std::string Tag::getName(Transaction *transaction) {
|
||||
std::string tag(m_string->evaluate(transaction));
|
||||
return tag;
|
||||
}
|
||||
|
||||
|
||||
bool Tag::execute(RuleWithActions *rule, Transaction *transaction) {
|
||||
std::string tag = getName(transaction);
|
||||
std::string tag = getTagName(transaction);
|
||||
ms_dbg_a(transaction, 9, "Rule tag: " + tag);
|
||||
|
||||
transaction->messageGetLast()->m_tags.push_back(tag);
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
#include <utility>
|
||||
|
||||
#include "modsecurity/actions/action.h"
|
||||
#include "src/run_time_string.h"
|
||||
#include "src/actions/action_with_run_time_string.h"
|
||||
|
||||
#ifndef SRC_ACTIONS_TAG_H_
|
||||
#define SRC_ACTIONS_TAG_H_
|
||||
@@ -30,18 +30,29 @@ class Transaction;
|
||||
namespace actions {
|
||||
|
||||
|
||||
class Tag : public Action {
|
||||
class Tag : public ActionWithRunTimeString {
|
||||
public:
|
||||
explicit Tag(std::unique_ptr<RunTimeString> z)
|
||||
: Action("tag", RunTimeOnlyIfMatchKind),
|
||||
m_string(std::move(z)) { }
|
||||
explicit Tag(std::unique_ptr<RunTimeString> runTimeString)
|
||||
: ActionWithRunTimeString(
|
||||
"tag",
|
||||
RunTimeOnlyIfMatchKind,
|
||||
std::move(runTimeString)
|
||||
)
|
||||
{ };
|
||||
|
||||
std::string getName(Transaction *transaction);
|
||||
explicit Tag(const Tag &action)
|
||||
: ActionWithRunTimeString(action)
|
||||
{ };
|
||||
|
||||
bool execute(RuleWithActions *rule, Transaction *transaction) override;
|
||||
|
||||
protected:
|
||||
std::shared_ptr<RunTimeString> m_string;
|
||||
inline std::string getTagName(Transaction *transaction) const {
|
||||
return getEvaluatedRunTimeString(transaction);
|
||||
}
|
||||
|
||||
virtual ActionWithRunTimeString *clone() override {
|
||||
return new Tag(*this);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -29,7 +29,18 @@ namespace actions {
|
||||
|
||||
class XmlNS : public Action {
|
||||
public:
|
||||
explicit XmlNS(const std::string &action) : Action(action) { }
|
||||
explicit XmlNS(const std::string &action)
|
||||
: Action(action),
|
||||
m_scope(""),
|
||||
m_href("")
|
||||
{ };
|
||||
|
||||
XmlNS(const XmlNS &o)
|
||||
: Action(o),
|
||||
m_scope(o.m_scope),
|
||||
m_href(o.m_href)
|
||||
{ };
|
||||
|
||||
|
||||
bool execute(RuleWithActions *rule, Transaction *transaction) override {
|
||||
return true;
|
||||
@@ -37,6 +48,15 @@ class XmlNS : public Action {
|
||||
|
||||
bool init(std::string *error) override;
|
||||
|
||||
std::string getScope() const {
|
||||
return m_scope;
|
||||
}
|
||||
|
||||
std::string getHref() const {
|
||||
return m_href;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string m_scope;
|
||||
std::string m_href;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user