Skip to content

Commit a0d57d4

Browse files
kamipoioquatix
authored andcommitted
Fix to handle same_site option for session pool
Follow up of #1543.
1 parent a9b223b commit a0d57d4

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

lib/rack/session/abstract/id.rb

+1
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ def initialize(app, options = {})
252252
@default_options = self.class::DEFAULT_OPTIONS.merge(options)
253253
@key = @default_options.delete(:key)
254254
@cookie_only = @default_options.delete(:cookie_only)
255+
@same_site = @default_options.delete(:same_site)
255256
initialize_sid
256257
end
257258

lib/rack/session/cookie.rb

-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ def initialize(app, options = {})
118118
Called from: #{caller[0]}.
119119
MSG
120120
@coder = options[:coder] ||= Base64::Marshal.new
121-
@same_site = options.delete :same_site
122121
super(app, options.merge!(cookie_only: true))
123122
end
124123

test/spec_session_pool.rb

+19
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,25 @@
178178
pool.pool[session_id.public_id].must_be_nil
179179
end
180180

181+
it "passes through same_site option to session pool" do
182+
pool = Rack::Session::Pool.new(incrementor, same_site: :none)
183+
req = Rack::MockRequest.new(pool)
184+
res = req.get("/")
185+
res["Set-Cookie"].must_include "SameSite=None"
186+
end
187+
188+
it "allows using a lambda to specify same_site option, because some browsers require different settings" do
189+
pool = Rack::Session::Pool.new(incrementor, same_site: lambda { |req, res| :none })
190+
req = Rack::MockRequest.new(pool)
191+
res = req.get("/")
192+
res["Set-Cookie"].must_include "SameSite=None"
193+
194+
pool = Rack::Session::Pool.new(incrementor, same_site: lambda { |req, res| :lax })
195+
req = Rack::MockRequest.new(pool)
196+
res = req.get("/")
197+
res["Set-Cookie"].must_include "SameSite=Lax"
198+
end
199+
181200
# anyone know how to do this better?
182201
it "should merge sessions when multithreaded" do
183202
unless $DEBUG

0 commit comments

Comments
 (0)