mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-08-14 05:45:59 +03:00
Adds support to the variables: RESPONSE{BODY,CONTENT_LENGTH,CONTENT_TYPE}
This commit is contained in:
parent
ec34f676c6
commit
ae81bb1433
@ -664,6 +664,9 @@ int Assay::addResponseHeader(const std::string& key,
|
||||
|
||||
this->store_variable("RESPONSE_HEADERS:" + key, value);
|
||||
|
||||
if (tolower(key) == "content-type") {
|
||||
this->store_variable("RESPONSE_CONTENT_TYPE", value);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -748,6 +751,10 @@ int Assay::processResponseBody() {
|
||||
store_variable("OUTBOUND_DATA_ERROR", "0");
|
||||
}
|
||||
|
||||
store_variable("RESPONSE_BODY", m_responseBody.str());
|
||||
store_variable("RESPONSE_CONTENT_LENGTH",
|
||||
std::to_string(m_responseBody.str().size()));
|
||||
|
||||
this->m_rules->evaluate(ModSecurity::ResponseBodyPhase, this);
|
||||
return 0;
|
||||
}
|
||||
|
45
test/test-cases/regression/variable-RESPONSE_BODY.json
Normal file
45
test/test-cases/regression/variable-RESPONSE_BODY.json
Normal file
@ -0,0 +1,45 @@
|
||||
[
|
||||
{
|
||||
"enabled":1,
|
||||
"version_min":300000,
|
||||
"title":"Testing Variables :: RESPONSE_BODY",
|
||||
"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: \"no need.\" \\(Variable: RESPONSE_BODY\\)"
|
||||
},
|
||||
"rules":[
|
||||
"SecRuleEngine On",
|
||||
"SecDebugLog \/tmp\/modsec_debug.log",
|
||||
"SecDebugLogLevel 9",
|
||||
"SecRule RESPONSE_BODY \"@contains test \" \"phase:4,pass,t:trim\""
|
||||
]
|
||||
}
|
||||
]
|
||||
|
@ -0,0 +1,45 @@
|
||||
[
|
||||
{
|
||||
"enabled":1,
|
||||
"version_min":300000,
|
||||
"title":"Testing Variables :: RESPONSE_CONTENT_LENGTH",
|
||||
"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: \"9\" \\(Variable: RESPONSE_CONTENT_LENGTH\\)"
|
||||
},
|
||||
"rules":[
|
||||
"SecRuleEngine On",
|
||||
"SecDebugLog \/tmp\/modsec_debug.log",
|
||||
"SecDebugLogLevel 9",
|
||||
"SecRule RESPONSE_CONTENT_LENGTH \"@contains test \" \"phase:4,pass,t:trim\""
|
||||
]
|
||||
}
|
||||
]
|
||||
|
@ -0,0 +1,45 @@
|
||||
[
|
||||
{
|
||||
"enabled":1,
|
||||
"version_min":300000,
|
||||
"title":"Testing Variables :: RESPONSE_CONTENT_TYPE",
|
||||
"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: \"text/html\" \\(Variable: RESPONSE_CONTENT_TYPE\\)"
|
||||
},
|
||||
"rules":[
|
||||
"SecRuleEngine On",
|
||||
"SecDebugLog \/tmp\/modsec_debug.log",
|
||||
"SecDebugLogLevel 9",
|
||||
"SecRule RESPONSE_CONTENT_TYPE \"@contains test \" \"phase:3,pass,t:trim\""
|
||||
]
|
||||
}
|
||||
]
|
||||
|
Loading…
x
Reference in New Issue
Block a user