From e48f468cbcaa22811db71ee3248ad1f9e3295a1f Mon Sep 17 00:00:00 2001 From: Felipe Zimmerle Date: Tue, 24 May 2016 10:04:06 -0300 Subject: [PATCH] Adds support to base64 decode transformation --- src/actions/transformations/base64_decode.cc | 18 +++++------------- src/actions/transformations/base64_decode.h | 3 ++- src/actions/transformations/transformation.cc | 2 +- 3 files changed, 8 insertions(+), 15 deletions(-) diff --git a/src/actions/transformations/base64_decode.cc b/src/actions/transformations/base64_decode.cc index a4c4e69a..cbb3c7f9 100644 --- a/src/actions/transformations/base64_decode.cc +++ b/src/actions/transformations/base64_decode.cc @@ -24,30 +24,22 @@ #include "modsecurity/transaction.h" #include "actions/transformations/transformation.h" +#include "utils/base64.h" namespace modsecurity { namespace actions { namespace transformations { -Base64Decode::Base64Decode(std::string action) - : Transformation(action) { - this->action_kind = 1; -} std::string Base64Decode::evaluate(std::string value, Transaction *transaction) { - /** - * @todo Implement the transformation base64decode - */ - if (transaction) { -#ifndef NO_LOGS - transaction->debug(4, "Transformation 64 is not implemented yet."); -#endif - } - return value; + std::string ret = Utils::Base64::decode(value); + + return ret; } + } // namespace transformations } // namespace actions } // namespace modsecurity diff --git a/src/actions/transformations/base64_decode.h b/src/actions/transformations/base64_decode.h index 564b9c84..e91d6898 100644 --- a/src/actions/transformations/base64_decode.h +++ b/src/actions/transformations/base64_decode.h @@ -30,7 +30,8 @@ namespace transformations { class Base64Decode : public Transformation { public: - explicit Base64Decode(std::string action); + explicit Base64Decode(std::string action) : Transformation(action) { }; + std::string evaluate(std::string exp, Transaction *transaction) override; }; diff --git a/src/actions/transformations/transformation.cc b/src/actions/transformations/transformation.cc index ae4cbf72..ae22f90a 100644 --- a/src/actions/transformations/transformation.cc +++ b/src/actions/transformations/transformation.cc @@ -74,7 +74,7 @@ std::string Transformation::evaluate(std::string value, Transformation* Transformation::instantiate(std::string a) { IF_MATCH(base64_decode_ext) { return new Base64DecodeExt(a); } - IF_MATCH(base64_decode) { return new Base64Decode(a); } + IF_MATCH(base64Decode) { return new Base64Decode(a); } IF_MATCH(cmd_line) { return new CmdLine(a); } IF_MATCH(compress_whitespace) { return new CompressWhitespace(a); } IF_MATCH(cssDecode) { return new CssDecode(a); }