Adds capture action to verifyCPF

This commit is contained in:
Felipe Zimmerle 2018-03-08 19:00:16 -03:00
parent 64ce41280d
commit 0b494c4cdc
No known key found for this signature in database
GPG Key ID: E6DFB08CE8B11277
4 changed files with 61 additions and 3 deletions

View File

@ -1,6 +1,8 @@
v3.0.x - YYYY-MMM-DD (To be released)
-------------------------------------
- Adds capture action to verifyCPF
[Issue #1698 - @zimmerle]
- Prettier error messages for unsupported configurations (UX)
[@victorhora]
- Add missing verify*** transformation statements to parser

View File

@ -144,6 +144,7 @@ TESTS+=test/test-cases/regression/operator-ipMatchFromFile.json
TESTS+=test/test-cases/regression/operator-rx.json
TESTS+=test/test-cases/regression/operator-UnconditionalMatch.json
TESTS+=test/test-cases/regression/operator-validate-byte-range.json
TESTS+=test/test-cases/regression/operator-verifycpf.json
TESTS+=test/test-cases/regression/request-body-parser-json.json
TESTS+=test/test-cases/regression/request-body-parser-multipart-crlf.json
TESTS+=test/test-cases/regression/request-body-parser-multipart.json

View File

@ -117,7 +117,7 @@ bool VerifyCPF::verify(const char *cpfnumber, int len) {
}
bool VerifyCPF::evaluate(Transaction *transaction, Rule *rule,
bool VerifyCPF::evaluate(Transaction *t, Rule *rule,
const std::string& input, std::shared_ptr<RuleMessage> ruleMessage) {
std::list<SMatch> matches;
bool is_cpf = false;
@ -129,11 +129,20 @@ bool VerifyCPF::evaluate(Transaction *transaction, Rule *rule,
for (i = 0; i < input.size() - 1 && is_cpf == false; i++) {
matches = m_re->searchAll(input.substr(i, input.size()));
for (const auto & i : matches) {
is_cpf = verify(i.match.c_str(), i.match.size());
logOffset(ruleMessage, i.m_offset, i.m_length);
if (is_cpf) {
logOffset(ruleMessage, i.m_offset, i.m_length);
if (rule && t
&& rule->getActionsByName("capture").size() > 0) {
t->m_collections.m_tx_collection->storeOrUpdateFirst(
"0", std::string(i.match));
#ifndef NO_LOGS
t->debug(7, "Added VerifyCPF match TX.0: " + \
std::string(i.match));
#endif
}
goto out;
}
}

View File

@ -0,0 +1,46 @@
[
{
"enabled":1,
"version_min":300000,
"title":"Testing Operator :: @verifycpf (1/2)",
"client":{
"ip":"200.249.12.31",
"port":123
},
"server":{
"ip":"200.249.12.31",
"port":80
},
"request":{
"headers":{
"Host":"localhost",
"User-Agent":"curl/7.38.0",
"Accept":"*/*",
"Content-Length": "27",
"Content-Type": "application/x-www-form-urlencoded"
},
"uri":"/",
"method":"POST",
"body": [
"param1=010.817.514-60&param2=value2"
]
},
"response":{
"headers":{
"Date":"Mon, 13 Jul 2015 20:02:41 GMT",
"Last-Modified":"Sun, 26 Oct 2014 22:33:37 GMT",
"Content-Type":"text/html"
},
"body":[
"no need."
]
},
"expected":{
"debug_log":"Added VerifyCPF match TX.0: 010.817.514-60"
},
"rules":[
"SecRuleEngine On",
"SecRule ARGS \"@verifycpf ^([0-9]{3}\\.){2}[0-9]{3}-[0-9]{2}$\" \"id:1,phase:2,capture,pass,t:trim\""
]
}
]