Skip to content

Conversation

@lukaso
Copy link

@lukaso lukaso commented May 5, 2020

Cookies can on occasion have base 64 encoded strings as their value. Base 64 encoded strings tend to end in '=' as this is a filler character. Cookies of this form cause rack to fail.

An example is __cf_bm=_somebase64encodedstringwithequalsatthened=; array=awesome.

This fixes the bug.

Alternative approach would be that in the function I've patched, to only parse the headers required in the enclosing function.

lib/rack/mock.rb Outdated
cookie_attributes.store('value', cookie_bits[0].strip)
cookie_bits.each do |bit|
if bit.include? '='
cookie_attribute, attribute_value = bit.split('=')
Copy link
Member

Choose a reason for hiding this comment

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

Would it make mores sense to use split('=', 2)?

Copy link
Author

Choose a reason for hiding this comment

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

Yes, also works. Either way, the results of this function are discarded other than for these areas:
https://github.com/rack/rack/pull/1645/files#diff-4fc9bc1f7d91630f4f9f47fc6663f3f7L240-L245

It is probably incorrect to assume '=' is a divider.

A third option is not to process the first element of the cookie_bits array at all, since this is the value. So cookie_bits[1..].each do |bit|.

Fourth option, do both since the value could possibly also contain '='.

Copy link
Author

Choose a reason for hiding this comment

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

Done both in f48f0b8

@lukaso
Copy link
Author

lukaso commented May 6, 2020

BTW: the build failures appear to be due to this: ruby/rubygems#3570

Copy link
Member

@tenderlove tenderlove left a comment

Choose a reason for hiding this comment

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

This seems good, but we need to make sure the build passes. It looks like there is a legit failure in 2.5

Co-authored-by: Aaron Patterson <aaron.patterson@gmail.com>
@lukaso
Copy link
Author

lukaso commented May 8, 2020

This seems good, but we need to make sure the build passes. It looks like there is a legit failure in 2.5

Done in c17569c. Thanks!

@lukaso lukaso requested a review from tenderlove May 12, 2020 21:22
@tenderlove tenderlove merged commit 6a50e46 into rack:master May 22, 2020
@lukaso lukaso deleted the base64_cookie_values branch July 1, 2020 09:55
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.

3 participants