8000 Proposal for removing negative lookbehind from 920120 by theseion · Pull Request #2360 · coreruleset/coreruleset · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Proposal for removing negative lookbehind from 920120 #2360

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

Conversation

theseion
Copy link
Contributor
@theseion theseion commented Jan 23, 2022

920120 now checks for HTML entities and skips the next rule if it finds
any.
920122 does the actual blocking, but first checks for [';"=].

Removed 920120-no-backtracking.data.
Removed scripts and facilities for generating and dealing with negative
lookbehind related expressions.

The rule numbering is currently experimental. I need some guidance on how to go forward (there's a PL2 rule with ID 920121). The rule comment should also be updated to explain the additional rule.

There's also the issue that the test file (920120.yaml) now actually tests two rules and looks for 920122 in the log. Not bad per se but it clashes somewhat with the naming of the test file.

This PR follows up on #2334 and #2339, where I discovered that !@rx is not a negative regular expression match but a "rule inversion" (docs: https://github.com/SpiderLabs/ModSecurity/wiki/Reference-Manual-%28v2.x%29#args_names).

920120 now checks for HTML entities and skips the next rule if it finds
any.
920122 does the actual blocking, but first checks for ['\;"=].

Removed 920120-no-backtracking.data.
Removed scripts and facilities for generating and dealing with negative
lookbehind related expressions.
@fzipi
Copy link
Member
fzipi commented Jan 23, 2022

@theseion Thinking on the semantic changes in the rule: what happens when we have this payload? 🤔

Content-Disposition: form-data; name="&fi;le"; filename="test"

I think this is why we need a chain...

@theseion
Copy link
Contributor Author

I didn't intend to change semantics. Did I? The current rule will already pass on name="&fi;le";, so there shouldn't be a difference.

@theseion
Copy link
Contributor Author

Nice find @fzipi! Because of the inverted logic we now have to check both variables separately. Also, we need to match the entire string.
I found a solution using a chained rule. TBH, I'm surprised it works. I guess I still don't understand how chains really work... I thought that both rules of the chain need to match for the action to be performed but, as the tests I've added show, a match on either of the rules will work (at least one needs to match to skip the blocking rule).

@theseion
Copy link
Contributor Author

Also checked against ReDos.

@fzipi
Copy link
Member
fzipi commented Jan 26, 2022

Nice find @fzipi! Because of the inverted logic we now have to check both variables separately. Also, we need to match the entire string. I found a solution using a chained rule. TBH, I'm surprised it works. I guess I still don't understand how chains really work... I thought that both rules of the chain need to match for the action to be performed but, as the tests I've added show, a match on either of the rules will work (at least one needs to match to skip the blocking rule).

🤔 I think that this works because the content is the same in FILES and FILES_NAMES. Can those be different?

A chain will be a logical AND of those rules.

@theseion
Copy link
Contributor Author

Yeah... I don't like that... Funny story, after thinking about it some more I realised that the solution to the problem is !@rx... 😅 . Both name and filename need to match the expression. If they match, the action isn't executed, if they don't (that's the inversion) we block.

In conclusion, the trick to removing negative lookahead is to require a match on the inverted expression.

@fzipi
Copy link
Member
fzipi commented Jan 27, 2022

I've been playing with this in regex101... and looks like it works. I'm puzzled also! Nice finding 🎉

Just for the sake of future generations, do you think we should document this in the util/regexp-assemble/data/920120.data file, or maybe in that wiki page about technical decisions?

@dune73
Copy link
Member
dune73 commented Jan 27, 2022

If you aim for the clean solution, then it's the wiki page and the data file links to the right section of the wiki page.

Copy link
Member
@fzipi fzipi left a comment

Choose a reason for hiding this comment

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

Just minor comments about the test files.

@dune73
Copy link
Member
dune73 commented Jan 28, 2022

The PR currently does a ton of additional changes. Is that a basing problem?
(Sorry, losing track a bit these days a bit.)

Also: With the recently discovered solution, @theseion, did you update the PR already?

10000
@fzipi
Copy link
Member
fzipi commented Jan 28, 2022

Looks like there are additional changes, but it is just good cleaning up. It is not a basing problem. This is the last and only rule that uses negative lookbehind, so there is the removal of the preprocessor and all comments related to it in multiple files.

The "real" change is the rule, the regexp, and tests (lets say the usual changes). And yes, the proposed change is there in rules/REQUEST-920-PROTOCOL-ENFORCEMENT.conf:104.

@dune73
Copy link
Member
dune73 commented Jan 28, 2022

Got it. Thanks.

@theseion
Copy link
Contributor Author

I've made a small adjustment to the expression to allow empty values (this matches the previous behaviour).

I also cleaned up the comments (and tests, thanks @fzipi) and added a link to the new wiki page I set up.

@dune73 @RedXanadu I went ahead and created a new page https://github.com/coreruleset/coreruleset/wiki/Technical-Decisions-and-Best-Practices (linked to from Home). It will probably make sense to split the two topics "technical decisions" and "best practices" at some point but I couldn't quite decide which of the two I was writing.

@fzipi fzipi requested a review from fgsch January 29, 2022 12:23
@fzipi
Copy link
Member
fzipi commented Jan 29, 2022

Excellent write-up @theseion!

I'm really happy with this now, but I would like to wait for @fgsch's review before merging.

Copy link
Member
@fzipi fzipi left a comment

Choose a reason for hiding this comment

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

I am really happy with the results here.

The only drawback is that we are indeed relying on modsecurity "trick", but this is preferable to the lookbehind itself, IMHO.

There is a good wiki article about why we did this.

I would like to get additional approvals also.

@fgsch
Copy link
Contributor
fgsch commented Feb 4, 2022

👋 Sorry for the late response. This looks good but I'm a bit concerned it touches 53 files.
Isolating the actual rule change from other changes would make reviewing easier, so if possible I think it'd be great if:

  • The new tests are added in their own PR. Preferably this would be merged before any changes to the rule.
  • The rule changes are moved to another PR.
  • The Accept: "*/*" c 8000 hanges are also in their own PR (and maybe extended to other tests).
  • And finally, the negative lookbehind block processor is removed in a separate PR.

Let me know your thoughts and whether I can help with any of this.

@theseion
Copy link
Contributor Author
theseion commented Feb 5, 2022

Thanks @fgsch. You're right, that does make sense. I'll split this up later today.

theseion added a commit to theseion/coreruleset that referenced this pull request Feb 5, 2022
@theseion
Copy link
Contributor Author
theseion commented Feb 5, 2022

Closed in favor of the following four PR's (in order):

@theseion theseion closed this Feb 5, 2022
theseion added a commit that referenced this pull request Feb 5, 2022
* Added additional tests for 920120

Related to #2360
theseion added a commit to theseion/coreruleset that referenced this pull request Feb 5, 2022
theseion added a commit to theseion/coreruleset that referenced this pull request Feb 5, 2022
@theseion theseion deleted the remove-negative-lookbehind-from-920120 branch February 6, 2022 06:29
9E81
theseion added a commit to theseion/coreruleset that referenced this pull request Feb 7, 2022
theseion added a commit to theseion/coreruleset that referenced this pull request Feb 7, 2022
theseion added a commit that referenced this pull request Feb 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0