mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-08-13 21:36:00 +03:00
Refactoring on {global,ip,resources,session,tx,user} collections
Now using the same name schema and interface for these "special" collection. Fix: #1754, #1778
This commit is contained in:
parent
550e9d3f39
commit
892beb5360
@ -105,9 +105,10 @@ void InMemoryPerProcess::resolveMultiMatches(const std::string& var,
|
||||
l->insert(l->begin(), new VariableValue(&m_name, &i.first, &i.second));
|
||||
}
|
||||
} else {
|
||||
auto range = this->equal_range(var);
|
||||
for (auto it = range.first; it != range.second; ++it) {
|
||||
l->insert(l->begin(), new VariableValue(&m_name, &var, &it->second));
|
||||
for (auto &a : *this) {
|
||||
if (a.first.compare(0, var.size(), var) == 0) {
|
||||
l->insert(l->begin(), new VariableValue(&m_name, &var, &a.second));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -116,7 +117,6 @@ void InMemoryPerProcess::resolveMultiMatches(const std::string& var,
|
||||
void InMemoryPerProcess::resolveRegularExpression(const std::string& var,
|
||||
std::vector<const VariableValue *> *l) {
|
||||
|
||||
|
||||
//if (var.find(":") == std::string::npos) {
|
||||
// return;
|
||||
//}
|
||||
|
@ -34,14 +34,15 @@ namespace Variables {
|
||||
class Global_DictElement : public Variable {
|
||||
public:
|
||||
explicit Global_DictElement(std::string dictElement)
|
||||
: Variable("GLOBAL"),
|
||||
m_dictElement(dictElement) { }
|
||||
: Variable("GLOBAL:" + dictElement),
|
||||
m_dictElement("GLOBAL:" + dictElement) { }
|
||||
|
||||
void evaluate(Transaction *t,
|
||||
Rule *rule,
|
||||
std::vector<const VariableValue *> *l) override {
|
||||
t->m_collections.m_global_collection->resolveMultiMatches(
|
||||
m_dictElement, t->m_collections.m_global_collection_key, l);
|
||||
m_name, t->m_collections.m_global_collection_key,
|
||||
t->m_rules->m_secWebAppId.m_value, l);
|
||||
}
|
||||
|
||||
std::string m_dictElement;
|
||||
@ -56,8 +57,9 @@ class Global_NoDictElement : public Variable {
|
||||
void evaluate(Transaction *t,
|
||||
Rule *rule,
|
||||
std::vector<const VariableValue *> *l) override {
|
||||
t->m_collections.m_global_collection->resolveMultiMatches(m_name,
|
||||
t->m_collections.m_global_collection_key, l);
|
||||
t->m_collections.m_global_collection->resolveMultiMatches("",
|
||||
t->m_collections.m_global_collection_key,
|
||||
t->m_rules->m_secWebAppId.m_value, l);
|
||||
}
|
||||
};
|
||||
|
||||
@ -73,7 +75,9 @@ class Global_DictElementRegexp : public Variable {
|
||||
Rule *rule,
|
||||
std::vector<const VariableValue *> *l) override {
|
||||
t->m_collections.m_global_collection->resolveRegularExpression(
|
||||
m_dictElement, t->m_collections.m_global_collection_key, l);
|
||||
m_dictElement,
|
||||
t->m_collections.m_global_collection_key,
|
||||
t->m_rules->m_secWebAppId.m_value, l);
|
||||
}
|
||||
|
||||
Utils::Regex m_r;
|
||||
@ -92,19 +96,24 @@ class Global_DynamicElement : public Variable {
|
||||
std::vector<const VariableValue *> *l) override {
|
||||
std::string string = m_string->evaluate(t);
|
||||
t->m_collections.m_global_collection->resolveMultiMatches(
|
||||
string, t->m_collections.m_global_collection_key, l);
|
||||
string,
|
||||
t->m_collections.m_global_collection_key,
|
||||
t->m_rules->m_secWebAppId.m_value, l);
|
||||
|
||||
}
|
||||
|
||||
void del(Transaction *t, std::string k) {
|
||||
t->m_collections.m_global_collection->del(k,
|
||||
t->m_collections.m_global_collection_key);
|
||||
t->m_collections.m_global_collection_key,
|
||||
t->m_rules->m_secWebAppId.m_value);
|
||||
}
|
||||
|
||||
void storeOrUpdateFirst(Transaction *t, std::string var,
|
||||
std::string value) {
|
||||
t->m_collections.m_global_collection->storeOrUpdateFirst(
|
||||
var, t->m_collections.m_global_collection_key, value);
|
||||
var, t->m_collections.m_global_collection_key,
|
||||
t->m_rules->m_secWebAppId.m_value,
|
||||
value);
|
||||
}
|
||||
|
||||
std::unique_ptr<RunTimeString> m_string;
|
||||
|
@ -40,9 +40,9 @@ class Ip_DictElement : public Variable {
|
||||
void evaluate(Transaction *t,
|
||||
Rule *rule,
|
||||
std::vector<const VariableValue *> *l) override {
|
||||
t->m_collections.m_ip_collection->resolveMultiMatches(m_dictElement,
|
||||
t->m_collections.m_ip_collection_key, l);
|
||||
|
||||
t->m_collections.m_ip_collection->resolveMultiMatches(
|
||||
m_name, t->m_collections.m_ip_collection_key,
|
||||
t->m_rules->m_secWebAppId.m_value, l);
|
||||
}
|
||||
|
||||
std::string m_dictElement;
|
||||
@ -57,8 +57,9 @@ class Ip_NoDictElement : public Variable {
|
||||
void evaluate(Transaction *t,
|
||||
Rule *rule,
|
||||
std::vector<const VariableValue *> *l) override {
|
||||
t->m_collections.m_ip_collection->resolveMultiMatches(m_name,
|
||||
t->m_collections.m_ip_collection_key, l);
|
||||
t->m_collections.m_ip_collection->resolveMultiMatches("",
|
||||
t->m_collections.m_ip_collection_key,
|
||||
t->m_rules->m_secWebAppId.m_value, l);
|
||||
}
|
||||
};
|
||||
|
||||
@ -68,13 +69,14 @@ class Ip_DictElementRegexp : public Variable {
|
||||
explicit Ip_DictElementRegexp(std::string dictElement)
|
||||
: Variable("IP:regex(" + dictElement + ")"),
|
||||
m_r(dictElement),
|
||||
m_dictElement("IP:" + dictElement) { }
|
||||
m_dictElement(dictElement) { }
|
||||
|
||||
void evaluate(Transaction *t,
|
||||
Rule *rule,
|
||||
std::vector<const VariableValue *> *l) override {
|
||||
t->m_collections.m_ip_collection->resolveRegularExpression(m_dictElement,
|
||||
t->m_collections.m_ip_collection_key, l);
|
||||
t->m_collections.m_ip_collection_key,
|
||||
t->m_rules->m_secWebAppId.m_value, l);
|
||||
}
|
||||
|
||||
Utils::Regex m_r;
|
||||
@ -92,19 +94,24 @@ class Ip_DynamicElement : public Variable {
|
||||
Rule *rule,
|
||||
std::vector<const VariableValue *> *l) override {
|
||||
std::string string = m_string->evaluate(t);
|
||||
t->m_collections.m_ip_collection->resolveMultiMatches("IP:" + string,
|
||||
t->m_collections.m_ip_collection_key, l);
|
||||
t->m_collections.m_ip_collection->resolveMultiMatches(
|
||||
string,
|
||||
t->m_collections.m_ip_collection_key,
|
||||
t->m_rules->m_secWebAppId.m_value, l);
|
||||
}
|
||||
|
||||
void del(Transaction *t, std::string k) {
|
||||
t->m_collections.m_ip_collection->del(k,
|
||||
t->m_collections.m_ip_collection_key);
|
||||
t->m_collections.m_ip_collection_key,
|
||||
t->m_rules->m_secWebAppId.m_value);
|
||||
}
|
||||
|
||||
void storeOrUpdateFirst(Transaction *t, std::string var,
|
||||
std::string value) {
|
||||
t->m_collections.m_ip_collection->storeOrUpdateFirst(
|
||||
var, t->m_collections.m_ip_collection_key, value);
|
||||
var, t->m_collections.m_ip_collection_key,
|
||||
t->m_rules->m_secWebAppId.m_value,
|
||||
value);
|
||||
}
|
||||
|
||||
std::unique_ptr<RunTimeString> m_string;
|
||||
|
@ -35,13 +35,13 @@ class Resource_DictElement : public Variable {
|
||||
public:
|
||||
explicit Resource_DictElement(std::string dictElement)
|
||||
: Variable("RESOURCE:" + dictElement),
|
||||
m_dictElement(dictElement) { }
|
||||
m_dictElement("RESOURCE:" + dictElement) { }
|
||||
|
||||
void evaluate(Transaction *t,
|
||||
Rule *rule,
|
||||
std::vector<const VariableValue *> *l) override {
|
||||
t->m_collections.m_resource_collection->resolveMultiMatches(m_dictElement,
|
||||
t->m_collections.m_resource_collection_key,
|
||||
t->m_collections.m_resource_collection->resolveMultiMatches(
|
||||
m_name, t->m_collections.m_resource_collection_key,
|
||||
t->m_rules->m_secWebAppId.m_value, l);
|
||||
}
|
||||
|
||||
@ -102,14 +102,14 @@ class Resource_DynamicElement : public Variable {
|
||||
|
||||
void del(Transaction *t, std::string k) {
|
||||
t->m_collections.m_resource_collection->del(k,
|
||||
t->m_collections.m_resource_collection_key);
|
||||
t->m_collections.m_resource_collection_key,
|
||||
t->m_rules->m_secWebAppId.m_value);
|
||||
}
|
||||
|
||||
void storeOrUpdateFirst(Transaction *t, std::string var,
|
||||
std::string value) {
|
||||
t->m_collections.m_resource_collection->storeOrUpdateFirst(
|
||||
var,
|
||||
t->m_collections.m_resource_collection_key,
|
||||
var, t->m_collections.m_resource_collection_key,
|
||||
t->m_rules->m_secWebAppId.m_value, value);
|
||||
}
|
||||
|
||||
|
@ -34,14 +34,14 @@ namespace Variables {
|
||||
class Session_DictElement : public Variable {
|
||||
public:
|
||||
explicit Session_DictElement(std::string dictElement)
|
||||
: Variable("SESSION"),
|
||||
m_dictElement(dictElement) { }
|
||||
: Variable("SESSION:" + dictElement),
|
||||
m_dictElement("SESSION:" + dictElement) { }
|
||||
|
||||
void evaluate(Transaction *t,
|
||||
Rule *rule,
|
||||
std::vector<const VariableValue *> *l) override {
|
||||
t->m_collections.m_session_collection->resolveMultiMatches(
|
||||
m_dictElement, t->m_collections.m_session_collection_key,
|
||||
m_name, t->m_collections.m_session_collection_key,
|
||||
t->m_rules->m_secWebAppId.m_value, l);
|
||||
}
|
||||
|
||||
@ -57,7 +57,7 @@ class Session_NoDictElement : public Variable {
|
||||
void evaluate(Transaction *t,
|
||||
Rule *rule,
|
||||
std::vector<const VariableValue *> *l) override {
|
||||
t->m_collections.m_session_collection->resolveMultiMatches(m_name,
|
||||
t->m_collections.m_session_collection->resolveMultiMatches("",
|
||||
t->m_collections.m_session_collection_key,
|
||||
t->m_rules->m_secWebAppId.m_value, l);
|
||||
}
|
||||
@ -96,18 +96,21 @@ class Session_DynamicElement : public Variable {
|
||||
std::string string = m_string->evaluate(t);
|
||||
t->m_collections.m_session_collection->resolveMultiMatches(
|
||||
string,
|
||||
t->m_collections.m_session_collection_key, l);
|
||||
t->m_collections.m_session_collection_key,
|
||||
t->m_rules->m_secWebAppId.m_value, l);
|
||||
}
|
||||
|
||||
void del(Transaction *t, std::string k) {
|
||||
t->m_collections.m_session_collection->del(k,
|
||||
t->m_collections.m_session_collection_key);
|
||||
t->m_collections.m_session_collection_key,
|
||||
t->m_collections.m_ip_collection_key);
|
||||
}
|
||||
|
||||
void storeOrUpdateFirst(Transaction *t, std::string var,
|
||||
std::string value) {
|
||||
t->m_collections.m_session_collection->storeOrUpdateFirst(
|
||||
var, t->m_collections.m_session_collection_key,
|
||||
t->m_rules->m_secWebAppId.m_value,
|
||||
value);
|
||||
}
|
||||
|
||||
|
@ -35,13 +35,13 @@ class Tx_DictElement : public Variable {
|
||||
public:
|
||||
explicit Tx_DictElement(std::string dictElement)
|
||||
: Variable("TX:" + dictElement),
|
||||
m_dictElement(dictElement) { }
|
||||
m_dictElement("TX:" + dictElement) { }
|
||||
|
||||
void evaluate(Transaction *t,
|
||||
Rule *rule,
|
||||
std::vector<const VariableValue *> *l) override {
|
||||
t->m_collections.m_tx_collection->resolveMultiMatches(
|
||||
m_dictElement, l);
|
||||
m_name, l);
|
||||
}
|
||||
|
||||
std::string m_dictElement;
|
||||
|
@ -34,14 +34,14 @@ namespace Variables {
|
||||
class User_DictElement : public Variable {
|
||||
public:
|
||||
explicit User_DictElement(std::string dictElement)
|
||||
: Variable("USER"),
|
||||
m_dictElement(dictElement) { }
|
||||
: Variable("USER:" + dictElement),
|
||||
m_dictElement("USER:" + dictElement) { }
|
||||
|
||||
void evaluate(Transaction *t,
|
||||
Rule *rule,
|
||||
std::vector<const VariableValue *> *l) override {
|
||||
t->m_collections.m_user_collection->resolveMultiMatches(
|
||||
m_dictElement, t->m_collections.m_user_collection_key,
|
||||
m_name, t->m_collections.m_user_collection_key,
|
||||
t->m_rules->m_secWebAppId.m_value, l);
|
||||
}
|
||||
|
||||
@ -95,18 +95,22 @@ class User_DynamicElement : public Variable {
|
||||
std::vector<const VariableValue *> *l) override {
|
||||
std::string string = m_string->evaluate(t);
|
||||
t->m_collections.m_user_collection->resolveMultiMatches(
|
||||
string, t->m_collections.m_user_collection_key, l);
|
||||
string,
|
||||
t->m_collections.m_user_collection_key,
|
||||
t->m_rules->m_secWebAppId.m_value, l);
|
||||
}
|
||||
|
||||
void del(Transaction *t, std::string k) {
|
||||
t->m_collections.m_user_collection->del(k,
|
||||
t->m_collections.m_user_collection_key);
|
||||
t->m_collections.m_user_collection_key,
|
||||
t->m_rules->m_secWebAppId.m_value);
|
||||
}
|
||||
|
||||
void storeOrUpdateFirst(Transaction *t, std::string var,
|
||||
std::string value) {
|
||||
t->m_collections.m_user_collection->storeOrUpdateFirst(
|
||||
var, t->m_collections.m_user_collection_key,
|
||||
t->m_rules->m_secWebAppId.m_value,
|
||||
value);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user