mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-09-30 03:34:29 +03:00
Huge improve in the variables resolution time
This commit is contained in:
@@ -49,15 +49,15 @@ std::list<transaction::Variable *> *
|
||||
std::string value = std::string(env, pos+1, env.length() - (pos + 1));
|
||||
|
||||
envs.insert(std::pair<std::string, std::string>("ENV:" + key, value));
|
||||
if ("env:" + key == name) {
|
||||
resl->push_back(new transaction::Variable(name, value));
|
||||
if ("env:" + key == m_name) {
|
||||
resl->push_back(new transaction::Variable(m_name, value));
|
||||
return resl;
|
||||
}
|
||||
}
|
||||
|
||||
for (auto& x : envs) {
|
||||
if ((x.first.substr(0, name.size() + 1).compare(name + ":") != 0)
|
||||
&& (x.first != name)) {
|
||||
if ((x.first.substr(0, m_name.size() + 1).compare(m_name + ":") != 0)
|
||||
&& (x.first != m_name)) {
|
||||
continue;
|
||||
}
|
||||
resl->push_back(new transaction::Variable(x.first, x.second));
|
||||
|
@@ -38,7 +38,13 @@ std::list<transaction::Variable *> *
|
||||
std::list<transaction::Variable *> *resl =
|
||||
new std::list<transaction::Variable *>();
|
||||
|
||||
resl->push_back(new transaction::Variable("TX:0", "teste"));
|
||||
if (m_type == SingleMatch) {
|
||||
assay->m_collections.resolveSingleMatch(m_name, "TX", resl);
|
||||
} else if (m_type == MultipleMatches) {
|
||||
assay->m_collections.resolveMultiMatches(m_name, "TX", resl);
|
||||
} else if (m_type == RegularExpression) {
|
||||
assay->m_collections.resolveRegularExpression(m_name, "TX", resl);
|
||||
}
|
||||
|
||||
return resl;
|
||||
}
|
||||
|
@@ -28,20 +28,80 @@ using ModSecurity::Variables::Variations::Exclusion;
|
||||
namespace ModSecurity {
|
||||
namespace Variables {
|
||||
|
||||
|
||||
Variable::Variable(std::string name)
|
||||
: m_name(name),
|
||||
m_collectionName("") {
|
||||
|
||||
if (m_name.at(0) == '\\') {
|
||||
m_type = RegularExpression;
|
||||
} else if (m_name.find(":") != std::string::npos) {
|
||||
m_type = SingleMatch;
|
||||
} else {
|
||||
m_type = MultipleMatches;
|
||||
}
|
||||
|
||||
if (m_name.find(".") != std::string::npos) {
|
||||
m_kind = CollectionVarible;
|
||||
m_collectionName = std::string(m_name, 0, m_name.find("."));
|
||||
} else {
|
||||
m_kind = DirectVariable;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Variable::Variable(std::string name, VariableKind kind)
|
||||
: m_name(name),
|
||||
m_collectionName(""),
|
||||
m_kind(kind) {
|
||||
|
||||
if (m_name.at(0) == '\\') {
|
||||
m_type = RegularExpression;
|
||||
} else if (m_name.find(":") != std::string::npos) {
|
||||
m_type = SingleMatch;
|
||||
} else {
|
||||
m_type = MultipleMatches;
|
||||
}
|
||||
|
||||
if (m_name.find(".") != std::string::npos) {
|
||||
m_collectionName = std::string(m_name, 0, m_name.find("."));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::list<transaction::Variable *> *
|
||||
Variable::evaluate(Assay *assay) {
|
||||
std::list<transaction::Variable *> *l =
|
||||
new std::list<transaction::Variable *>();
|
||||
assay->m_collections.resolve(this->name, l);
|
||||
|
||||
if (m_collectionName.empty() == false) {
|
||||
if (m_kind == CollectionVarible && m_type == MultipleMatches) {
|
||||
assay->m_collections.resolveMultiMatches(m_name, m_collectionName, l);
|
||||
} if (m_kind == CollectionVarible && m_type == RegularExpression) {
|
||||
assay->m_collections.resolveRegularExpression(m_name, m_collectionName, l);
|
||||
} else {
|
||||
assay->m_collections.resolveSingleMatch(m_name, m_collectionName, l);
|
||||
}
|
||||
} else {
|
||||
if (m_kind == CollectionVarible && m_type == MultipleMatches) {
|
||||
assay->m_collections.resolveMultiMatches(m_name, l);
|
||||
} if (m_kind == CollectionVarible && m_type == RegularExpression) {
|
||||
assay->m_collections.resolveRegularExpression(m_name, l);
|
||||
} else {
|
||||
assay->m_collections.resolveSingleMatch(m_name, l);
|
||||
}
|
||||
}
|
||||
|
||||
return l;
|
||||
}
|
||||
|
||||
|
||||
std::string Variable::to_s(
|
||||
std::vector<Variable *> *variables) {
|
||||
std::string ret;
|
||||
std::string except("");
|
||||
for (int i = 0; i < variables->size() ; i++) {
|
||||
std::string name = variables->at(i)->name;
|
||||
std::string name = variables->at(i)->m_name;
|
||||
Exclusion *e = dynamic_cast<Exclusion *>(variables->at(i));
|
||||
if (e != NULL) {
|
||||
if (except.empty()) {
|
||||
|
@@ -29,13 +29,51 @@ namespace Variables {
|
||||
|
||||
class Variable {
|
||||
public:
|
||||
explicit Variable(std::string _name)
|
||||
: name(_name) { }
|
||||
/**
|
||||
*
|
||||
*/
|
||||
enum VariableType {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
SingleMatch,
|
||||
/**
|
||||
*
|
||||
*/
|
||||
MultipleMatches,
|
||||
/**
|
||||
*
|
||||
*/
|
||||
RegularExpression
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
enum VariableKind {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
DirectVariable,
|
||||
/**
|
||||
*
|
||||
*/
|
||||
CollectionVarible,
|
||||
};
|
||||
|
||||
explicit Variable(std::string _name);
|
||||
Variable(std::string name, VariableKind kind);
|
||||
|
||||
static std::string to_s(std::vector<Variable *> *variables);
|
||||
virtual std::list<transaction::Variable *> *
|
||||
evaluate(Assay *assay);
|
||||
std::string name;
|
||||
|
||||
virtual std::list<transaction::Variable *> *evaluate(Assay *assay);
|
||||
//virtual std::list<transaction::Variable *> *eval_int(Assay *assay);
|
||||
|
||||
std::string m_name;
|
||||
std::string m_collectionName;
|
||||
|
||||
VariableType m_type;
|
||||
VariableKind m_kind;
|
||||
};
|
||||
|
||||
|
||||
|
@@ -49,7 +49,7 @@ std::list<transaction::Variable *> *
|
||||
|
||||
std::string res = std::to_string(count);
|
||||
|
||||
reslOut->push_back(new transaction::Variable(std::string(var->name),
|
||||
reslOut->push_back(new transaction::Variable(std::string(var->m_name),
|
||||
std::string(res)));
|
||||
|
||||
return reslOut;
|
||||
|
@@ -32,7 +32,7 @@ namespace Variations {
|
||||
class Count : public Variable {
|
||||
public:
|
||||
explicit Count(Variable *v)
|
||||
: Variable("count(" + v->name + ")"),
|
||||
: Variable("count(" + v->m_name + ")"),
|
||||
var(v) { }
|
||||
|
||||
std::list<transaction::Variable *> *
|
||||
|
@@ -33,7 +33,7 @@ std::list<transaction::Variable *> *
|
||||
Exclusion::evaluate(Assay *assay) {
|
||||
std::list<transaction::Variable *> *l =
|
||||
new std::list<transaction::Variable *>();
|
||||
assay->m_collections.resolve(this->name, l);
|
||||
assay->m_collections.resolve(this->m_name, l);
|
||||
return l;
|
||||
}
|
||||
|
||||
|
@@ -33,7 +33,7 @@ namespace Variations {
|
||||
class Exclusion : public Variable {
|
||||
public:
|
||||
explicit Exclusion(Variable *v)
|
||||
: Variable(v->name),
|
||||
: Variable(v->m_name),
|
||||
var(v) { }
|
||||
|
||||
std::list<transaction::Variable *> *
|
||||
|
Reference in New Issue
Block a user