Skip to content

Commit

Permalink
Change REQUEST_FILENAME behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
airween committed Jan 30, 2024
1 parent a859574 commit 5f28c2b
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 18 deletions.
26 changes: 11 additions & 15 deletions src/transaction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,14 @@ int Transaction::processURI(const char *uri, const char *method,

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

std::string path_info_raw;
if (pos_raw_query == std::string::npos) {
path_info_raw = std::string(uri_s, 0);
} else {
path_info_raw = std::string(uri_s, 0, pos_raw_query);
}
std::string path_info = utils::uri_decode(path_info_raw);

m_uri_decoded = utils::uri_decode(uri_s);

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


size_t pos_query = m_uri_decoded.find("?");
if (pos_query != std::string::npos) {
m_uri_no_query_string_decoded = std::unique_ptr<std::string>(
new std::string(m_uri_decoded, 0, pos_query));
} else {
m_uri_no_query_string_decoded = std::unique_ptr<std::string>(
new std::string(m_uri_decoded));
}
m_uri_no_query_string_decoded = std::unique_ptr<std::string>(
new std::string(path_info));


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

std::string path_info;
if (pos_query == std::string::npos) {
path_info = std::string(m_uri_decoded, 0);
} else {
path_info = std::string(m_uri_decoded, 0, pos_query);
}

if (var_size == std::string::npos) {
var_size = uri_s.size();
}
Expand Down
50 changes: 47 additions & 3 deletions test/test-cases/regression/variable-PATH_INFO.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
"enabled":1,
"version_min":300000,
"title":"Testing Variables :: PATH_INFO (1/3)",
"title":"Testing Variables :: PATH_INFO (1/4)",
"client":{
"ip":"200.249.12.31",
"port":123
Expand Down Expand Up @@ -46,7 +46,7 @@
{
"enabled":1,
"version_min":300000,
"title":"Testing Variables :: PATH_INFO (2/3)",
"title":"Testing Variables :: PATH_INFO (2/4)",
"client":{
"ip":"200.249.12.31",
"port":123
Expand Down Expand Up @@ -90,7 +90,7 @@
{
"enabled":1,
"version_min":300000,
"title":"Testing Variables :: PATH_INFO (3/3)",
"title":"Testing Variables :: PATH_INFO (3/4)",
"client":{
"ip":"200.249.12.31",
"port":123
Expand Down Expand Up @@ -130,5 +130,49 @@
"SecRuleEngine On",
"SecRule PATH_INFO \"@contains test \" \"id:1,phase:3,pass,t:trim\""
]
},
{
"enabled":1,
"version_min":300000,
"title":"Testing Variables :: PATH_INFO (4/4)",
"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":"/one/t%3fo/three?key=value",
"method":"POST",
"body":[
"param1=value1&param2=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":{
"http_code": 403
},
"rules":[
"SecRuleEngine On",
"SecRule PATH_INFO \"@contains three\" \"id:1,phase:2,deny,status:403,t:trim\""
]
}
]

0 comments on commit 5f28c2b

Please sign in to comment.