mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-09-30 11:44:32 +03:00
Adds support 'xmlns' action to the libmodsec parser
This commit is contained in:
63
src/actions/xmlns.cc
Normal file
63
src/actions/xmlns.cc
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* 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/xmlns.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include "actions/action.h"
|
||||
#include "modsecurity/transaction.h"
|
||||
#include "src/utils.h"
|
||||
|
||||
namespace modsecurity {
|
||||
namespace actions {
|
||||
|
||||
|
||||
bool XmlNS::init(std::string *error) {
|
||||
size_t pos;
|
||||
std::string http = "http://";
|
||||
|
||||
pos = action.find("=");
|
||||
if (pos == std::string::npos) {
|
||||
error->assign("XMLS: Bad format, missing equals sign.");
|
||||
return false;
|
||||
}
|
||||
m_name = std::string(action, 0, pos);
|
||||
m_value = std::string(action, pos+1, action.size());
|
||||
|
||||
if (m_value.empty() or m_name.empty()) {
|
||||
error->assign("XMLS: XMLNS is invalid. Expecting a " \
|
||||
"name=value format.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_value.at(0) == '\'' && m_value.size() > 3) {
|
||||
m_value.erase(0, 1);
|
||||
m_value.pop_back();
|
||||
}
|
||||
|
||||
if (m_value.compare(0, http.length(), http) != 0) {
|
||||
error->assign("XMLS: Missing xmlns href for prefix: " \
|
||||
"`" + m_value + "'.");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
} // namespace actions
|
||||
} // namespace modsecurity
|
49
src/actions/xmlns.h
Normal file
49
src/actions/xmlns.h
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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"
|
||||
|
||||
#ifndef SRC_ACTIONS_XMLNS_H_
|
||||
#define SRC_ACTIONS_XMLNS_H_
|
||||
|
||||
class Transaction;
|
||||
|
||||
namespace modsecurity {
|
||||
class Transaction;
|
||||
namespace actions {
|
||||
|
||||
|
||||
class XmlNS : public Action {
|
||||
public:
|
||||
explicit XmlNS(std::string action) : Action(action) { }
|
||||
|
||||
bool evaluate(Rule *rule, Transaction *transaction) override {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool init(std::string *error);
|
||||
|
||||
private:
|
||||
std::string m_name;
|
||||
std::string m_value;
|
||||
};
|
||||
|
||||
|
||||
} // namespace actions
|
||||
} // namespace modsecurity
|
||||
|
||||
#endif // SRC_ACTIONS_XMLNS_H_
|
Reference in New Issue
Block a user