Skip to content

Commit

Permalink
Added support for SameSite=None cookie value, added in revision 3 of …
Browse files Browse the repository at this point in the history
…rfc6265bis

- https://tools.ietf.org/html/draft-ietf-httpbis-rfc6265bis-03#appendix-A.4
- Indicates that cookie is used as a third party cookie.
  • Loading branch information
hennikul authored and Mikhail Doronin committed Jan 7, 2020
1 parent e7ee459 commit 0177005
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/rack/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,8 @@ def add_cookie_to_header(header, key, value)
case value[:same_site]
when false, nil
nil
when :none, 'None', :None
'; SameSite=None'.freeze
when :lax, 'Lax', :Lax
'; SameSite=Lax'.freeze
when true, :strict, 'Strict', :Strict
Expand Down
18 changes: 18 additions & 0 deletions test/spec_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,24 @@
response["Set-Cookie"].must_equal "foo=bar"
end

it "can set SameSite cookies with symbol value :none" do
response = Rack::Response.new
response.set_cookie "foo", { value: "bar", same_site: :none }
response["Set-Cookie"].must_equal "foo=bar; SameSite=None"
end

it "can set SameSite cookies with symbol value :None" do
response = Rack::Response.new
response.set_cookie "foo", { value: "bar", same_site: :None }
response["Set-Cookie"].must_equal "foo=bar; SameSite=None"
end

it "can set SameSite cookies with string value 'None'" do
response = Rack::Response.new
response.set_cookie "foo", { value: "bar", same_site: "None" }
response["Set-Cookie"].must_equal "foo=bar; SameSite=None"
end

it "can set SameSite cookies with symbol value :lax" do
response = Rack::Response.new
response.set_cookie "foo", {:value => "bar", :same_site => :lax}
Expand Down

0 comments on commit 0177005

Please sign in to comment.