Skip to content

Commit 5e65d56

Browse files
defanatorFelipe Zimmerle
authored andcommitted
Fix utils::string::ssplit() to handle delimiter in the end of string
This closes #1743.
1 parent 5018358 commit 5e65d56

File tree

4 files changed

+82
-2
lines changed

4 files changed

+82
-2
lines changed

Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ TESTS+=test/test-cases/regression/issue-1576.json
136136
TESTS+=test/test-cases/regression/issue-1591.json
137137
TESTS+=test/test-cases/regression/issue-394.json
138138
TESTS+=test/test-cases/regression/issue-960.json
139+
TESTS+=test/test-cases/regression/issue-1743.json
139140
TESTS+=test/test-cases/regression/misc.json
140141
TESTS+=test/test-cases/regression/misc-variable-under-quotes.json
141142
TESTS+=test/test-cases/regression/offset-variable.json

src/utils/string.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,14 @@ std::vector<std::string> ssplit(std::string str, char delimiter) {
178178
std::vector<std::string> internal;
179179
std::stringstream ss(str); // Turn the string into a stream.
180180
std::string tok;
181+
ssize_t n = str.length();
182+
int i = 0;
181183

182184
while (getline(ss, tok, delimiter)) {
183-
internal.push_back(tok);
185+
n -= tok.length();
186+
if (i > 0) n--;
187+
internal.push_back(n == 1 ? tok + delimiter : tok);
188+
i++;
184189
}
185190

186191
return internal;

test/test-cases/regression/action-tnf-base64.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
"uri":"/",
6767
"method":"POST",
6868
"body": [
69-
"param1=dmFsdWUyCg==&param2=value2"
69+
"param1=dmFsdWUy&param2=value2"
7070
]
7171
},
7272
"response":{
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
[
2+
{
3+
"enabled": 1,
4+
"version_min": 209000,
5+
"version_max": -1,
6+
"title": "Regex match does not work when arg ends with unescaped equal char (1/2)",
7+
"url": "https:\/\/github.com\/SpiderLabs\/ModSecurity\/issues\/1743",
8+
"gihub_issue": 9999,
9+
"client": {
10+
"ip": "200.249.12.31",
11+
"port": 2313
12+
},
13+
"server": {
14+
"ip": "200.249.12.31",
15+
"port": 80
16+
},
17+
"request": {
18+
"uri":"/?x=foo%3d",
19+
"headers": "",
20+
"body": "",
21+
"method": "GET",
22+
"http_version": 1.1
23+
},
24+
"response": {
25+
"headers": "",
26+
"body": ""
27+
},
28+
"expected": {
29+
"debug_log": "Rule returned 1",
30+
"error_log": "Value: `foo='",
31+
"http_code": 403
32+
},
33+
"rules": [
34+
"SecRuleEngine On",
35+
"SecRule ARGS \"foo?=\" \"phase:2,id:1,capture,t:none,t:lowercase,deny,msg:'XSS Attack Detected',logdata:'Matched Data: %{TX.0} found within %{MATCHED_VAR_NAME}: %{MATCHED_VAR}'\""
36+
]
37+
},
38+
{
39+
"enabled": 1,
40+
"version_min": 209000,
41+
"version_max": -1,
42+
"title": "Regex match does not work when arg ends with unescaped equal char (2/2)",
43+
"url": "https:\/\/github.com\/SpiderLabs\/ModSecurity\/issues\/1743",
44+
"gihub_issue": 9999,
45+
"client": {
46+
"ip": "200.249.12.31",
47+
"port": 2313
48+
},
49+
"server": {
50+
"ip": "200.249.12.31",
51+
"port": 80
52+
},
53+
"request": {
54+
"uri":"/?x=foo=",
55+
"headers": "",
56+
"body": "",
57+
"method": "GET",
58+
"http_version": 1.1
59+
},
60+
"response": {
61+
"headers": "",
62+
"body": ""
63+
},
64+
"expected": {
65+
"debug_log": "Rule returned 1",
66+
"error_log": "Value: `foo='",
67+
"http_code": 403
68+
},
69+
"rules": [
70+
"SecRuleEngine On",
71+
"SecRule ARGS \"foo?=\" \"phase:2,id:1,capture,t:none,t:lowercase,deny,msg:'XSS Attack Detected',logdata:'Matched Data: %{TX.0} found within %{MATCHED_VAR_NAME}: %{MATCHED_VAR}'\""
72+
]
73+
}
74+
]

0 commit comments

Comments
 (0)