Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/rule_with_operator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -158,16 +158,23 @@ inline void RuleWithOperator::getFinalVars(variables::Variables *vars,
variables::Variables addition;
getVariablesExceptions(*trans, exclusion, &addition); // cppcheck-suppress ctunullpointer

for (int i = 0; i < m_variables->size(); i++) {
for (std::size_t i = 0; i < m_variables->size(); i++) {
Variable *variable = m_variables->at(i);
if (exclusion->contains(variable)) {
continue;
}
if (std::find_if(trans->m_ruleRemoveTargetById.begin(),
trans->m_ruleRemoveTargetById.end(),
[&, variable, this](const auto &m) -> bool {
return m.first == m_ruleId
&& m.second == *variable->m_fullName.get();
const auto& str1 = m.second;
const auto& str2 = *variable->m_fullName.get();
return m.first == m_ruleId &&
str1.size() == str2.size() &&
std::equal(str1.begin(), str1.end(), str2.begin(),
[](char a, char b) {
return std::tolower(static_cast<unsigned char>(a)) ==
std::tolower(static_cast<unsigned char>(b));
}); // end-of std::equal
}) != trans->m_ruleRemoveTargetById.end()) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,73 @@
"SecRule REQUEST_FILENAME \"@endsWith /wp-login.php\" \"id:9002100,phase:2,t:none,nolog,pass,ctl:ruleRemoveTargetById=1;ARGS\"",
"SecRule ARGS \"@contains lhebs\" \"id:1,phase:3,t:none,status:202,block,deny,tag:'CRS'\""
]
},
{
"enabled":1,
"version_min":300000,
"title":"Testing CtlRuleRemoveTargetById (4): uppercase `Referer` header",
"expected":{
"http_code": 200
},
"client":{
"ip":"200.249.12.31",
"port":123
},
"request":{
"headers":{
"Host":"localhost",
"User-Agent":"curl/7.38.0",
"Accept":"*/*",
"Cookie": "PHPSESSID=rAAAAAAA2t5uvjq435r4q7ib3vtdjq120",
"Content-Type": "text/xml",
"Referer": "This is an attack"
},
"uri":"/index.html",
"method":"GET",
"body": [ ]
},
"server":{
"ip":"200.249.12.31",
"port":80
},
"rules":[
"SecRuleEngine On",
"SecRule REQUEST_FILENAME \"@unconditionalMatch\" \"id:1,phase:1,pass,t:none,ctl:ruleRemoveTargetById=2;REQUEST_HEADERS:referer\"",
"SecRule REQUEST_HEADERS:Referer \"@contains attack\" \"id:2,phase:1,deny,t:none,log\""
]
},
{
"enabled":1,
"version_min":300000,
"title":"Testing CtlRuleRemoveTargetById (5): lowercase `Referer` header",
"expected":{
"http_code": 200
},
"client":{
"ip":"200.249.12.31",
"port":123
},
"request":{
"headers":{
"Host":"localhost",
"User-Agent":"curl/7.38.0",
"Accept":"*/*",
"Cookie": "PHPSESSID=rAAAAAAA2t5uvjq435r4q7ib3vtdjq120",
"Content-Type": "text/xml",
"referer": "This is an attack"
},
"uri":"/index.html",
"method":"GET",
"body": [ ]
},
"server":{
"ip":"200.249.12.31",
"port":80
},
"rules":[
"SecRuleEngine On",
"SecRule REQUEST_FILENAME \"@unconditionalMatch\" \"id:1,phase:1,pass,t:none,ctl:ruleRemoveTargetById=2;REQUEST_HEADERS:referer\"",
"SecRule REQUEST_HEADERS:Referer \"@contains attack\" \"id:2,phase:1,deny,t:none,log\""
]
}
]
Loading