rails: Cookies are being set incorrectly
Cookies are being sent wrapped in an array string, not in the correct format. Results in keys to cookies including an extraneous [" prefix that breaks querying later. First practical effect is breaking the establishment of current user identity in ActionCable::Channel
Steps to reproduce
Set any cookie. Inspect response headers and cookie store in browser. Compare to behavior witih literally any other site on the web.
Expected behavior
Actual behavior
System configuration
Rails version: 7.1.0.alpha
Ruby version: 3.2.2
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 17 (7 by maintainers)
Commits related to this issue
- support Rack 3.0 multi-value headers (from https://github.com/rails/rails/issues/48195) — committed to GernotUllrich/unicorn by GernotUllrich 2 years ago
I hit this today when I took my new Rails app that I created two weeks ago into production. Downgrading rack to 2.2.8 was the fix.
I built a minimal repro here and I opened a PR for Puma. I think a lot of people are about to hit this (when Rails 7.1 releases). I am hoping to mitigate it.
Upgrading to Puma 6 should fix the issue.
This issue also affects unicorn. The master branch supports Rack 3 but the latest version of unicorn (6.1.0) doesn’t support it. A v7 release of unicorn will be here “soon” as mentioned here: https://yhbt.net/unicorn-public/20231214230933.M299458@dcvr/
The latest release of passenger is not compatible with Rack 3. You can add
gem "rack", "< 3"to your Gemfile to use Rails 7.1https://github.com/phusion/passenger/blob/b4c3921de29b3fa6aaa0d300fb06df67f12df698/CHANGELOG#L3
I had the same issue. I tracked it to Puma 5 with rack 3. If you generated your app a while ago, your gemfile probably has
gem "puma", "~> 5.0"(mine did) which would give you the broken combination when runningbundle update.If you run a
rails newtoday (from main), you’ll getgem "puma", ">= 5.0"instead. Which explain why it’s hard to recreate.It looks like rails with rack 2 used to return only strings separated by line jump for the
set-cookieheader. Now it returns arrays if there is more than one cookie.I am having trouble reproducing this locally. Could you share some more information?
For example, which cookie serializer are you using? Which
config.load_defaultsversion? Are you using any add-ons? Can you reproduce this with a fresh Rails 7.1 app? Could you share a minimal reproduction script or app?Also, would you mind trying the latest
mainref now that #48197 is merged?