-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Feature: Pm custom separator #2786
base: v3/master
Are you sure you want to change the base?
Feature: Pm custom separator #2786
Conversation
Thanks a lot for this PM. I hope it will be accepted. About the syntax, why not simplifying it: Also, would this be supported? |
Hi @marcstern, happy to see you still around! SyntaxFor the first proposal, I gave a go to a more explicit syntax in order to:
Furthermore, I'm gonna try to dig into how the rules are parsed by ModSecurity, but I'm guessing that a space character between the operator name ( It would be easy to do something like Making Custom delimiters and Suricata syntax coexistAs of now, in your example (
Just wanted to share some thoughts behind my implementation, happy to keep this conversation going on and implement an agreed and technically doable design! |
FYI: @marcstern, I extended the conversation also with Coraza's folks. I would be happy to see your point of view also about their proposals corazawaf/coraza#349 |
Indeed, a space is mandatory after the operator |
Overall I think there are quite a few things to like about this proposal. A couple of things that gave me pause: One thing that's somewhat different from existing functionality is with the operator's parameters. Almost all ModSecurity operators take exactly one parameter, and that (mostly) makes them simple to use. We do have at least one exception to this: fuzzyHash takes 2 parms. But we don't have anything currently that takes either one or two parameters. That doesn't need to be a show-stopper but it is something to be aware of. This does mean implementing a "magic string" that has a special meaning, when that same string might have had an entirely different meaning prior to this implementation. (Might someone have wanted to try to match 'PmCustomSeparator:' against ARGS?) That can be a bit of a red flag when building a syntax. If we were concerned about this, one alternative could be to implement an entirely separate operator (@pmWithSeparator ?) to support the new functionality. On balance, I think I still prefer your approach here for what is likely to be, in practice, only a theoretical downside. On a more detail level, I think there are still some things to consider mostly from the perspective of clarity and usability. I'll use your example
Just some initial thoughts. I do think it's a pretty good solution overall. It expands functionality without meaningful downside to existing handling. |
Signed-off-by: Matteo Pace <[email protected]>
Hello @martinhsv, thank you for your feedback on this PR!
The "magic string" would become sort of an optional parameter. The only way I see to not impact the default pm behaviour would be making the second parameter mandatory in a separate operator (just like you pointed out with
I'm not sure what you mean by this. I guess it is about enforcing that it is not a space. I'm sorry if I misunderstood. If the guess is right, yes, I agree, I implemented it. Now if it is just
I agree, some corner cases without separators at the beginning and end can be definitely awkward. I implemented it by adding some logic to parsing the string: it is about looking for the initial and final separator and stripping all the rest. |
Can we be future-proof and find a standard for additional parameters?
Also, I already 2 use cases for a custom separator; why not standardizing "@CustomSeparator:" and implementing it in the common code. |
Context
@pm
currently implicitly relies only on therx
(less performant) or onpmFromFile
(not available for some environments e.g. Wasm).The possibility of choosing a custom delimiter has been requested for such a long time (see #682) and iterated over time by some different issues (E.g. #2699).
Proposal
This PR proposes a little extension of the
pm
operator capability permitting the specification of a custom separator.It :
pm
operator.PmFromFile
, this proposal bypasses the Snort-Suricata format parsing, therefore the pipe symbol can be used as a separator or matched as any other character).Notes:
@pm
still can not contain%
,"
and can not end with\
.Example Rule syntax:
Open to any discussion about this functionality and to further work on it for any better design agreed.
Closes #682.