makara icon indicating copy to clipboard operation
makara copied to clipboard

cookie[:max_age] must be a string on rack 1.5.5. Makara supplies an integer.

Open jamby1100 opened this issue 7 years ago • 6 comments

Hi Task Rabbit Team,

I hope you're having a great day so far! (or night, wherever you are in the world)

Reporting a bug when I use makara with:

Rails 4.0 spree_auth_devise (2.2.0) spree 2.2 rack 1.5.5 ruby 2.1.1

The error is specified below. This happens whenever I try to sign out, or add to cart.

no implicit conversion of Fixnum into String rack (1.5.5) lib/rack/utils.rb, line 265


  260       def set_cookie_header!(header, key, value)
  261         case value
  262         when Hash
  263           domain  = "; domain="  + value[:domain] if value[:domain]
  264           path    = "; path="    + value[:path]   if value[:path]
> 265           max_age = "; max-age=" + value[:max_age] if value[:max_age]
  266           # There is an RFC mess in the area of date formatting for Cookies. Not
  267           # only are there contradicting RFCs and examples within RFC text, but
  268           # there are also numerous conflicting names of fields and partially
  269           # cross-applicable specifications.
  270           #

The trace is:

  • rack (1.5.5) lib/rack/utils.rb:265:in `set_cookie_header!'
  • makara (0.4.0) lib/makara/cookie.rb:20:in `store'
  • makara (0.4.0) lib/makara/middleware.rb:31:in `store_new_context'
  • makara (0.4.0) lib/makara/middleware.rb:17:in `call'
  • newrelic_rpm (5.0.0.342) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
  • exception_notification (4.0.1) lib/exception_notification/rack.rb:28:in `call'
  • newrelic_rpm (5.0.0.342) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
  • newrelic_rpm (5.0.0.342) lib/new_relic/rack/agent_hooks.rb:30:in `traced_call'
  • newrelic_rpm (5.0.0.342) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
  • newrelic_rpm (5.0.0.342) lib/new_relic/rack/browser_monitoring.rb:32:in `traced_call'
  • newrelic_rpm (5.0.0.342) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
  • rack (1.5.5) lib/rack/deflater.rb:25:in `call'
  • newrelic_rpm (5.0.0.342) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call' ... more trace ... (let me know if you need to see the entire trace)

I looked through the second file in the trace (which is a file in Makara). The build_cookie in cookies.rb makes the cookie[:max_age] to be an integer. Rack 1.5.5 requires it to be a string so it can do the concatenation on lib/rack/utils.rb, line 265.

My solution was creating a fork from your repository so I can quickly get up and running with Makara. This fixed the problem on my end. Kindly see my changes here

With this, I'm not sure if this fixes the problem entirely or if Makara requires cookie[:max_age] to be an integer somewhere else. What do you think?

Thank you and kindly let me know if you need anything else on my end to help :D

jamby1100 avatar Sep 26 '18 02:09 jamby1100

Research:

I see that rack 1.6.10 at least has: max_age = "; max-age=" + value[:max_age].to_s if value[:max_age] Made here: https://github.com/rack/rack/pull/697/files

And the current rack master does this: max_age = "; max-age=#{value[:max_age]}" if value[:max_age] That was 4 years ago.

Regardless, it seems fine to to_s it in makara to be compatible. @rosa what you think?

bleonard avatar Sep 26 '18 07:09 bleonard

@bleonard yes! That seems totally fine 👍 Happy to do the change if you want!

rosa avatar Sep 26 '18 07:09 rosa

Go for it! Or maybe @jamby1100 wants to make a PR and you review.

bleonard avatar Sep 26 '18 08:09 bleonard

Or maybe @jamby1100 wants to make a PR and you review.

Oh, yes, even better! 👍

rosa avatar Sep 26 '18 10:09 rosa

Thanks @rosa and @bleonard, will send in a pull request on the weekend! :D

jamby1100 avatar Sep 26 '18 15:09 jamby1100

For now I circumvent this issue by adding: application.rb config.middleware.delete Makara::Middleware

database.yml sticky: false

tomymehdi avatar Oct 24 '18 18:10 tomymehdi