-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat: improved XMLArgs processing #3358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: v2/master
Are you sure you want to change the base?
Conversation
This is a great new feature. This will open up ModSecurity to anyone who needs to do serious processing of XML APIs (lots of legacy and current applications!). Especially with pre-written rule sets like CRS, this makes the task of handling false positives possible. Thank you for the work that has gone into this 🚀 |
@airween Could you share how the new option parses / advertises multi-level documents with multiple leaves carrying the same name? Is the hierarchy part of the name or is that hidden? Needless to say, that I really like this option. |
I hope I understand your question as well 😄, so consider this file: cat test.xml
<?xml version="1.0" encoding="UTF-8"?>
<root>
<level1>
<level2>
<node>foo1</node>
<node>bar1</node>
</level2>
<level2>
<node>foo2</node>
<node>bar2</node>
</level2>
</level1>
<level1>
<level2>
<node>foo1</node>
<node>bar1</node>
</level2>
<level2>
<node>foo2</node>
<node>bar2</node>
</level2>
</level1>
</root> and this request: curl -v -H "Content-Type: application/xml" -X POST -d @test.xml http://localhost/post.php This will generates these arguments (it's totally the same as in case of JSON):
|
This was what I expected. Thanks for the confirmation. Very good. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No tests?
static void msc_xml_on_start_elementns( | ||
void *ctx, | ||
const xmlChar *localname, | ||
const xmlChar *prefix, | ||
const xmlChar *URI, | ||
int nb_namespaces, | ||
const xmlChar **namespaces, | ||
int nb_attributes, | ||
int nb_defaulted, | ||
const xmlChar **attributes | ||
) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this new formatting for the code? Or was adopted as standard already?
Having mixed format in parameters, in general makes more difficult reading the code. So my suggestion will be:
- use the same format as all other files
- propose a new standard
- once accepted, apply to all files once and for all
- enforce the new format in the pipeline.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean by "new"? AFAICT, there are already multiple different formats for long function signatures (e.g., sec_guarstatic void dian_logger
, static void copy_rules_phase
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, could you show me an example what can I assume as "standard" already?
static void msc_xml_on_end_elementns( | ||
void* ctx, | ||
const xmlChar* localname, | ||
const xmlChar* prefix, | ||
const xmlChar* URI | ||
) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
static void msc_xml_on_start_elementns( | ||
void *ctx, | ||
const xmlChar *localname, | ||
const xmlChar *prefix, | ||
const xmlChar *URI, | ||
int nb_namespaces, | ||
const xmlChar **namespaces, | ||
int nb_attributes, | ||
int nb_defaulted, | ||
const xmlChar **attributes | ||
) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean by "new"? AFAICT, there are already multiple different formats for long function signatures (e.g., sec_guarstatic void dian_logger
, static void copy_rules_phase
).
I know we should start at some point to add tests, but unfortunately almost all of directives and features do not have tests. In project MRTS I really hope once we will arrive that point where we can cover all directives, arguments, operators and actions. But not yet. NB: in case of libmodsecurity3 implementation there are many new tests, but it's more easier. |
Co-authored-by: Felipe Zipitría <[email protected]>
Co-authored-by: Felipe Zipitría <[email protected]>
Co-authored-by: Felipe Zipitría <[email protected]>
Co-authored-by: Max Leske <[email protected]>
Co-authored-by: Max Leske <[email protected]>
Co-authored-by: Max Leske <[email protected]>
Co-authored-by: Max Leske <[email protected]>
Co-authored-by: Max Leske <[email protected]>
Co-authored-by: Max Leske <[email protected]>
Co-authored-by: Max Leske <[email protected]>
Co-authored-by: Max Leske <[email protected]>
Co-authored-by: Max Leske <[email protected]>
I have only a rough working knowledge of C/C++, so it's very likely that I missed stuff during the review. Knowing how many mistakes I make in languages that I'm proficient in I feel rather uncomfortable saying that code is good. Tests would give me much more confidence. I do understand your situation though. Ultimately, it's up to you (you would probably have to carry the weight of bug fixes and user inquiries). |
I completely agree with you. Making a review without tests is very hard. Fortunately the two codes (this and #3363) is almost the same, but yes, we can't declare that they are the same, and the other PR's test cases cover this PR too. My problem is in this case that there are many-many tests are missing. Adding a unique test against this PR just makes the CI more complicated. The solution is that we find out how can we make a framework when we can write tests against directives and their arguments. (This is why I started MRTS project.) |
Co-authored-by: Max Leske <[email protected]>
I added two new commits:
|
Co-authored-by: Max Leske <[email protected]>
|
what
This PR adds a new feature within XML processing.
Old (current) behavior: in case of
XML:/*
target the body processor expands the node values from the XML payload. Eg.:will produce this value:
In this case, there is no option to exclude any node. For example, if a node contains a term that a rule is looking for, the administrator could not create an exclusion. The only solution is to exclude the whole rule.
New behavior: there is a new configuration keyword,
SecParseXMLintoArgs
with possible valuesOn
,Off
andOnlyArgs
. The default value isOff
. This won't change anything. If the administrator set this toOn
, then the engine will parse the XML intoARGS
AND theXML:/*
target will still contain the only text content as before. If the value isOnlyArgs
then only the parsed content will appear inARGS
target; theXML:/*
target won't contain the parsed content anymore.If administrator sets it to
On
, then the node values will appear inARGS
, and it's easy to make any exclusion against the named target.why
A customer request has been received to solve this.
references
See #3178.