diff --git a/src/actions/ctl/parse_xml_into_args.cc b/src/actions/ctl/parse_xml_into_args.cc new file mode 100644 index 00000000..03b8413c --- /dev/null +++ b/src/actions/ctl/parse_xml_into_args.cc @@ -0,0 +1,63 @@ +/* + * ModSecurity, http://www.modsecurity.org/ + * Copyright (c) 2025 OWASP ModSecurity project + * + * 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 modsecurity@owasp.org. + * + */ + +#include "src/actions/ctl/parse_xml_into_args.h" + +#include +#include + +#include "modsecurity/rules_set_properties.h" +#include "modsecurity/rules_set.h" +#include "modsecurity/transaction.h" + +namespace modsecurity { +namespace actions { +namespace ctl { + + +bool ParseXmlIntoArgs::init(std::string *error) { + std::string what(m_parser_payload, 17, m_parser_payload.size() - 17); + + if (what == "on") { + m_secXMLParseXmlIntoArgs = RulesSetProperties::TrueConfigXMLParseXmlIntoArgs; + } else if (what == "off") { + m_secXMLParseXmlIntoArgs = RulesSetProperties::FalseConfigXMLParseXmlIntoArgs; + } else if (what == "onlyargs") { + m_secXMLParseXmlIntoArgs = RulesSetProperties::OnlyArgsConfigXMLParseXmlIntoArgs; + } else { + error->assign("Internal error. Expected: On, Off or OnlyArgs; " \ + "got: " + m_parser_payload); + return false; + } + + return true; +} + +bool ParseXmlIntoArgs::evaluate(RuleWithActions *rule, Transaction *transaction) { + std::stringstream a; + a << "Setting SecParseXMLIntoArgs to "; + a << modsecurity::RulesSetProperties::configXMLParseXmlIntoArgsString(m_secXMLParseXmlIntoArgs); + a << " as requested by a ctl:parseXmlIntoArgs action"; + + ms_dbg_a(transaction, 8, a.str()); + + transaction->m_secXMLParseXmlIntoArgs = m_secXMLParseXmlIntoArgs; + return true; +} + + +} // namespace ctl +} // namespace actions +} // namespace modsecurity diff --git a/src/actions/ctl/parse_xml_into_args.h b/src/actions/ctl/parse_xml_into_args.h new file mode 100644 index 00000000..4bfa7844 --- /dev/null +++ b/src/actions/ctl/parse_xml_into_args.h @@ -0,0 +1,48 @@ +/* + * ModSecurity, http://www.modsecurity.org/ + * Copyright (c) 2025 OWASP ModSecurity Project + * + * 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 modsecurity@owasp.org + * + */ + +#include + +#include "modsecurity/rules_set_properties.h" +#include "modsecurity/actions/action.h" +#include "modsecurity/transaction.h" + + +#ifndef SRC_ACTIONS_CTL_PARSE_XML_INTO_ARGS_H_ +#define SRC_ACTIONS_CTL_PARSE_XML_INTO_ARGS_H_ + +namespace modsecurity { +namespace actions { +namespace ctl { + + +class ParseXmlIntoArgs : public Action { + public: + explicit ParseXmlIntoArgs(const std::string &action) + : Action(action), + m_secXMLParseXmlIntoArgs(RulesSetProperties::PropertyNotSetConfigXMLParseXmlIntoArgs) { } + + bool init(std::string *error) override; + bool evaluate(RuleWithActions *rule, Transaction *transaction) override; + + RulesSetProperties::ConfigXMLParseXmlIntoArgs m_secXMLParseXmlIntoArgs; +}; + + +} // namespace ctl +} // namespace actions +} // namespace modsecurity + +#endif // SRC_ACTIONS_CTL_PARSE_XML_INTO_ARGS_H_