Skip to content

Commit 0b494c4

Browse files
author
Felipe Zimmerle
committed
Adds capture action to verifyCPF
1 parent 64ce412 commit 0b494c4

File tree

4 files changed

+61
-3
lines changed

4 files changed

+61
-3
lines changed

CHANGES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
v3.0.x - YYYY-MMM-DD (To be released)
22
-------------------------------------
33

4+
- Adds capture action to verifyCPF
5+
[Issue #1698 - @zimmerle]
46
- Prettier error messages for unsupported configurations (UX)
57
[@victorhora]
68
- Add missing verify*** transformation statements to parser

Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ TESTS+=test/test-cases/regression/operator-ipMatchFromFile.json
144144
TESTS+=test/test-cases/regression/operator-rx.json
145145
TESTS+=test/test-cases/regression/operator-UnconditionalMatch.json
146146
TESTS+=test/test-cases/regression/operator-validate-byte-range.json
147+
TESTS+=test/test-cases/regression/operator-verifycpf.json
147148
TESTS+=test/test-cases/regression/request-body-parser-json.json
148149
TESTS+=test/test-cases/regression/request-body-parser-multipart-crlf.json
149150
TESTS+=test/test-cases/regression/request-body-parser-multipart.json

src/operators/verify_cpf.cc

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ bool VerifyCPF::verify(const char *cpfnumber, int len) {
117117
}
118118

119119

120-
bool VerifyCPF::evaluate(Transaction *transaction, Rule *rule,
120+
bool VerifyCPF::evaluate(Transaction *t, Rule *rule,
121121
const std::string& input, std::shared_ptr<RuleMessage> ruleMessage) {
122122
std::list<SMatch> matches;
123123
bool is_cpf = false;
@@ -129,11 +129,20 @@ bool VerifyCPF::evaluate(Transaction *transaction, Rule *rule,
129129

130130
for (i = 0; i < input.size() - 1 && is_cpf == false; i++) {
131131
matches = m_re->searchAll(input.substr(i, input.size()));
132-
133132
for (const auto & i : matches) {
134133
is_cpf = verify(i.match.c_str(), i.match.size());
135-
logOffset(ruleMessage, i.m_offset, i.m_length);
136134
if (is_cpf) {
135+
logOffset(ruleMessage, i.m_offset, i.m_length);
136+
if (rule && t
137+
&& rule->getActionsByName("capture").size() > 0) {
138+
t->m_collections.m_tx_collection->storeOrUpdateFirst(
139+
"0", std::string(i.match));
140+
#ifndef NO_LOGS
141+
t->debug(7, "Added VerifyCPF match TX.0: " + \
142+
std::string(i.match));
143+
#endif
144+
}
145+
137146
goto out;
138147
}
139148
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
[
2+
{
3+
"enabled":1,
4+
"version_min":300000,
5+
"title":"Testing Operator :: @verifycpf (1/2)",
6+
"client":{
7+
"ip":"200.249.12.31",
8+
"port":123
9+
},
10+
"server":{
11+
"ip":"200.249.12.31",
12+
"port":80
13+
},
14+
"request":{
15+
"headers":{
16+
"Host":"localhost",
17+
"User-Agent":"curl/7.38.0",
18+
"Accept":"*/*",
19+
"Content-Length": "27",
20+
"Content-Type": "application/x-www-form-urlencoded"
21+
},
22+
"uri":"/",
23+
"method":"POST",
24+
"body": [
25+
"param1=010.817.514-60&param2=value2"
26+
]
27+
},
28+
"response":{
29+
"headers":{
30+
"Date":"Mon, 13 Jul 2015 20:02:41 GMT",
31+
"Last-Modified":"Sun, 26 Oct 2014 22:33:37 GMT",
32+
"Content-Type":"text/html"
33+
},
34+
"body":[
35+
"no need."
36+
]
37+
},
38+
"expected":{
39+
"debug_log":"Added VerifyCPF match TX.0: 010.817.514-60"
40+
},
41+
"rules":[
42+
"SecRuleEngine On",
43+
"SecRule ARGS \"@verifycpf ^([0-9]{3}\\.){2}[0-9]{3}-[0-9]{2}$\" \"id:1,phase:2,capture,pass,t:trim\""
44+
]
45+
}
46+
]

0 commit comments

Comments
 (0)