diff --git a/headers/modsecurity/collection/collection.h b/headers/modsecurity/collection/collection.h index 94e8c9dc..30bd5ff2 100644 --- a/headers/modsecurity/collection/collection.h +++ b/headers/modsecurity/collection/collection.h @@ -62,49 +62,49 @@ class Collection { virtual void store(std::string key, std::string compartment, std::string value) { - std::string nkey = key + "::" + compartment; + std::string nkey = compartment + "::" + key; store(nkey, value); } virtual bool storeOrUpdateFirst(const std::string &key, std::string compartment, const std::string &value) { - std::string nkey = key + "::" + compartment; + std::string nkey = compartment + "::" + key; return storeOrUpdateFirst(nkey, value); } virtual bool updateFirst(const std::string &key, std::string compartment, const std::string &value) { - std::string nkey = key + "::" + compartment; + std::string nkey = compartment + "::" + key; return updateFirst(nkey, value); } virtual void del(const std::string& key, std::string compartment) { - std::string nkey = key + "::" + compartment; + std::string nkey = compartment + "::" + key; del(nkey); } virtual std::string* resolveFirst(const std::string& var, std::string compartment) { - std::string nkey = var + "::" + compartment; + std::string nkey = compartment + "::" + var; return resolveFirst(nkey); } virtual void resolveSingleMatch(const std::string& var, std::string compartment, std::vector *l) { - std::string nkey = var + "::" + compartment; + std::string nkey = compartment + "::" + var; resolveSingleMatch(nkey, l); } virtual void resolveMultiMatches(const std::string& var, std::string compartment, std::vector *l) { - std::string nkey = var + "::" + compartment; + std::string nkey = compartment + "::" + var; resolveMultiMatches(nkey, l); } virtual void resolveRegularExpression(const std::string& var, std::string compartment, std::vector *l) { - std::string nkey = var + "::" + compartment; + std::string nkey = compartment + "::" + var; resolveRegularExpression(nkey, l); } diff --git a/src/variables/variable.cc b/src/variables/variable.cc index dc390daf..61eb743e 100644 --- a/src/variables/variable.cc +++ b/src/variables/variable.cc @@ -22,6 +22,7 @@ #include "modsecurity/transaction.h" #include "variations/exclusion.h" +#include "src/utils.h" using modsecurity::Variables::Variations::Exclusion; @@ -37,12 +38,32 @@ Variable::Variable(std::string name) if (m_name.at(0) == '\\') { m_type = RegularExpression; } else if (m_name.find(":") != std::string::npos) { + std::string col = toupper(std::string(m_name, 0, m_name.find(":"))); + if (col == "TX" || col == "IP" || col == "GLOBAL" + || col == "RESOURCE" || col == "SESSION") { + m_collectionName = col; + } m_type = SingleMatch; } else { m_type = MultipleMatches; } - if (m_name.find(".") != std::string::npos) { + if (tolower(m_name) == "tx") { + m_collectionName = "TX"; + m_type = MultipleMatches; + } else if (tolower(m_name) == "ip") { + m_collectionName = "IP"; + m_type = MultipleMatches; + } else if (tolower(m_name) == "global") { + m_collectionName = "GLOBAL"; + m_type = MultipleMatches; + } else if (tolower(m_name) == "resource") { + m_collectionName = "RESOURCE"; + m_type = MultipleMatches; + } else if (tolower(m_name) == "session") { + m_collectionName = "SESSION"; + m_type = MultipleMatches; + } else if (m_name.find(".") != std::string::npos) { m_kind = CollectionVarible; m_collectionName = std::string(m_name, 0, m_name.find(".")); } else { @@ -60,12 +81,32 @@ Variable::Variable(std::string name, VariableKind kind) if (m_name.at(0) == '\\') { m_type = RegularExpression; } else if (m_name.find(":") != std::string::npos) { + std::string col = toupper(std::string(m_name, 0, m_name.find(":"))); + if (col == "TX" || col == "IP" || col == "GLOBAL" + || col == "RESOURCE" || col == "SESSION") { + m_collectionName = col; + } m_type = SingleMatch; } else { m_type = MultipleMatches; } - if (m_name.find(".") != std::string::npos) { + if (tolower(m_name) == "tx") { + m_collectionName = "TX"; + m_type = MultipleMatches; + } else if (tolower(m_name) == "ip") { + m_collectionName = "IP"; + m_type = MultipleMatches; + } else if (tolower(m_name) == "global") { + m_collectionName = "GLOBAL"; + m_type = MultipleMatches; + } else if (tolower(m_name) == "resource") { + m_collectionName = "RESOURCE"; + m_type = MultipleMatches; + } else if (tolower(m_name) == "session") { + m_collectionName = "SESSION"; + m_type = MultipleMatches; + } else if (m_name.find(".") != std::string::npos) { m_collectionName = std::string(m_name, 0, m_name.find(".")); } }