Adds first version of `processContentOffset'

This commit also includes an example application on how to use the
`processContentOffset' method.
This commit is contained in:
Felipe Zimmerle
2017-02-15 18:18:10 -03:00
committed by Felipe Zimmerle
parent 7aae5dc183
commit 027d50b76b
11 changed files with 325 additions and 95 deletions

View File

@@ -35,18 +35,10 @@ std::string LowerCase::evaluate(std::string value,
Transaction *transaction) {
std::locale loc;
if (LowerCaseInstantCache::getInstance().count(value) > 0) {
return LowerCaseInstantCache::getInstance().at(value);
}
std::string orig_value = value;
for (std::string::size_type i=0; i < value.length(); ++i) {
value[i] = std::tolower(value[i], loc);
}
LowerCaseInstantCache::getInstance().cache(orig_value, value);
return value;
}

View File

@@ -58,6 +58,11 @@
#include "src/actions/transformations/url_encode.h"
#include "src/actions/transformations/utf8_to_unicode.h"
#define IF_MATCH(b) \
if (a.compare(2, std::strlen(#b), #b) == 0)
namespace modsecurity {
namespace actions {
namespace transformations {
@@ -68,6 +73,49 @@ std::string Transformation::evaluate(std::string value,
return value;
}
Transformation* Transformation::instantiate(std::string a) {
IF_MATCH(base64DecodeExt) { return new Base64DecodeExt(a); }
IF_MATCH(base64Decode) { return new Base64Decode(a); }
IF_MATCH(base64Encode) { return new Base64Encode(a); }
IF_MATCH(cmd_line) { return new CmdLine(a); }
IF_MATCH(compress_whitespace) { return new CompressWhitespace(a); }
IF_MATCH(cssDecode) { return new CssDecode(a); }
IF_MATCH(escapeSeqDecode) { return new EscapeSeqDecode(a); }
IF_MATCH(hexDecode) { return new HexDecode(a); }
IF_MATCH(hexEncode) { return new HexEncode(a); }
IF_MATCH(htmlEntityDecode) { return new HtmlEntityDecode(a); }
IF_MATCH(jsDecode) { return new JsDecode(a); }
IF_MATCH(length) { return new Length(a); }
IF_MATCH(lowercase) { return new LowerCase(a); }
IF_MATCH(md5) { return new Md5(a); }
IF_MATCH(none) { return new None(a); }
IF_MATCH(normalizePathWin) { return new NormalisePathWin(a); }
IF_MATCH(normalisePathWin) { return new NormalisePathWin(a); }
IF_MATCH(normalizePath) { return new NormalisePath(a); }
IF_MATCH(normalisePath) { return new NormalisePath(a); }
IF_MATCH(parityEven7bit) { return new ParityEven7bit(a); }
IF_MATCH(parityOdd7bit) { return new ParityOdd7bit(a); }
IF_MATCH(parityZero7bit) { return new ParityZero7bit(a); }
IF_MATCH(removeCommentsChar) { return new RemoveCommentsChar(a); }
IF_MATCH(removeComments) { return new RemoveComments(a); }
IF_MATCH(removeNulls) { return new RemoveNulls(a); }
IF_MATCH(removeWhitespace) { return new RemoveWhitespace(a); }
IF_MATCH(compressWhitespace) { return new CompressWhitespace(a); }
IF_MATCH(replaceComments) { return new ReplaceComments(a); }
IF_MATCH(replaceNulls) { return new ReplaceNulls(a); }
IF_MATCH(sha1) { return new Sha1(a); }
IF_MATCH(sqlHexDecode) { return new SqlHexDecode(a); }
IF_MATCH(transformation) { return new Transformation(a); }
IF_MATCH(trimLeft) { return new TrimLeft(a); }
IF_MATCH(trimRight) { return new TrimRight(a); }
IF_MATCH(trim) { return new Trim(a); }
IF_MATCH(urlDecodeUni) { return new UrlDecodeUni(a); }
IF_MATCH(urlDecode) { return new UrlDecode(a); }
IF_MATCH(urlEncode) { return new UrlEncode(a); }
IF_MATCH(utf8ToUnicode) { return new Utf8ToUnicode(a); }
return new Transformation(a);
}
} // namespace transformations
} // namespace actions

View File

@@ -20,6 +20,7 @@
#ifndef SRC_ACTIONS_TRANSFORMATIONS_TRANSFORMATION_H_
#define SRC_ACTIONS_TRANSFORMATIONS_TRANSFORMATION_H_
namespace modsecurity {
class Transaction;
@@ -36,6 +37,9 @@ class Transformation : public Action {
std::string evaluate(std::string exp,
Transaction *transaction) override;
static Transformation* instantiate(std::string a);
};
} // namespace transformations