-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Aligned Cookie parsing method to ModSecurity2 style #2023
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
Note, that this bug triggered by this CRS test. |
@@ -571,6 +571,14 @@ int Transaction::addRequestHeader(const std::string& key, | |||
m_variableRequestCookies.set(s[0], s[1], localOffset); | |||
localOffset = localOffset + s[1].size() + 2; | |||
} | |||
else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we want to check if it is bigger than 0. Just to avoid a memory access violation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But if we checked pos1 > 0
, then what if the Cookie header starts with '='?
Should be check pos >= 0
?
Hi @airween, I remember that we were discussing this issue over hangout a few days ago. Are the changes ready? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't modified the affected code since, just make a small program to demonstrate the differences between old method and new one. Here is it:
https://gist.github.com/airween/efb8a737193910b5ae893d93e0325902
@@ -571,6 +571,14 @@ int Transaction::addRequestHeader(const std::string& key, | |||
m_variableRequestCookies.set(s[0], s[1], localOffset); | |||
localOffset = localOffset + s[1].size() + 2; | |||
} | |||
else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But if we checked pos1 > 0
, then what if the Cookie header starts with '='?
Should be check pos >= 0
?
I've merged the newest version from upstream to this branch. Could we continue the discussion about the patch? First, please review the snippet: The C++ code contains the old (current) and the new method of cookie parsing. You can pass the cookie string to the compiled binary as argument (see output.txt). The first line is the output of current version, the second is the last product. The |
May be it's not a bug, but the behavior is differ from ModSec v2. Here is an example, take a look to this header request:
Cookie: foo
This is invalid, because the RFC allows the Cookie as like this:
But ModSec2 interprets this as there is a cookie with name "foo" with empty value.
This patch aligns the behavior of ModSec3.