mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-08-14 05:45:59 +03:00
Improves rules dump for better testing
This commit is contained in:
parent
8976e374f9
commit
ca26aee1ce
2
CHANGES
2
CHANGES
@ -1,6 +1,8 @@
|
|||||||
v3.x.y - YYYY-MMM-DD (to be released)
|
v3.x.y - YYYY-MMM-DD (to be released)
|
||||||
-------------------------------------
|
-------------------------------------
|
||||||
|
|
||||||
|
- More structured rules dump. Better supporting debugging.
|
||||||
|
[@zimmerle]
|
||||||
- Added the basics for supporting better error/warning handling while
|
- Added the basics for supporting better error/warning handling while
|
||||||
loading configurations.
|
loading configurations.
|
||||||
[@zimmerle]
|
[@zimmerle]
|
||||||
|
@ -46,15 +46,14 @@ class Rule {
|
|||||||
Rule(std::unique_ptr<std::string> fileName, int lineNumber)
|
Rule(std::unique_ptr<std::string> fileName, int lineNumber)
|
||||||
: m_fileName(std::move(fileName)),
|
: m_fileName(std::move(fileName)),
|
||||||
m_lineNumber(lineNumber),
|
m_lineNumber(lineNumber),
|
||||||
m_phase(modsecurity::Phases::RequestHeadersPhase) {
|
m_phase(modsecurity::Phases::RequestHeadersPhase)
|
||||||
}
|
{ }
|
||||||
|
|
||||||
Rule(const Rule &r)
|
Rule(const Rule &r)
|
||||||
: m_fileName(r.m_fileName),
|
: m_fileName(r.m_fileName),
|
||||||
m_lineNumber(r.m_lineNumber),
|
m_lineNumber(r.m_lineNumber),
|
||||||
m_phase(r.m_phase) {
|
m_phase(r.m_phase)
|
||||||
|
{ }
|
||||||
}
|
|
||||||
|
|
||||||
Rule &operator=(const Rule& other) {
|
Rule &operator=(const Rule& other) {
|
||||||
m_fileName = other.m_fileName;
|
m_fileName = other.m_fileName;
|
||||||
@ -80,6 +79,18 @@ class Rule {
|
|||||||
return *m_fileName + ":" + std::to_string(m_lineNumber);
|
return *m_fileName + ":" + std::to_string(m_lineNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void dump(std::stringstream &out) {
|
||||||
|
out << getOriginInTextFormat() << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
std::string getOriginInTextFormat() const {
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << "# File name: " << *getFileName() << std::endl;
|
||||||
|
ss << "# Line number: " << getLineNumber();
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<std::string> m_fileName;
|
std::shared_ptr<std::string> m_fileName;
|
||||||
int m_lineNumber;
|
int m_lineNumber;
|
||||||
|
@ -63,7 +63,12 @@ class Rules {
|
|||||||
std::vector<std::shared_ptr<actions::Action> > m_defaultActions;
|
std::vector<std::shared_ptr<actions::Action> > m_defaultActions;
|
||||||
std::vector<std::shared_ptr<actions::transformations::Transformation> > m_defaultTransformations;
|
std::vector<std::shared_ptr<actions::transformations::Transformation> > m_defaultTransformations;
|
||||||
|
|
||||||
void dump();
|
virtual void dump() {
|
||||||
|
std::stringstream ss;
|
||||||
|
dump(ss);
|
||||||
|
std::cout << ss.str();
|
||||||
|
};
|
||||||
|
virtual void dump(std::stringstream &out);
|
||||||
|
|
||||||
inline iterator begin() noexcept { return m_rules.begin(); }
|
inline iterator begin() noexcept { return m_rules.begin(); }
|
||||||
inline const_iterator cbegin() const noexcept { return m_rules.cbegin(); }
|
inline const_iterator cbegin() const noexcept { return m_rules.cbegin(); }
|
||||||
|
@ -44,6 +44,15 @@ class RuleMarker : public Rule {
|
|||||||
: Rule(std::move(fileName), lineNumber),
|
: Rule(std::move(fileName), lineNumber),
|
||||||
m_name(std::make_shared<std::string>(name)) { }
|
m_name(std::make_shared<std::string>(name)) { }
|
||||||
|
|
||||||
|
RuleMarker(RuleMarker &&r) :
|
||||||
|
Rule(r),
|
||||||
|
m_name(std::move(r.m_name))
|
||||||
|
{ };
|
||||||
|
|
||||||
|
RuleMarker(const RuleMarker &r) :
|
||||||
|
Rule(r),
|
||||||
|
m_name(std::move(r.m_name))
|
||||||
|
{ };
|
||||||
|
|
||||||
virtual bool evaluate(Transaction *transaction) override {
|
virtual bool evaluate(Transaction *transaction) override {
|
||||||
if (transaction->isInsideAMarker()) {
|
if (transaction->isInsideAMarker()) {
|
||||||
@ -62,6 +71,11 @@ class RuleMarker : public Rule {
|
|||||||
return m_name;
|
return m_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void dump(std::stringstream &out) override {
|
||||||
|
Rule::dump(out);
|
||||||
|
out << "SecMarker \"" << *getName() << "\"" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<std::string> m_name;
|
std::shared_ptr<std::string> m_name;
|
||||||
};
|
};
|
||||||
|
@ -454,6 +454,11 @@ class RuleWithActions : public Rule {
|
|||||||
return dst;
|
return dst;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
virtual void dump(std::stringstream &out) override {
|
||||||
|
out << "RuleWithActions" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
RuleId m_ruleId;
|
RuleId m_ruleId;
|
||||||
|
|
||||||
|
@ -30,6 +30,8 @@
|
|||||||
#include "modsecurity/variable_value.h"
|
#include "modsecurity/variable_value.h"
|
||||||
#include "modsecurity/rule.h"
|
#include "modsecurity/rule.h"
|
||||||
#include "src/rule_with_actions.h"
|
#include "src/rule_with_actions.h"
|
||||||
|
#include "src/variables/variable.h"
|
||||||
|
#include "src/operators/operator.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
||||||
@ -80,6 +82,15 @@ class RuleWithOperator : public RuleWithActions {
|
|||||||
return std::to_string(getId());
|
return std::to_string(getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void dump(std::stringstream &out) override {
|
||||||
|
Rule::dump(out);
|
||||||
|
out << "# RuleWithOperator" << std::endl;
|
||||||
|
out << "SecRule ";
|
||||||
|
out << m_variables->getVariableNames() << " ";
|
||||||
|
out << "\"" << "@" << m_operator->m_op << " " << m_operator->m_param << "\"";
|
||||||
|
out << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<modsecurity::variables::Variables> m_variables;
|
std::shared_ptr<modsecurity::variables::Variables> m_variables;
|
||||||
std::shared_ptr<operators::Operator> m_operator;
|
std::shared_ptr<operators::Operator> m_operator;
|
||||||
|
@ -57,13 +57,11 @@ std::shared_ptr<Rule> Rules::at(int index) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Rules::dump() {
|
void Rules::dump(std::stringstream &out) {
|
||||||
for (int j = 0; j < m_rules.size(); j++) {
|
for (auto &r : m_rules) {
|
||||||
std::cout << " Rule ID: " << m_rules.at(j)->getReference();
|
r->dump(out);
|
||||||
std::cout << "--" << m_rules.at(j) << std::endl;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace modsecurity
|
} // namespace modsecurity
|
||||||
|
|
||||||
|
@ -91,6 +91,7 @@ int main(int argc, char **argv) {
|
|||||||
if (err.empty() == false) {
|
if (err.empty() == false) {
|
||||||
std::cerr << " " << err << std::endl;
|
std::cerr << " " << err << std::endl;
|
||||||
}
|
}
|
||||||
|
rules->dump();
|
||||||
next:
|
next:
|
||||||
args++;
|
args++;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user