Skip to content

Commit d648a44

Browse files
authored
Merge pull request #3048 from airween/v3/encodedqm
Change REQUEST_FILENAME behavior
2 parents a859574 + 5f28c2b commit d648a44

File tree

2 files changed

+58
-18
lines changed

2 files changed

+58
-18
lines changed

src/transaction.cc

+11-15
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,14 @@ int Transaction::processURI(const char *uri, const char *method,
463463

464464
size_t pos_raw_query = uri_s.find("?");
465465

466+
std::string path_info_raw;
467+
if (pos_raw_query == std::string::npos) {
468+
path_info_raw = std::string(uri_s, 0);
469+
} else {
470+
path_info_raw = std::string(uri_s, 0, pos_raw_query);
471+
}
472+
std::string path_info = utils::uri_decode(path_info_raw);
473+
466474
m_uri_decoded = utils::uri_decode(uri_s);
467475

468476
size_t var_size = pos_raw_query;
@@ -477,15 +485,8 @@ int Transaction::processURI(const char *uri, const char *method,
477485
m_variableRequestProtocol.set("HTTP/" + std::string(http_version),
478486
m_variableOffset + requestLine.size() + 1);
479487

480-
481-
size_t pos_query = m_uri_decoded.find("?");
482-
if (pos_query != std::string::npos) {
483-
m_uri_no_query_string_decoded = std::unique_ptr<std::string>(
484-
new std::string(m_uri_decoded, 0, pos_query));
485-
} else {
486-
m_uri_no_query_string_decoded = std::unique_ptr<std::string>(
487-
new std::string(m_uri_decoded));
488-
}
488+
m_uri_no_query_string_decoded = std::unique_ptr<std::string>(
489+
new std::string(path_info));
489490

490491

491492
if (pos_raw_query != std::string::npos) {
@@ -495,12 +496,7 @@ int Transaction::processURI(const char *uri, const char *method,
495496
+ std::string(method).size() + 1);
496497
}
497498

498-
std::string path_info;
499-
if (pos_query == std::string::npos) {
500-
path_info = std::string(m_uri_decoded, 0);
501-
} else {
502-
path_info = std::string(m_uri_decoded, 0, pos_query);
503-
}
499+
504500
if (var_size == std::string::npos) {
505501
var_size = uri_s.size();
506502
}

test/test-cases/regression/variable-PATH_INFO.json

+47-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{
33
"enabled":1,
44
"version_min":300000,
5-
"title":"Testing Variables :: PATH_INFO (1/3)",
5+
"title":"Testing Variables :: PATH_INFO (1/4)",
66
"client":{
77
"ip":"200.249.12.31",
88
"port":123
@@ -46,7 +46,7 @@
4646
{
4747
"enabled":1,
4848
"version_min":300000,
49-
"title":"Testing Variables :: PATH_INFO (2/3)",
49+
"title":"Testing Variables :: PATH_INFO (2/4)",
5050
"client":{
5151
"ip":"200.249.12.31",
5252
"port":123
@@ -90,7 +90,7 @@
9090
{
9191
"enabled":1,
9292
"version_min":300000,
93-
"title":"Testing Variables :: PATH_INFO (3/3)",
93+
"title":"Testing Variables :: PATH_INFO (3/4)",
9494
"client":{
9595
"ip":"200.249.12.31",
9696
"port":123
@@ -130,5 +130,49 @@
130130
"SecRuleEngine On",
131131
"SecRule PATH_INFO \"@contains test \" \"id:1,phase:3,pass,t:trim\""
132132
]
133+
},
134+
{
135+
"enabled":1,
136+
"version_min":300000,
137+
"title":"Testing Variables :: PATH_INFO (4/4)",
138+
"client":{
139+
"ip":"200.249.12.31",
140+
"port":123
141+
},
142+
"server":{
143+
"ip":"200.249.12.31",
144+
"port":80
145+
},
146+
"request":{
147+
"headers":{
148+
"Host":"localhost",
149+
"User-Agent":"curl/7.38.0",
150+
"Accept":"*/*",
151+
"Content-Length":"27",
152+
"Content-Type":"application/x-www-form-urlencoded"
153+
},
154+
"uri":"/one/t%3fo/three?key=value",
155+
"method":"POST",
156+
"body":[
157+
"param1=value1&param2=value2"
158+
]
159+
},
160+
"response":{
161+
"headers":{
162+
"Date":"Mon, 13 Jul 2015 20:02:41 GMT",
163+
"Last-Modified":"Sun, 26 Oct 2014 22:33:37 GMT",
164+
"Content-Type":"text/html"
165+
},
166+
"body":[
167+
"no need."
168+
]
169+
},
170+
"expected":{
171+
"http_code": 403
172+
},
173+
"rules":[
174+
"SecRuleEngine On",
175+
"SecRule PATH_INFO \"@contains three\" \"id:1,phase:2,deny,status:403,t:trim\""
176+
]
133177
}
134178
]

0 commit comments

Comments
 (0)