Adds support to variables: REQUEST_{METHOD,PROTOCOL,URI,URI_RAW}

This commit is contained in:
Felipe Zimmerle 2015-07-22 02:05:58 -03:00
parent bc925e01e6
commit ec34f676c6
5 changed files with 184 additions and 0 deletions

View File

@ -239,6 +239,10 @@ int Assay::processURI(const char *uri, const char *protocol,
path_info.length() - offset);
store_variable("REQUEST_BASENAME", basename);
}
store_variable("REQUEST_METHOD", protocol);
store_variable("REQUEST_PROTOCOL", "HTTP/" + std::string(http_version));
store_variable("REQUEST_URI", uri);
store_variable("REQUEST_URI_RAW", uri);
if (pos != NULL && strlen(pos) > 2) {
/**

View File

@ -0,0 +1,45 @@
[
{
"enabled":1,
"version_min":300000,
"title":"Testing Variables :: REQUEST_METHOD",
"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":"*/*"
},
"uri":"/?key=value&key=other_value",
"protocol":"GET",
"http_version":1.1
},
"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":{
"debug_log":"Target value: \"GET\" \\(Variable: REQUEST_METHOD\\)"
},
"rules":[
"SecRuleEngine On",
"SecDebugLog \/tmp\/modsec_debug.log",
"SecDebugLogLevel 9",
"SecRule REQUEST_METHOD \"@contains test \" \"pass,t:trim\""
]
}
]

View File

@ -0,0 +1,45 @@
[
{
"enabled":1,
"version_min":300000,
"title":"Testing Variables :: REQUEST_PROTOCOL",
"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":"*/*"
},
"uri":"/?key=value&key=other_value",
"protocol":"GET",
"http_version":1.1
},
"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":{
"debug_log":"Target value: \"HTTP/1.1\" \\(Variable: REQUEST_PROTOCOL\\)"
},
"rules":[
"SecRuleEngine On",
"SecDebugLog \/tmp\/modsec_debug.log",
"SecDebugLogLevel 9",
"SecRule REQUEST_PROTOCOL \"@contains test \" \"pass,t:trim\""
]
}
]

View File

@ -0,0 +1,45 @@
[
{
"enabled":1,
"version_min":300000,
"title":"Testing Variables :: REQUEST_URI",
"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":"*/*"
},
"uri":"/?key=value&key=other_value",
"protocol":"GET",
"http_version":1.1
},
"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":{
"debug_log":"Target value: \"/\\?key=value\\&key=other_value\" \\(Variable: REQUEST_URI\\)"
},
"rules":[
"SecRuleEngine On",
"SecDebugLog \/tmp\/modsec_debug.log",
"SecDebugLogLevel 9",
"SecRule REQUEST_URI \"@contains test \" \"pass,t:trim\""
]
}
]

View File

@ -0,0 +1,45 @@
[
{
"enabled":1,
"version_min":300000,
"title":"Testing Variables :: REQUEST_URI_RAW",
"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":"*/*"
},
"uri":"/?key=value&key=other_value",
"protocol":"GET",
"http_version":1.1
},
"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":{
"debug_log":"Target value: \"/\\?key=value\\&key=other_value\" \\(Variable: REQUEST_URI_RAW\\)"
},
"rules":[
"SecRuleEngine On",
"SecDebugLog \/tmp\/modsec_debug.log",
"SecDebugLogLevel 9",
"SecRule REQUEST_URI_RAW \"@contains test \" \"pass,t:trim\""
]
}
]