Skip to content

Commit 220caa5

Browse files
authored
Merge pull request #3363 from airween/v3/xmlargsfeat
feat: improved XMLArgs processing
2 parents 01a0615 + a3876e3 commit 220caa5

16 files changed

+8499
-7288
lines changed

headers/modsecurity/rules_set_properties.h

+39-1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@
5252
to = (from == PropertyNotSetBodyLimitAction) ? default : from; \
5353
}
5454

55+
#define merge_xmlargparse_value(to, from, default) \
56+
if (to == PropertyNotSetConfigXMLParseXmlIntoArgs) { \
57+
to = (from == PropertyNotSetConfigXMLParseXmlIntoArgs) ? default : from; \
58+
}
59+
5560
#ifdef __cplusplus
5661

5762
namespace modsecurity {
@@ -177,6 +182,7 @@ class RulesSetProperties {
177182
m_secRequestBodyAccess(PropertyNotSetConfigBoolean),
178183
m_secResponseBodyAccess(PropertyNotSetConfigBoolean),
179184
m_secXMLExternalEntity(PropertyNotSetConfigBoolean),
185+
m_secXMLParseXmlIntoArgs(PropertyNotSetConfigXMLParseXmlIntoArgs),
180186
m_tmpSaveUploadedFiles(PropertyNotSetConfigBoolean),
181187
m_uploadKeepFiles(PropertyNotSetConfigBoolean),
182188
m_debugLog(new DebugLog()),
@@ -191,6 +197,7 @@ class RulesSetProperties {
191197
m_secRequestBodyAccess(PropertyNotSetConfigBoolean),
192198
m_secResponseBodyAccess(PropertyNotSetConfigBoolean),
193199
m_secXMLExternalEntity(PropertyNotSetConfigBoolean),
200+
m_secXMLParseXmlIntoArgs(PropertyNotSetConfigXMLParseXmlIntoArgs),
194201
m_tmpSaveUploadedFiles(PropertyNotSetConfigBoolean),
195202
m_uploadKeepFiles(PropertyNotSetConfigBoolean),
196203
m_debugLog(debugLog),
@@ -218,14 +225,27 @@ class RulesSetProperties {
218225

219226
/**
220227
*
221-
*
228+
* The ConfigBoolean enumerator defines the states for configuration boolean values.
229+
* The default value is PropertyNotSetConfigBoolean.
222230
*/
223231
enum ConfigBoolean {
224232
TrueConfigBoolean,
225233
FalseConfigBoolean,
226234
PropertyNotSetConfigBoolean
227235
};
228236

237+
/**
238+
*
239+
* The ConfigXMLParseXmlIntoArgs enumerator defines the states for the configuration
240+
* XMLParseXmlIntoArgs values.
241+
* The default value is PropertyNotSetConfigXMLParseXmlIntoArgs.
242+
*/
243+
enum ConfigXMLParseXmlIntoArgs {
244+
TrueConfigXMLParseXmlIntoArgs,
245+
FalseConfigXMLParseXmlIntoArgs,
246+
OnlyArgsConfigXMLParseXmlIntoArgs,
247+
PropertyNotSetConfigXMLParseXmlIntoArgs
248+
};
229249

230250
/**
231251
*
@@ -338,6 +358,19 @@ class RulesSetProperties {
338358
}
339359
}
340360

361+
static std::string configXMLParseXmlIntoArgsString(ConfigXMLParseXmlIntoArgs i) {
362+
switch (i) {
363+
case TrueConfigXMLParseXmlIntoArgs:
364+
return "True";
365+
case FalseConfigXMLParseXmlIntoArgs:
366+
return "False";
367+
case OnlyArgsConfigXMLParseXmlIntoArgs:
368+
return "OnlyArgs";
369+
case PropertyNotSetConfigXMLParseXmlIntoArgs:
370+
default:
371+
return "Not set";
372+
}
373+
}
341374

342375
static int mergeProperties(RulesSetProperties *from,
343376
RulesSetProperties *to, std::ostringstream *err) {
@@ -357,6 +390,10 @@ class RulesSetProperties {
357390
from->m_secXMLExternalEntity,
358391
PropertyNotSetConfigBoolean);
359392

393+
merge_xmlargparse_value(to->m_secXMLParseXmlIntoArgs,
394+
from->m_secXMLParseXmlIntoArgs,
395+
PropertyNotSetConfigXMLParseXmlIntoArgs);
396+
360397
merge_boolean_value(to->m_uploadKeepFiles,
361398
from->m_uploadKeepFiles,
362399
PropertyNotSetConfigBoolean);
@@ -464,6 +501,7 @@ class RulesSetProperties {
464501
ConfigBoolean m_secRequestBodyAccess;
465502
ConfigBoolean m_secResponseBodyAccess;
466503
ConfigBoolean m_secXMLExternalEntity;
504+
ConfigXMLParseXmlIntoArgs m_secXMLParseXmlIntoArgs;
467505
ConfigBoolean m_tmpSaveUploadedFiles;
468506
ConfigBoolean m_uploadKeepFiles;
469507
ConfigDouble m_argumentsLimit;

headers/modsecurity/transaction.h

+1
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,7 @@ class Transaction : public TransactionAnchoredVariables, public TransactionSecMa
619619
RequestBodyProcessor::JSON *m_json;
620620

621621
int m_secRuleEngine;
622+
int m_secXMLParseXmlIntoArgs;
622623

623624
std::string m_variableDuration;
624625
std::map<std::string, std::string> m_variableEnvs;

src/Makefile.am

+1
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ ACTIONS = \
119119
actions/chain.cc \
120120
actions/ctl/audit_log_parts.cc \
121121
actions/ctl/audit_engine.cc \
122+
actions/ctl/parse_xml_into_args.cc \
122123
actions/ctl/rule_engine.cc \
123124
actions/ctl/request_body_processor_json.cc \
124125
actions/ctl/request_body_processor_xml.cc \
+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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 OWASP.
12+
* directly using the email address [email protected].
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

src/actions/ctl/parse_xml_into_args.h

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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 OWASP.
12+
* directly using the email address [email protected]
13+
*
14+
*/
15+
16+
#include <string>
17+
18+
#include "modsecurity/rules_set_properties.h"
19+
#include "modsecurity/actions/action.h"
20+
#include "modsecurity/transaction.h"
21+
22+
23+
#ifndef SRC_ACTIONS_CTL_PARSE_XML_INTO_ARGS_H_
24+
#define SRC_ACTIONS_CTL_PARSE_XML_INTO_ARGS_H_
25+
26+
namespace modsecurity {
27+
namespace actions {
28+
namespace ctl {
29+
30+
31+
class ParseXmlIntoArgs : public Action {
32+
public:
33+
explicit ParseXmlIntoArgs(const std::string &action)
34+
: Action(action),
35+
m_secXMLParseXmlIntoArgs(RulesSetProperties::PropertyNotSetConfigXMLParseXmlIntoArgs) { }
36+
37+
bool init(std::string *error) override;
38+
bool evaluate(RuleWithActions *rule, Transaction *transaction) override;
39+
40+
RulesSetProperties::ConfigXMLParseXmlIntoArgs m_secXMLParseXmlIntoArgs;
41+
};
42+
43+
44+
} // namespace ctl
45+
} // namespace actions
46+
} // namespace modsecurity
47+
48+
#endif // SRC_ACTIONS_CTL_PARSE_XML_INTO_ARGS_H_

0 commit comments

Comments
 (0)