Skip to content

Fix variables case sensitiveness #1810

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

Closed
wants to merge 1 commit into from
Closed

Fix variables case sensitiveness #1810

wants to merge 1 commit into from

Conversation

victorhora
Copy link
Contributor

Changes the behaviour of the collection backend to fix an issue where variables were case sensitive in some scenarios. Should fix #1808.

@theMiddleBlue
Copy link

Tested with setvar:tx.paranoia_level=1, it works! Thanks @victorhora !

@@ -106,7 +106,7 @@ void InMemoryPerProcess::resolveMultiMatches(const std::string& var,
}
} else {
for (auto &a : *this) {
if (a.first.compare(0, var.size(), var) == 0) {
if (strncasecmp(a.first.c_str(), var.c_str(), a.first.size()) == 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Ignoring the change from case-sensitive to case-insensitive (which is the correct fix):

The old code compares the first var.size() characters, the new code compares the first a.first.size() characters. If these two sizes are not the same, this is not equivalent.

Consider var = "tx.paranoia", key = "tx.paranoia_level": the old comparison is true, the new one false.

I don't know why the logic was changed from full comparison to partial comparison in the first place (it looks wrong to me), but with this commit we're changing the logic again.

It would be good to learn about the motivation of the original change (892beb5). One aspect is that it turned a hash lookup into a linear search, so it may well have performance impact.

Copy link
Member

@airween airween Jun 22, 2018

Choose a reason for hiding this comment

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

Consider var = "tx.paranoia", key = "tx.paranoia_level": the old comparison is true, the new one false.

Sorry for the question, but why is the old way accepted? In my opinion, any strNcmp is incomprehensible. If I want to set a variable with name tx.paranoia, I want to search it exactly, not the ones which starts with it. :)

I mean, the old any new method is wrong :)

Copy link
Contributor

Choose a reason for hiding this comment

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

@airween : I agree with you, as I said in my comment. For the purpose of this PR, however, I was just pointing out the change in logic that is not related to case sensitivity, which is the only thing this commit should change.

I've raised the question of comparing only the first N bytes on the original PR.

Copy link
Member

Choose a reason for hiding this comment

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

@michaelgranzow-avi : sorry, may be you misunderstood me. I don't understand why is there any strn... comparing, instead of "simple" strcmp()/strcasecmp()? Why just need to compare the first N byte, why not the two strings as they are, without any length argument?

Copy link
Contributor

Choose a reason for hiding this comment

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

@airween, I know what you mean and I agree with you. I've opened #1818 and added a patch.

Copy link
Contributor

Choose a reason for hiding this comment

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

Proposed fix: #1820 - this would make the current PR #1810 unnecessary.

@zimmerle
Copy link
Contributor

fixed by: d810de9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.x Related to ModSecurity version 3.x RIP - libmodsecurity
Projects
None yet
Development

Successfully merging this pull request may close these issues.

setvar tx.paranoia_level on v3/master ignored
5 participants