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

feat: add support for case sensitive args #1059

Merged
merged 6 commits into from
May 28, 2024

Conversation

fzipi
Copy link
Member

@fzipi fzipi commented May 3, 2024

what

  • add support for case sensitive args keys

why

  • comply with RFC.

notes

I don't like too much that it is the rule that tells if the collection is case sensitive. Ideally, we should be able to ask the collection (by calling collection.IsCaseSensitive() or similar) so that responsibility is delegated properly. But didn't knew how to do it first hand.

@fzipi fzipi requested a review from a team as a code owner May 3, 2024 21:42
@fzipi fzipi force-pushed the change-args-names-to-be-case-sensitive branch from 6c89ae1 to 20c4076 Compare May 4, 2024 12:36
@jcchavezs jcchavezs requested a review from anuraaga May 4, 2024 14:17
@@ -119,7 +119,7 @@ SecRule ARGS_GET "@rx prepayloadpost" "id:200, phase:2, log, msg:'Rule Parent 2
SecRule MATCHED_VAR "@rx pre" "chain"
SecRule MATCHED_VAR "@rx post"

SecRule ARGS_GET:var3 "@rx pre3payloadpost" "id:300, phase:2, log, msg:'Rule Parent 300', \
SecRule ARGS_GET:Var3 "@rx pre3payloadpost" "id:300, phase:2, log, msg:'Rule Parent 300', \
Copy link
Member

Choose a reason for hiding this comment

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

Isn't this a breaking change in the behavior of the engine? Up to now users might have written rules in lowercase that would not work anymore once this PR gets merged. Are we okay with this change in a minor release?

Copy link
Member Author

Choose a reason for hiding this comment

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

IMHO yes, because this is the common behavior in other engines.

Copy link
Member

Choose a reason for hiding this comment

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

We had some controvercy about what we consider a breaking change at different points in the project. I think if in general we can avoid BC we should do it. Maybe we could leverage a build tag for this and introduce the BC in 4.0? WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

Just checking, have there been any test cases added to CRS test suite verifying the insensitive behavior? If this is to bring parity to other engines, I guess we should verify it with the suite.

But agree if rules deployed that worked stop working and possibly crash users, it's best to be behind a flag of some sort, that can be made the default after a major. With go's promise of compatibility, it's common to auto-update on minors and expect no change. Just for reference, the recent blog about rand was quite profound for me on how far it's necessary to go to... be go.

https://go.dev/blog/randv2

Copy link
Member Author

Choose a reason for hiding this comment

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

What do you mean? Does CRS need to change and add tests about this when the expected behavior and rfc says this is the right thing?

Copy link
Member

@jcchavezs jcchavezs May 9, 2024

Choose a reason for hiding this comment

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

IMHO yes, because this is the common behavior in other engines.

I think this is key to me, rules that use to work won't work anymore and with no notice. That is the definition of breaking change (yes, we are breaking something that was broken). I think it could easily considered a bugfix if this was fixing an incorrect behaviour and or making work something that wasn't working bur from my understanding this is going to make something that use to work to not to work anymore?

While this is completely our fault, I think it is too late to do the right thing in v3 and I would be more inclined to use a build tag and make this part of normal engine on v4. The person who complained about this can use the build tag and all the rest can live without having to know about this, that is to me the definition of compatibility.

BONUS: the change for supporting a build tag seems very easy as in this PR we support both.

Copy link
Member Author

@fzipi fzipi May 9, 2024

Choose a reason for hiding this comment

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

Can someone then, with more knownledge than me, add that magnificent build tag and we can get over this?

Copy link
Member

Choose a reason for hiding this comment

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

Check #1065

Copy link
Member

Choose a reason for hiding this comment

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

@M4tteoP in order to be facts driven, could you please show a rule that would break across versions so we are 100% sure this aren't hypoteticall concerns?

Copy link
Member

@M4tteoP M4tteoP May 15, 2024

Choose a reason for hiding this comment

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

Uhmm, the line we are commenting on should indeed be the case:
With ARGS not case-sensitive, we might have in place a rule like:

SecRule ARGS_GET:var3 "@rx pre3payloadpost"  "id:300, phase:2, log, msg:'Rule Parent 300'...

We are expecting that it will check ARGS_GET:var3, ARGS_GET:Var3, ARGS_GET:VAR3...

Enabling case sensitivity, it would suddenly just check ARGS_GET:var3. If a user wrote that rule with the intent of matching for example ARGS_GET:Var3, the rule would never trigger anymore (The test is calling /testcase3.php?Var3=pre3payloadpost)

* feat: adds build tag for case sensitive args keys.

* chore: updates license year.
// Copyright 2024 Juan Pablo Tosso and the OWASP Coraza contributors
// SPDX-License-Identifier: Apache-2.0

//go:build coraza.rule.case_sensitive_args_keys
Copy link
Member

Choose a reason for hiding this comment

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

I think it deserves a line in the README under the Build tags section

Copy link
Member

Choose a reason for hiding this comment

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

Something like the following?

* `case_sensitive_args_keys` - enables case-sensitive matching for ARGS keys, aligning Coraza behavior with RFC 3986 specification. It will be enabled by default in the next major version.

if 👍 I would push the line and merge it

Copy link
Member

@M4tteoP M4tteoP left a comment

Choose a reason for hiding this comment

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

I see no more raised concerns, so merging!

@M4tteoP M4tteoP merged commit 711e4a4 into main May 28, 2024
7 checks passed
@M4tteoP M4tteoP deleted the change-args-names-to-be-case-sensitive branch May 28, 2024 17:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants