Skip to content
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

V3/collection re fix #2297

Closed

Conversation

airween
Copy link
Member

@airween airween commented Apr 22, 2020

This PR is the cleaned version of #2107.

I've updated my local branch and forked a new one from current v3/master. Contains only one necessary commit, changed the variable name for better readability.

Edit: this PR fixes the #2296.

@martinhsv
Copy link
Contributor

martinhsv commented Jul 3, 2020

A couple of observations:

  1. What if someone wanted to write a rule where they did indeed want the TX:/[regex-content]/ to be case sensitive? Wouldn't these code changes make that impossible?
  2. Would your use case be satisfied by instead modifying the regex itself. For example in your first test use something like 'TX:/^(?i)HEADER_NAME_/ ' ?

@airween
Copy link
Member Author

airween commented Jul 3, 2020

Hi @martinhsv,

1. What if someone wanted to write a rule where they did indeed want the TX:/[regex-content]/ to be case sensitive?  Wouldn't these code changes make that impossible?

If someone wants to do that, how can he/she does it in case of mod_security2? The expected mode is case insensitive (but the documentation doesn't contain it).

I think if you want to implement this feature, it would be more correct to introduce some new syntax (and make the relevant code).

2. Would your use case be satisfied by instead modifying the regex itself.  For example in your first test use something like 'TX:/^(?i)HEADER_NAME_/ ' ?

Yes, that works as well - but you can see there are two issues about this problem (#2296, #1808) and one PR (#1810), so I think the users accustomed this form.

@zimmerle zimmerle added this to In progress in v3.1.0 via automation Oct 19, 2020
@zimmerle zimmerle moved this from In progress to Backlog in v3.1.0 Oct 19, 2020
@martinhsv martinhsv moved this from Backlog to In progress in v3.1.0 Oct 22, 2020
@martinhsv
Copy link
Contributor

Hi @airween ,

First off, apologies for the delay.

I previously expressed some reservations about the change. I have put some more thought into this and am persuaded that this is the right thing to do.

A couple of reasons:

  • Given that exact names in the VARIABLES portion of a rule (e.g. ARGS:myid) are treated as case insensitive, making the regex equivalent (ARGS:/myid/) behave likewise is good for consistency
  • this change probably doesn't reduce user flexibility as much as I had feared. For example, in PCRE if a rule writer specifically wants to make the test case sensitive, one can prefix the main portion of the pattern with (?i-). (Not to mention that the cases where one has a compelling reason to do this are likely rare.)

(We also wanted to check that some futures features, such as supporting PCRE alternatives, would be unlikely to be hampered by this change.)

@zimmerle and I discussed this earlier today, and I don't think we have any further concerns.

This should get merged within a few days.

@airween
Copy link
Member Author

airween commented Oct 22, 2020

Hi @martinhsv,

This should get merged within a few days.

Thanks, it's good to read :).

@zimmerle zimmerle self-requested a review October 23, 2020 17:57
@zimmerle zimmerle self-assigned this Oct 23, 2020
Copy link
Contributor

@zimmerle zimmerle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have read the code and made some comments.

I am going the make the modifications by myself as this is going back and forth from a while. We want to have a fix for it.

Vide: #2297, #2296, and #2107.

@airween let me know if you have any doubts or concerns on my comments.

{
"enabled":1,
"version_min":300000,
"title":"OWASP CRS id:920450",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to have a title with a more meaningful message. If the test "OWASP CRS id:920450" fails, what does it means to the user?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed in ceb0e3

{
"enabled":1,
"version_min":300000,
"title":"OWASP CRS id:920450",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fixed too.

test/test-cases/regression/rule-920450.json Outdated Show resolved Hide resolved
Makefile.am Outdated
@@ -185,6 +185,7 @@ TESTS+=test/test-cases/regression/request-body-parser-xml-validade-dtd.json
TESTS+=test/test-cases/regression/rule-920120.json
TESTS+=test/test-cases/regression/rule-920200.json
TESTS+=test/test-cases/regression/rule-920274.json
TESTS+=test/test-cases/regression/rule-920450.json
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expect a different name for that file. Explained below.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@@ -0,0 +1,87 @@
[
{
"enabled":1,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is a pull request that was well described in a issue i miss the github_issue tag.

As listed -
https://github.com/SpiderLabs/ModSecurity/blob/785958f9b5089b918c7d054cbcc2fe4a3c7b3788/test/test-cases/regression/issue-960.json#L7-L9

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for info. The last commit contains both 'url' and 'github_issue' keys, in both test cases.

Note: it would be good to make some wiki page about your expectations for contributors. I'm sure these keywords are part of the regression test structure, but after 17 commits I've met with them first.

},
"rules":[
"SecRuleEngine On",
"SecRule &TX:restricted_headers \"@eq 0\" \"id:901165,phase:1,pass,nolog,setvar:'tx.restricted_headers=/proxy/ /lock-token/ /content-range/ /translate/ /if/'\"",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a value of having complex rules on the regression tests as it increases surface area for testing features. However, I am afraid that together with the complex example, we need to have a very simple use case scenario. If/When this test fails, it was a consequence of a problem on the selection of variables using regular expression or elsewhere (e.g. setvar)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the rules in the new regression test file. I based @michaelgranzow-avi test cases, but there are only two cases, with same context: only the TX variable name format differ.

},
"request":{
"headers":{
"TRANSLATE": "test"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to use real request headers, to mimic a real world example.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed.

},
"rules":[
"SecRuleEngine On",
"SecRule &TX:restricted_headers \"@eq 0\" \"id:901165,phase:1,pass,nolog,setvar:'tx.restricted_headers=/proxy/ /lock-token/ /content-range/ /translate/ /if/'\"",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same rule complexity issue explained below.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

"no need."
]
},
"expected":{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Specially because the rules are complex, this test case could fail silent... as a combination of two (or more) failures. Better to also considers the debug and error log (when possible).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the test cases: both of them block the request, and gives the error_log, which used in "expected" block.

"no need."
]
},
"expected":{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment above. Use error and debug logs.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed too.

@airween
Copy link
Member Author

airween commented Oct 23, 2020

@airween let me know if you have any doubts or concerns on my comments.

See my answers and the new commit: ceb0e38.

@zimmerle zimmerle moved this from In progress to Needs review in v3.1.0 Oct 29, 2020
zimmerle added a commit that referenced this pull request Nov 30, 2020
This issue was initially reported by @michaelgranzow-avi on #2296.

@airween made an initial attempt to provide a fixed at #2107; As a
consequence of the pull request review - provided by @victorhora,
@zimmerle, and @michaelgranzow-avi - @airween made a second attempt
at #2297. After reviewing by @martinhsv, @zimmerle, I have absorbed
the essential pieces from @airween patch into this one.

This patch differs from @airween's because @airween's patches were
partially working: Key exclusions with regex weren't covered, same
for anchored variables (e.g. ARGS). During the review, I have
highlighted the importance of having elementary test cases. A simple
test case on ARGS could spot the issue. Since that is an important
fix, I don't want to hold this for one more review cycle; therefore,
I am committing the fix myself.

Thank you all involved in the solution of this very own issue.
@zimmerle zimmerle moved this from Needs review to Under QA in v3.1.0 Nov 30, 2020
@zimmerle
Copy link
Contributor

Closing this as consequence of 910a187. Thanks everybody involved on this issue resolution.

@zimmerle zimmerle closed this Nov 30, 2020
v3.1.0 automation moved this from Under QA to Done Nov 30, 2020
zimmerle added a commit that referenced this pull request Dec 10, 2020
This issue was initially reported by @michaelgranzow-avi on #2296.

@airween made an initial attempt to provide a fixed at #2107; As a
consequence of the pull request review - provided by @victorhora,
@zimmerle, and @michaelgranzow-avi - @airween made a second attempt
at #2297. After reviewing by @martinhsv, @zimmerle, I have absorbed
the essential pieces from @airween patch into this one.

This patch differs from @airween's because @airween's patches were
partially working: Key exclusions with regex weren't covered, same
for anchored variables (e.g. ARGS). During the review, I have
highlighted the importance of having elementary test cases. A simple
test case on ARGS could spot the issue. Since that is an important
fix, I don't want to hold this for one more review cycle; therefore,
I am committing the fix myself.

Thank you all involved in the solution of this very own issue.
vladbukin pushed a commit to vladbukin/ModSecurity that referenced this pull request Apr 12, 2022
This issue was initially reported by @michaelgranzow-avi on owasp-modsecurity#2296.

@airween made an initial attempt to provide a fixed at owasp-modsecurity#2107; As a
consequence of the pull request review - provided by @victorhora,
@zimmerle, and @michaelgranzow-avi - @airween made a second attempt
at owasp-modsecurity#2297. After reviewing by @martinhsv, @zimmerle, I have absorbed
the essential pieces from @airween patch into this one.

This patch differs from @airween's because @airween's patches were
partially working: Key exclusions with regex weren't covered, same
for anchored variables (e.g. ARGS). During the review, I have
highlighted the importance of having elementary test cases. A simple
test case on ARGS could spot the issue. Since that is an important
fix, I don't want to hold this for one more review cycle; therefore,
I am committing the fix myself.

Thank you all involved in the solution of this very own issue.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
v3.1.0
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

3 participants