|
| 1 | +/* |
| 2 | + * ModSecurity, http://www.modsecurity.org/ |
| 3 | + * Copyright (c) 2025 OWASP ModSecurity project |
| 4 | + * |
| 5 | + * You may not use this file except in compliance with |
| 6 | + * the License. You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * If any of the files related to licensing are missing or if you have any |
| 11 | + * other questions related to licensing please contact Trustwave Holdings, Inc. |
| 12 | + * directly using the email address modsecurity@owasp.org. |
| 13 | + * |
| 14 | + */ |
| 15 | + |
| 16 | +#include "src/actions/ctl/parse_xml_into_args.h" |
| 17 | + |
| 18 | +#include <iostream> |
| 19 | +#include <string> |
| 20 | + |
| 21 | +#include "modsecurity/rules_set_properties.h" |
| 22 | +#include "modsecurity/rules_set.h" |
| 23 | +#include "modsecurity/transaction.h" |
| 24 | + |
| 25 | +namespace modsecurity { |
| 26 | +namespace actions { |
| 27 | +namespace ctl { |
| 28 | + |
| 29 | + |
| 30 | +bool ParseXmlIntoArgs::init(std::string *error) { |
| 31 | + std::string what(m_parser_payload, 17, m_parser_payload.size() - 17); |
| 32 | + |
| 33 | + if (what == "on") { |
| 34 | + m_secXMLParseXmlIntoArgs = RulesSetProperties::TrueConfigXMLParseXmlIntoArgs; |
| 35 | + } else if (what == "off") { |
| 36 | + m_secXMLParseXmlIntoArgs = RulesSetProperties::FalseConfigXMLParseXmlIntoArgs; |
| 37 | + } else if (what == "onlyargs") { |
| 38 | + m_secXMLParseXmlIntoArgs = RulesSetProperties::OnlyArgsConfigXMLParseXmlIntoArgs; |
| 39 | + } else { |
| 40 | + error->assign("Internal error. Expected: On, Off or OnlyArgs; " \ |
| 41 | + "got: " + m_parser_payload); |
| 42 | + return false; |
| 43 | + } |
| 44 | + |
| 45 | + return true; |
| 46 | +} |
| 47 | + |
| 48 | +bool ParseXmlIntoArgs::evaluate(RuleWithActions *rule, Transaction *transaction) { |
| 49 | + std::stringstream a; |
| 50 | + a << "Setting SecParseXMLIntoArgs to "; |
| 51 | + a << modsecurity::RulesSetProperties::configXMLParseXmlIntoArgsString(m_secXMLParseXmlIntoArgs); |
| 52 | + a << " as requested by a ctl:parseXmlIntoArgs action"; |
| 53 | + |
| 54 | + ms_dbg_a(transaction, 8, a.str()); |
| 55 | + |
| 56 | + transaction->m_secXMLParseXmlIntoArgs = m_secXMLParseXmlIntoArgs; |
| 57 | + return true; |
| 58 | +} |
| 59 | + |
| 60 | + |
| 61 | +} // namespace ctl |
| 62 | +} // namespace actions |
| 63 | +} // namespace modsecurity |
0 commit comments