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

Support for the Partitioned cookie attribute #2131

Merged
merged 5 commits into from
Oct 31, 2023
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ All notable changes to this project will be documented in this file. For info on
- MIME type for JavaScript files (`.js`) changed from `application/javascript` to `text/javascript` ([`1bd0f15`](https://github.com/rack/rack/commit/1bd0f1597d8f4a90d47115f3e156a8ce7870c9c8))
- Add `.mjs` MIME type ([#2057](https://github.com/rack/rack/pull/2057), [@axilleas])
- Update MIME types associated to `.ttf`, `.woff`, `.woff2` and `.otf` extensions to use mondern `font/*` types. ([#2065](https://github.com/rack/rack/pull/2065), [@davidstosik])
- `set_cookie_header` utility now supports the `partitioned` cookie attribute. This is required by Chrome in some embedded contexts. ([#2131](https://github.com/rack/rack/pull/2131), [@flavio-b])

## [3.0.8] - 2023-06-14

Expand Down
3 changes: 2 additions & 1 deletion lib/rack/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ def set_cookie_header(key, value)
else
raise ArgumentError, "Invalid :same_site value: #{value[:same_site].inspect}"
end
partitioned = "; partitioned" if value[:partitioned]
value = value[:value]
else
key = escape(key)
Expand All @@ -297,7 +298,7 @@ def set_cookie_header(key, value)
value = [value] unless Array === value

return "#{key}=#{value.map { |v| escape v }.join('&')}#{domain}" \
"#{path}#{max_age}#{expires}#{secure}#{httponly}#{same_site}"
"#{path}#{max_age}#{expires}#{secure}#{httponly}#{same_site}#{partitioned}"
end

# :call-seq:
Expand Down
4 changes: 4 additions & 0 deletions test/spec_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,10 @@ def initialize(*)
Rack::Utils.set_cookie_header('na e', value: 'value', escape_key: false).must_equal 'na e=value'
end

it "sets partitioned cookie attribute" do
Rack::Utils.set_cookie_header('name', {value: 'value', partitioned: true}).must_equal 'name=value; partitioned'
end

it "deletes cookies in header field" do
header = []

Expand Down