mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-09-29 19:24:29 +03:00
Adds support to ctl:requestBodyProcessor=XML
This commit is contained in:
@@ -68,6 +68,7 @@ ACTIONS = \
|
||||
actions/capture.cc \
|
||||
actions/chain.cc \
|
||||
actions/ctl_audit_log_parts.cc \
|
||||
actions/ctl_request_body_processor_xml.cc \
|
||||
actions/init_col.cc \
|
||||
actions/deny.cc \
|
||||
actions/log_data.cc \
|
||||
|
34
src/actions/ctl_request_body_processor_xml.cc
Normal file
34
src/actions/ctl_request_body_processor_xml.cc
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* ModSecurity, http://www.modsecurity.org/
|
||||
* Copyright (c) 2015 Trustwave Holdings, Inc. (http://www.trustwave.com/)
|
||||
*
|
||||
* You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* If any of the files related to licensing are missing or if you have any
|
||||
* other questions related to licensing please contact Trustwave Holdings, Inc.
|
||||
* directly using the email address security@modsecurity.org.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "actions/ctl_request_body_processor_xml.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include "modsecurity/transaction.h"
|
||||
|
||||
namespace modsecurity {
|
||||
namespace actions {
|
||||
|
||||
|
||||
bool CtlRequestBodyProcessorXML::evaluate(Rule *rule, Transaction *transaction) {
|
||||
transaction->m_requestBodyProcessor = modsecurity::Transaction::XMLRequestBody;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
} // namespace actions
|
||||
} // namespace modsecurity
|
39
src/actions/ctl_request_body_processor_xml.h
Normal file
39
src/actions/ctl_request_body_processor_xml.h
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* ModSecurity, http://www.modsecurity.org/
|
||||
* Copyright (c) 2015 Trustwave Holdings, Inc. (http://www.trustwave.com/)
|
||||
*
|
||||
* You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* If any of the files related to licensing are missing or if you have any
|
||||
* other questions related to licensing please contact Trustwave Holdings, Inc.
|
||||
* directly using the email address security@modsecurity.org.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "actions/action.h"
|
||||
#include "modsecurity/transaction.h"
|
||||
|
||||
#ifndef SRC_ACTIONS_CTL_REQUEST_BODY_PROCESSOR_XML_H_
|
||||
#define SRC_ACTIONS_CTL_REQUEST_BODY_PROCESSOR_XML_H_
|
||||
|
||||
namespace modsecurity {
|
||||
namespace actions {
|
||||
|
||||
|
||||
class CtlRequestBodyProcessorXML : public Action {
|
||||
public:
|
||||
explicit CtlRequestBodyProcessorXML(std::string action)
|
||||
: Action(action, RunTimeOnlyIfMatchKind) { }
|
||||
|
||||
bool evaluate(Rule *rule, Transaction *transaction) override;
|
||||
};
|
||||
|
||||
} // namespace actions
|
||||
} // namespace modsecurity
|
||||
|
||||
#endif // SRC_ACTIONS_CTL_REQUEST_BODY_PROCESSOR_XML_H_
|
@@ -23,6 +23,7 @@ class Driver;
|
||||
#include "actions/action.h"
|
||||
#include "actions/audit_log.h"
|
||||
#include "actions/ctl_audit_log_parts.h"
|
||||
#include "actions/ctl_request_body_processor_xml.h"
|
||||
#include "actions/init_col.h"
|
||||
#include "actions/set_sid.h"
|
||||
#include "actions/set_uid.h"
|
||||
@@ -69,6 +70,7 @@ using modsecurity::ModSecurity;
|
||||
using modsecurity::actions::Accuracy;
|
||||
using modsecurity::actions::Action;
|
||||
using modsecurity::actions::CtlAuditLogParts;
|
||||
using modsecurity::actions::CtlRequestBodyProcessorXML;
|
||||
using modsecurity::actions::InitCol;
|
||||
using modsecurity::actions::SetSID;
|
||||
using modsecurity::actions::SetUID;
|
||||
@@ -1094,8 +1096,7 @@ act:
|
||||
}
|
||||
| ACTION_CTL_BDY_XML
|
||||
{
|
||||
/* not ready yet. */
|
||||
$$ = Action::instantiate($1);
|
||||
$$ = new modsecurity::actions::CtlRequestBodyProcessorXML($1);
|
||||
}
|
||||
| ACTION_CTL_BDY_JSON
|
||||
{
|
||||
|
@@ -107,6 +107,7 @@ Transaction::Transaction(ModSecurity *ms, Rules *rules, void *logCbData)
|
||||
m_namesArgsPost(NULL),
|
||||
m_namesArgsGet(NULL),
|
||||
m_requestBodyType(UnknownFormat),
|
||||
m_requestBodyProcessor(UnknownFormat),
|
||||
m_requestHeadersNames(NULL),
|
||||
m_responseHeadersNames(NULL),
|
||||
m_responseContentType(NULL),
|
||||
@@ -475,7 +476,6 @@ int Transaction::addRequestHeader(const std::string& key,
|
||||
if (keyl == "content-type") {
|
||||
std::string multipart("multipart/form-data");
|
||||
std::string l = tolower(value);
|
||||
|
||||
if (l.compare(0, multipart.length(), multipart) == 0) {
|
||||
this->m_requestBodyType = MultiPartRequestBody;
|
||||
}
|
||||
@@ -590,15 +590,11 @@ int Transaction::processRequestBody() {
|
||||
*
|
||||
*/
|
||||
|
||||
if (m_requestBodyType == XMLRequestBody) {
|
||||
std::string *a = m_collections.resolveFirst(
|
||||
"REQUEST_HEADERS:Content-Type");
|
||||
if (a != NULL) {
|
||||
if (m_xml->init() == true) {
|
||||
m_xml->processChunk(m_requestBody.str().c_str(),
|
||||
m_requestBody.str().size());
|
||||
m_xml->complete();
|
||||
}
|
||||
if (m_requestBodyProcessor == XMLRequestBody) {
|
||||
if (m_xml->init() == true) {
|
||||
m_xml->processChunk(m_requestBody.str().c_str(),
|
||||
m_requestBody.str().size());
|
||||
m_xml->complete();
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user