Skip to content

Fix Cookie header parsing issues #2202

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 2 commits into from
Closed

Fix Cookie header parsing issues #2202

wants to merge 2 commits into from

Conversation

martinhsv
Copy link
Contributor

This pull request includes airween's fixes plus the additional issue identified yesterday

@airween
Copy link
Member

airween commented Nov 14, 2019

Hi @martinhsv, I saw your addition part of transaction.cc, but I don't see the point. I assume you want to remove the trailing spaces, but (may be I'm wrong) I don't understand why do you do that only in case of last cookie?

And I think that method does not have effect if the cookie is like this:

Cookie: foo=bar; baz=foo ;

Also note, that the reason why I didn't adopted this feature, that the existing regression tests contains the trim action for the checked variable, so I assume the original intention was to keep the cookie as is, and the rule writer can decide that is it allowed or not.

The leading spaces (in case of all keys) is justifiable from my point, because the modsecurity2 does it, and I tried to align the method like that.

What do you think about it?

@martinhsv
Copy link
Contributor Author

The reason is this portion of the grammar: 'cookie-header = "Cookie:" OWS cookie-string OWS'.

The OWS (optional whitespace) can occur after the last cookie-pair (and not, for example, between 'baz=foo' and ';' as in your example).

You are correct that this extra change is at least somewhat less urgent than a portion of your fix, since a rule writer could manage this by always using t:trim for cookie values. However, I would argue that that is not the correct approach. Since the RFC explicitly defines whitespace at the end of the cookie header as not being part of the final value, we should not make it the responsibility of the rule writer to finish the parsing correctly.

@airween
Copy link
Member

airween commented Nov 14, 2019

The reason is this portion of the grammar: 'cookie-header = "Cookie:" OWS cookie-string OWS'.

but - in my opinion - then it would be better to place it before the ssplit() method, with argument value. I think it would be more clear for an external viewer.

The OWS (optional whitespace) can occur after the last cookie-pair (and not, for example, between 'baz=foo' and ';' as in your example).

Sure - if you see my previous patch (#2023), then you can see I also reviewed the RFC.

And if you see my example above, you can see the spaces after the last ;. That means if the cookie header looks like that, then the optional whitespaces will remain until the process. But it no matter :).

You are correct that this extra change is at least somewhat less urgent than a portion of your fix, since a rule writer could manage this by always using t:trim for cookie values. However, I would argue that that is not the correct approach. Since the RFC explicitly defines whitespace at the end of the cookie header as not being part of the final value, we should not make it the responsibility of the rule writer to finish the parsing correctly.

Just my 2 cents: I don't want to argue, but would like to discuss. :)

@martinhsv
Copy link
Contributor Author

Re 'before the ssplit()': Yes, that was my first impulse. But, I didn't want to remove the const-ness of value and preferred not to make yet another copy just for this. (That doesn't mean my choice of implementation is the only correct/reasonable choice, of course.)

And, no worries, such discussion seems entirely reasonable to me.

@dune73
Copy link
Member

dune73 commented Nov 15, 2019

This is a apparently replacing PR #2201 (which looks reasonable to me).

Can you please give us a timeline for the security release fixing these issues in the libModSecurity3 release line?

@zimmerle zimmerle self-requested a review November 20, 2019 11:54
@zimmerle zimmerle self-assigned this Nov 20, 2019
@zimmerle zimmerle added the 3.x Related to ModSecurity version 3.x label Nov 20, 2019
@zimmerle
Copy link
Contributor

Merged! Thanks to everybody involved in the issue.

@zimmerle zimmerle closed this Nov 20, 2019
@theMiddleBlue
Copy link

Thank you all! 🎉 @zimmerle, @martinhsv are you planning to publish a new release version? Just to know if we can inform our users to upgrade.

@zimmerle
Copy link
Contributor

Hi @theMiddleBlue,

You can inform your users to upgrade, the published code on v3/master is passing all the tests. More updates to came. Thank you for your concern.

@carnil
Copy link

carnil commented Jan 21, 2020

Is CVE-2019-19886 relating to this issue?

@airween
Copy link
Member

airween commented Jan 21, 2020

Yes. This is.

@carnil
Copy link

carnil commented Jan 21, 2020

@airween, thanks for confirming!

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants