mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-11-17 09:55:28 +03:00
Implement id ranges for ctl:ruleRemoveTargetById
This commit is contained in:
committed by
Felipe Zimmerle
parent
39ac4760ea
commit
b83d1f1d06
@@ -39,12 +39,36 @@ bool RuleRemoveTargetById::init(std::string *error) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
m_id = std::stoi(param[0]);
|
||||
} catch(...) {
|
||||
error->assign("Not able to convert '" + param[0] +
|
||||
"' into a number");
|
||||
return false;
|
||||
size_t dash = param[0].find('-');
|
||||
if (dash != std::string::npos) {
|
||||
std::string n1s = std::string(param[0], 0, dash);
|
||||
std::string n2s = std::string(param[0], dash + 1, param[0].size() - (dash + 1));
|
||||
int n1n = 0;
|
||||
int n2n = 0;
|
||||
try {
|
||||
n1n = std::stoi(n1s);
|
||||
} catch(...) {
|
||||
error->assign("Not a number: " + n1s);
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
n2n = std::stoi(n2s);
|
||||
} catch(...) {
|
||||
error->assign("Not a number: " + n2s);
|
||||
return false;
|
||||
}
|
||||
if (n1n > n2n) {
|
||||
error->assign("Invalid range: " + param[0]);
|
||||
}
|
||||
m_id = n1n;
|
||||
m_id_end_of_range = n2n;
|
||||
} else {
|
||||
try {
|
||||
m_id = std::stoi(param[0]);
|
||||
} catch(...) {
|
||||
error->assign("Not able to convert '" + param[0] + "' into a number");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
m_target = param[1];
|
||||
@@ -54,8 +78,12 @@ bool RuleRemoveTargetById::init(std::string *error) {
|
||||
|
||||
|
||||
bool RuleRemoveTargetById::execute(Transaction *transaction) const noexcept {
|
||||
transaction->m_ruleRemoveTargetById.push_back(
|
||||
std::make_pair(m_id, m_target));
|
||||
if (m_id_end_of_range == 0) {
|
||||
transaction->m_ruleRemoveTargetById.push_back(std::make_pair(m_id, m_target));
|
||||
} else {
|
||||
std::pair<int, int> id_range = std::make_pair(m_id, m_id_end_of_range);
|
||||
transaction->m_ruleRemoveTargetByIdRange.push_back(std::make_pair(id_range, m_target));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ class RuleRemoveTargetById : public ActionWithExecution {
|
||||
explicit RuleRemoveTargetById(const std::string &action)
|
||||
: Action(action),
|
||||
m_id(0),
|
||||
m_id_end_of_range(0),
|
||||
m_target("")
|
||||
{ }
|
||||
|
||||
@@ -44,6 +45,7 @@ class RuleRemoveTargetById : public ActionWithExecution {
|
||||
|
||||
private:
|
||||
int m_id;
|
||||
int m_id_end_of_range;
|
||||
std::string m_target;
|
||||
};
|
||||
|
||||
|
||||
@@ -194,6 +194,14 @@ inline void RuleWithOperator::getFinalVars(variables::Variables *vars,
|
||||
}) != trans->m_ruleRemoveTargetById.end()) {
|
||||
continue;
|
||||
}
|
||||
if (std::find_if(trans->m_ruleRemoveTargetByIdRange.begin(),
|
||||
trans->m_ruleRemoveTargetByIdRange.end(),
|
||||
[&, variable, this](std::pair<std::pair<int, int>, std::string> &m) -> bool {
|
||||
return (m.first.first <= getId() && m.first.second >= getId()
|
||||
&& m.second == *variable->getVariableKeyWithCollection());
|
||||
}) != trans->m_ruleRemoveTargetByIdRange.end()) {
|
||||
continue;
|
||||
}
|
||||
if (std::find_if(trans->m_ruleRemoveTargetByTag.begin(),
|
||||
trans->m_ruleRemoveTargetByTag.end(),
|
||||
[&, variable, trans, this](
|
||||
@@ -289,6 +297,17 @@ bool RuleWithOperator::evaluate(Transaction *trans) const {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (exclusion.contains(v) ||
|
||||
std::find_if(trans->m_ruleRemoveTargetByIdRange.begin(),
|
||||
trans->m_ruleRemoveTargetByIdRange.end(),
|
||||
[&, v, this](std::pair<std::pair<int, int>, std::string> &m) -> bool {
|
||||
return (m.first.first <= getId() && m.first.second >= getId()
|
||||
&& m.second == v->getName());
|
||||
}) != trans->m_ruleRemoveTargetByIdRange.end()
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (exclusion.contains(v) ||
|
||||
std::find_if(trans->m_ruleRemoveTargetByTag.begin(),
|
||||
trans->m_ruleRemoveTargetByTag.end(),
|
||||
|
||||
Reference in New Issue
Block a user