mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-11-19 02:40:35 +03:00
Adds new method for rule merge
IMPORTANT: SecDefaultAction specified on a child configuration will overwrite the ones specified on the parent; Previously it was concatenating.
This commit is contained in:
@@ -31,6 +31,46 @@ using modsecurity::Utils::HttpsClient;
|
||||
|
||||
namespace modsecurity {
|
||||
|
||||
void Rules::fixDefaultActions() {
|
||||
for (size_t i = 0; i < m_rules.size(); i++) {
|
||||
auto &rule = m_rules[i];
|
||||
|
||||
RuleWithActions *r = dynamic_cast<RuleWithActions *>(rule.get());
|
||||
if (!r) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (dynamic_cast<RuleWithOperator *>(rule.get())) {
|
||||
RuleWithOperator *op = new RuleWithOperator(*dynamic_cast<RuleWithOperator *>(rule.get()));
|
||||
std::unique_ptr<RuleWithOperator> nrp(op);
|
||||
m_rules[i] = std::move(nrp);
|
||||
} else if (dynamic_cast<RuleUnconditional *>(rule.get())) {
|
||||
RuleUnconditional *un = new RuleUnconditional(*dynamic_cast<RuleUnconditional *>(rule.get()));
|
||||
std::unique_ptr<RuleUnconditional> nrp(un);
|
||||
m_rules[i] = std::move(nrp);
|
||||
} else if (dynamic_cast<RuleScript *>(rule.get())) {
|
||||
RuleScript *rs = new RuleScript(*dynamic_cast<RuleScript *>(rule.get()));
|
||||
std::unique_ptr<RuleScript> nrp(rs);
|
||||
m_rules[i] = std::move(nrp);
|
||||
} else {
|
||||
RuleWithActions *nr = new RuleWithActions(*dynamic_cast<RuleWithActions *>(rule.get()));
|
||||
std::unique_ptr<RuleWithActions> nrp(nr);
|
||||
m_rules[i] = std::move(nrp);
|
||||
}
|
||||
|
||||
RuleWithActions *nr = dynamic_cast<RuleWithActions *>(m_rules[i].get());
|
||||
nr->clearDefaultActions();
|
||||
for (auto a : m_defaultActions) {
|
||||
nr->addDefaultAction(a);
|
||||
}
|
||||
for (auto a : m_defaultTransformations) {
|
||||
nr->addDefaultTransformation(a);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @name loadFromUri
|
||||
|
||||
Reference in New Issue
Block a user