Uses macro expansion before apply redirect action

This commit is contained in:
Felipe Zimmerle 2015-09-17 09:30:39 -03:00
parent 90df21bbb1
commit 490ad23e41
2 changed files with 12 additions and 8 deletions

View File

@ -19,6 +19,7 @@
#include <string> #include <string>
#include "modsecurity/assay.h" #include "modsecurity/assay.h"
#include "src/macro_expansion.h"
namespace ModSecurity { namespace ModSecurity {
namespace actions { namespace actions {
@ -28,13 +29,14 @@ Redirect::~Redirect() {
Redirect::Redirect(const std::string& action) Redirect::Redirect(const std::string& action)
: Action(action, RunTimeOnlyIfMatchKind), : Action(action, RunTimeOnlyIfMatchKind),
url(action) { m_url(action) {
this->url = this->url.erase(0, 9); m_url = m_url.erase(0, 9);
this->status = 302; m_status = 302;
} }
bool Redirect::evaluate(Rule *rule, Assay *assay) { bool Redirect::evaluate(Rule *rule, Assay *assay) {
m_urlExpanded = MacroExpansion::expand(m_url, assay);
assay->actions.push_back(this); assay->actions.push_back(this);
return true; return true;
} }
@ -42,10 +44,10 @@ bool Redirect::evaluate(Rule *rule, Assay *assay) {
void Redirect::fill_intervention(ModSecurityIntervention *i) { void Redirect::fill_intervention(ModSecurityIntervention *i) {
/* if it was changed before, lets keep it. */ /* if it was changed before, lets keep it. */
if (i->status == 200) { if (i->status == 200) {
i->status = this->status; i->status = m_status;
} }
// reinterpret_cast<char *>
i->url = this->url.c_str(); //** TODO: wheee */ i->url = m_urlExpanded.c_str();
i->log = "Redirecting"; i->log = "Redirecting";
} }

View File

@ -34,10 +34,12 @@ class Redirect : public Action {
~Redirect() override; ~Redirect() override;
bool evaluate(Rule *rule, Assay *assay) override; bool evaluate(Rule *rule, Assay *assay) override;
int status;
std::string url;
void fill_intervention(ModSecurityIntervention *i) override; void fill_intervention(ModSecurityIntervention *i) override;
bool isDisruptive() override { return true; } bool isDisruptive() override { return true; }
private:
int m_status;
std::string m_urlExpanded;
std::string m_url;
}; };
} // namespace actions } // namespace actions