Adds support to urlDecodeUni transformation

This commit is contained in:
Felipe Zimmerle
2015-08-05 22:54:48 -03:00
parent 6dad6af4a9
commit 522f195aa0
7 changed files with 171 additions and 14 deletions

View File

@@ -105,7 +105,7 @@ Transformation* Transformation::instantiate(std::string a) {
IF_MATCH(trim_left) { return new TrimLeft(a); }
IF_MATCH(trim_right) { return new TrimRight(a); }
IF_MATCH(url_decode) { return new UrlDecode(a); }
IF_MATCH(url_decode_uni) { return new UrlDecodeUni(a); }
IF_MATCH(urlDecodeUni) { return new UrlDecodeUni(a); }
IF_MATCH(url_encode) { return new UrlEncode(a); }
IF_MATCH(utf8_to_unicode) { return new Utf8Unicode(a); }

View File

@@ -15,6 +15,8 @@
#include "actions/transformations/url_decode_uni.h"
#include <string.h>
#include <iostream>
#include <string>
#include <algorithm>
@@ -24,26 +26,28 @@
#include "modsecurity/assay.h"
#include "actions/transformations/transformation.h"
#include "src/utils.h"
namespace ModSecurity {
namespace actions {
namespace transformations {
UrlDecodeUni::UrlDecodeUni(std::string action)
: Transformation(action) {
this->action_kind = 1;
}
std::string UrlDecodeUni::evaluate(std::string value,
Assay *assay) {
/**
* @todo Implement the transformation UrlDecodeUni
*/
assay->debug(4, "Transformation UrlDecodeUni is not implemented yet.");
return value;
int changed = 0;
char *tmp = strdup(value.c_str());
int res = urldecode_uni_nonstrict_inplace_ex(assay, (unsigned char *)tmp,
value.size(), &changed);
std::string ret("");
ret.assign(tmp);
free(tmp);
return ret;
}
} // namespace transformations
} // namespace actions
} // namespace ModSecurity

View File

@@ -30,7 +30,9 @@ namespace transformations {
class UrlDecodeUni : public Transformation {
public:
explicit UrlDecodeUni(std::string action);
explicit UrlDecodeUni(std::string action)
: Transformation(action) { }
std::string evaluate(std::string exp,
Assay *assay) override;
};