Skip to content

Commit 51e9fb7

Browse files
author
Felipe Zimmerle
committed
Adds support for /32 in @ipMatch cidr notation.
/32 is the representation of the ip itself. Not sure if it is needed, but there is a complaint for that: #849
1 parent 425ae1d commit 51e9fb7

File tree

4 files changed

+105
-7
lines changed

4 files changed

+105
-7
lines changed

CHANGES

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

4+
- @ipMatch "Could not add entry" on slash/32 notation in 2.9.0
5+
[Issue #849 - @zimmerle, @dune73]
46
- Using values after transformation at MATCHED_VARS
57
[0x70e32 @zimmerle]
68
- Adds support to UpdateActionById.

Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ TESTS+=test/test-cases/regression/variable-ARGS_GET.json
218218
TESTS+=test/test-cases/regression/config-update-target-by-msg.json
219219
TESTS+=test/test-cases/regression/variable-UNIQUE_ID.json
220220
TESTS+=test/test-cases/regression/issue-1528.json
221+
TESTS+=test/test-cases/regression/issue-849.json
221222
TESTS+=test/test-cases/regression/variable-REQBODY_PROCESSOR_ERROR.json
222223
TESTS+=test/test-cases/regression/operator-detectxss.json
223224
TESTS+=test/test-cases/regression/config-update-target-by-tag.json

src/utils/msc_tree.cc

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -846,16 +846,14 @@ TreeNode *TreeAddIP(const char *buffer, CPTTree *tree, int type) {
846846
ptr = NULL;
847847
return NULL;
848848
}
849-
850-
if(ptr != NULL) {
849+
if (ptr != NULL) {
851850
free(ptr);
852851
ptr = NULL;
853852
}
854-
855-
if(netmask_v4 == 0) {
853+
if (netmask_v4 == 0) {
856854
return NULL;
857855
}
858-
else if (netmask_v4 != NETMASK_32 && pos < strlen(ip_strv4)) {
856+
else if (pos < strlen(ip_strv4)) {
859857
ip_strv4[pos] = '\0';
860858
}
861859

@@ -864,11 +862,9 @@ TreeNode *TreeAddIP(const char *buffer, CPTTree *tree, int type) {
864862
if (ret <= 0) {
865863
return NULL;
866864
}
867-
868865
ip = addr4.s_addr;
869866

870867
tree->count++;
871-
872868
return CPTAddElement((unsigned char *)&ip, NETMASK_32, tree, netmask_v4);
873869

874870
case IPV6_TREE:
@@ -1067,6 +1063,9 @@ unsigned char is_netmask_v4(char *ip_strv4) {
10671063
}
10681064

10691065
cidr = atoi(mask_str);
1066+
if (cidr == 32) {
1067+
return 32;
1068+
}
10701069
if ((cidr < 0) || (cidr > 32)) {
10711070
return 0;
10721071
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
[
2+
{
3+
"enabled": 1,
4+
"version_min": 209000,
5+
"version_max": -1,
6+
"title": "@ipMatch \"Could not add entry\" on slash\/32 notation in 2.9.0 (1/2)",
7+
"url": "https:\/\/github.com\/SpiderLabs\/ModSecurity\/issues\/849",
8+
"client": {
9+
"ip": "200.249.12.31",
10+
"port": 2313
11+
},
12+
"server": {
13+
"ip": "200.249.12.31",
14+
"port": 80
15+
},
16+
"request": {
17+
"headers": {
18+
"Host": "net.tutsplus.com",
19+
"User-Agent": "",
20+
"Accept": "text\/html,application\/xhtml+xml,application\/xml;q=0.9,*\/*;q=0.8",
21+
"Accept-Language": "en-us,en;q=0.5",
22+
"Accept-Encoding": "gzip,deflate",
23+
"Accept-Charset": "ISO-8859-1,utf-8;q=0.7,*;q=0.7",
24+
"Keep-Alive": "300",
25+
"Connection": "keep-alive",
26+
"Cookie": "PHPSESSID=r2t5uvjq435r4q7ib3vtdjq120",
27+
"Pragma": "no-cache",
28+
"Cache-Control": "no-cache"
29+
},
30+
"uri": "\/test.pl?foo=bar",
31+
"method": "GET",
32+
"http_version": 1.1,
33+
"body": ""
34+
},
35+
"response": {
36+
"headers": {
37+
"Content-Type": "text\/xml; charset=utf-8\n\r",
38+
"Content-Length": "length\n\r"
39+
}
40+
},
41+
"expected": {
42+
"http_code": 403
43+
},
44+
"rules": [
45+
"SecRuleEngine On",
46+
"SecRule REMOTE_ADDR \"@ipMatch 200.249.12.31\/32\" \"phase:1,nolog,pass,msg:'Localhost connection',id:1,deny,status:403\""
47+
]
48+
},
49+
{
50+
"enabled": 1,
51+
"version_min": 209000,
52+
"version_max": -1,
53+
"title": "@ipMatch \"Could not add entry\" on slash\/32 notation in 2.9.0 (2/2)",
54+
"url": "https:\/\/github.com\/SpiderLabs\/ModSecurity\/issues\/849",
55+
"client": {
56+
"ip": "200.249.12.31",
57+
"port": 2313
58+
},
59+
"server": {
60+
"ip": "200.249.12.31",
61+
"port": 80
62+
},
63+
"request": {
64+
"headers": {
65+
"Host": "net.tutsplus.com",
66+
"User-Agent": "",
67+
"Accept": "text\/html,application\/xhtml+xml,application\/xml;q=0.9,*\/*;q=0.8",
68+
"Accept-Language": "en-us,en;q=0.5",
69+
"Accept-Encoding": "gzip,deflate",
70+
"Accept-Charset": "ISO-8859-1,utf-8;q=0.7,*;q=0.7",
71+
"Keep-Alive": "300",
72+
"Connection": "keep-alive",
73+
"Cookie": "PHPSESSID=r2t5uvjq435r4q7ib3vtdjq120",
74+
"Pragma": "no-cache",
75+
"Cache-Control": "no-cache"
76+
},
77+
"uri": "\/test.pl?foo=bar",
78+
"method": "GET",
79+
"http_version": 1.1,
80+
"body": ""
81+
},
82+
"response": {
83+
"headers": {
84+
"Content-Type": "text\/xml; charset=utf-8\n\r",
85+
"Content-Length": "length\n\r"
86+
}
87+
},
88+
"expected": {
89+
"http_code": 403
90+
},
91+
"rules": [
92+
"SecRuleEngine On",
93+
"SecRule REMOTE_ADDR \"@ipMatch 200.249.12.31\" \"phase:1,nolog,pass,msg:'Localhost connection',id:1,deny,status:403\""
94+
]
95+
}
96+
]

0 commit comments

Comments
 (0)