rack / rack-session

MIT License
33 stars 14 forks source link

NoMethodError: undefined method `rpartition' for nil:NilClass #11

Closed everton closed 2 years ago

everton commented 2 years ago

When I access any URL (browser or curl) using the Rack::Session::Cookie it raises the exception:

NoMethodError at /
undefined method `rpartition' for nil:NilClass

            session_data, _, digest = cookie_data.rpartition('--')

file: rack-session-0.2.1/lib/rack/session/cookie.rb: in block in unpacked_cookie_data, line 229

Can be reproduced using the rack "hello, world" app:

require 'rack'
require 'rack/session'

use Rack::Session::Cookie,
  domain: '127.0.0.1:9292',
  expire_after: 3600*24,
  secret: '***********************unique secret key************************'

run ->(env) {
  [ 200,  { "Content-Type" => "text/html" }, [ "Hello World!" ]]
}
mperham commented 2 years ago

Same. This affects Sidekiq::Web on Rack 3.

ioquatix commented 2 years ago

@mperham do you have time to investigate? Otherwise I can take a look later.

mperham commented 2 years ago

I don’t know anything of Rack internals. It’s nighttime here, I can debug tomorrow if you’d like.

ioquatix commented 2 years ago

I may have time tonight to have a look, and if so I'll report back here. Otherwise if you want to have a go, that would be swell.

mperham commented 2 years ago

I debugged a bit but I really don't know anything about Rack's cookie handling and legacy option handling so I don't know what the "proper" fix is. If you throw a binding.pry after cookie.rb line 210, you'll have the context. line 216 checks for nil cookie_data but line 229 does not.

jeremyevans commented 2 years ago

I submitted a possible fix for this: #12

everton commented 2 years ago

I can confirm it solved the original problem, but now I'm facing a second issue:

Rack::Lint::LintError at / uppercase character in header name: Content-Type

I can understand this relates to https://github.com/rack/rack/issues/1592 but it is not clear to me if I should open another issue here or on Rack itself.

mperham commented 2 years ago

@everton "Content-Type", and all headers, must be lower case in your code.

everton commented 2 years ago

@everton "Content-Type", and all headers must be lower case in your code.

Of course, sorry, this was about MY code, not yours, totally right! Thanks and sorry for making you lose time.