Skip to content
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

Fix to handle same_site option for session pool #1587

Merged
merged 1 commit into from Feb 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/rack/session/abstract/id.rb
Expand Up @@ -252,6 +252,7 @@ def initialize(app, options = {})
@default_options = self.class::DEFAULT_OPTIONS.merge(options)
@key = @default_options.delete(:key)
@cookie_only = @default_options.delete(:cookie_only)
@same_site = @default_options.delete(:same_site)
initialize_sid
end

Expand Down
1 change: 0 additions & 1 deletion lib/rack/session/cookie.rb
Expand Up @@ -118,7 +118,6 @@ def initialize(app, options = {})
Called from: #{caller[0]}.
MSG
@coder = options[:coder] ||= Base64::Marshal.new
@same_site = options.delete :same_site
super(app, options.merge!(cookie_only: true))
end

Expand Down
19 changes: 19 additions & 0 deletions test/spec_session_pool.rb
Expand Up @@ -178,6 +178,25 @@
pool.pool[session_id.public_id].must_be_nil
end

it "passes through same_site option to session pool" do
pool = Rack::Session::Pool.new(incrementor, same_site: :none)
req = Rack::MockRequest.new(pool)
res = req.get("/")
res["Set-Cookie"].must_include "SameSite=None"
end

it "allows using a lambda to specify same_site option, because some browsers require different settings" do
pool = Rack::Session::Pool.new(incrementor, same_site: lambda { |req, res| :none })
req = Rack::MockRequest.new(pool)
res = req.get("/")
res["Set-Cookie"].must_include "SameSite=None"

pool = Rack::Session::Pool.new(incrementor, same_site: lambda { |req, res| :lax })
req = Rack::MockRequest.new(pool)
res = req.get("/")
res["Set-Cookie"].must_include "SameSite=Lax"
end

# anyone know how to do this better?
it "should merge sessions when multithreaded" do
unless $DEBUG
Expand Down