diff --git a/CHANGES b/CHANGES index 10ca5cb9..056b7f21 100644 --- a/CHANGES +++ b/CHANGES @@ -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 diff --git a/Makefile.am b/Makefile.am index 7cf6d208..370b3ef7 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 diff --git a/src/operators/verify_cpf.cc b/src/operators/verify_cpf.cc index f8261639..94759ba1 100644 --- a/src/operators/verify_cpf.cc +++ b/src/operators/verify_cpf.cc @@ -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) { std::list 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; } } diff --git a/test/test-cases/regression/operator-verifycpf.json b/test/test-cases/regression/operator-verifycpf.json new file mode 100644 index 00000000..669f3eca --- /dev/null +++ b/test/test-cases/regression/operator-verifycpf.json @@ -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¶m2=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\"" + ] + } +]