Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V3/reqbodyproc #2045

Open
wants to merge 3 commits into
base: v3/master
Choose a base branch
from
Open
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
58 changes: 34 additions & 24 deletions src/rule.cc
Original file line number Diff line number Diff line change
Expand Up @@ -728,39 +728,49 @@ bool Rule::evaluate(Transaction *trans,
values = executeDefaultTransformations(trans, value);

for (const auto &valueTemp : values) {
bool ret;
bool ret = false;
std::string valueAfterTrans = std::move(*valueTemp.first);

ret = executeOperatorAt(trans, key, valueAfterTrans, ruleMessage);
// REQUEST_BBODY available only in RequestBodyProcessor
// https://github.com/SpiderLabs/ModSecurity/wiki/Reference-Manual-(v2.x)#REQUEST_BODY
// "This variable is available only if the URLENCODED request body processor was used"
// assume that the current operator couldn't has any effect
if (key != "REQUEST_BODY" ||
(key == "REQUEST_BODY" &&
trans->m_requestBodyType != Transaction::MultiPartRequestBody &&
trans->m_requestBodyType != Transaction::JSONRequestBody &&
trans->m_requestBodyType != Transaction::XMLRequestBody)) {
ret = executeOperatorAt(trans, key, valueAfterTrans, ruleMessage);

if (ret == true) {
ruleMessage->m_match = m_op->resolveMatchMessage(trans,
key, value);
for (auto &i : v->m_orign) {
ruleMessage->m_reference.append(i->toText());
}

if (ret == true) {
ruleMessage->m_match = m_op->resolveMatchMessage(trans,
key, value);
for (auto &i : v->m_orign) {
ruleMessage->m_reference.append(i->toText());
}
ruleMessage->m_reference.append(*valueTemp.second);
updateMatchedVars(trans, key, valueAfterTrans);
executeActionsIndependentOfChainedRuleResult(trans,
&containsBlock, ruleMessage);

ruleMessage->m_reference.append(*valueTemp.second);
updateMatchedVars(trans, key, valueAfterTrans);
executeActionsIndependentOfChainedRuleResult(trans,
&containsBlock, ruleMessage);
bool isItToBeLogged = ruleMessage->m_saveMessage;
if (m_containsMultiMatchAction && isItToBeLogged) {
/* warn */
trans->m_rulesMessages.push_back(*ruleMessage);

bool isItToBeLogged = ruleMessage->m_saveMessage;
if (m_containsMultiMatchAction && isItToBeLogged) {
/* warn */
trans->m_rulesMessages.push_back(*ruleMessage);
/* error */
if (!ruleMessage->m_isDisruptive) {
trans->serverLog(ruleMessage);
}

/* error */
if (!ruleMessage->m_isDisruptive) {
trans->serverLog(ruleMessage);
RuleMessage *rm = new RuleMessage(this, trans);
rm->m_saveMessage = ruleMessage->m_saveMessage;
ruleMessage.reset(rm);
}

RuleMessage *rm = new RuleMessage(this, trans);
rm->m_saveMessage = ruleMessage->m_saveMessage;
ruleMessage.reset(rm);
globalRet = true;
}

globalRet = true;
}
}
delete v;
Expand Down
14 changes: 14 additions & 0 deletions src/transaction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,8 @@ int Transaction::addRequestHeader(const std::string& key,
if (keyl == "content-type") {
std::string multipart("multipart/form-data");
std::string urlencoded("application/x-www-form-urlencoded");
std::string xml("application/xml");
std::string json("application/json");
std::string l = utils::string::tolower(value);
if (l.compare(0, multipart.length(), multipart) == 0) {
this->m_requestBodyType = MultiPartRequestBody;
Expand All @@ -593,6 +595,18 @@ int Transaction::addRequestHeader(const std::string& key,
this->m_requestBodyType = WWWFormUrlEncoded;
m_variableReqbodyProcessor.set("URLENCODED", m_variableOffset);
}

if (l.compare(0, xml.length(), xml) == 0) {
this->m_requestBodyType = XMLRequestBody;
m_variableReqbodyProcessor.set("XML", m_variableOffset);
m_requestBodyProcessor = XMLRequestBody;
}

if (l.compare(0, json.length(), json) == 0) {
this->m_requestBodyType = JSONRequestBody;
m_variableReqbodyProcessor.set("JSON", m_variableOffset);
m_requestBodyProcessor = JSONRequestBody;
}
}

if (keyl == "host") {
Expand Down
4 changes: 2 additions & 2 deletions test/test-cases/regression/offset-variable.json
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,7 @@
]
},
{
"enabled":1,
"enabled":0,
"version_min":300000,
"title":"Testing Variables :: REQUEST_BODY",
"client":{
Expand Down Expand Up @@ -1013,7 +1013,7 @@
]
},
{
"enabled":1,
"enabled":0,
"version_min":300000,
"title":"Testing Variables :: REQUEST_BODY",
"client":{
Expand Down
Loading