Skip to content

Commit a77a358

Browse files
authored
Merge pull request rails#54843 from skipkayhil/hm-cookie-length-name
Include cookie name in length calculation
2 parents 8e88224 + 69a1e07 commit a77a358

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed

actionpack/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
* Include cookie name when calculating maximum allowed size.
2+
3+
*Hartley McGuire*
4+
15
* Implement `must-understand` directive according to RFC 9111.
26

37
The `must-understand` directive indicates that a cache must understand the semantics of the response status code, or discard the response. This directive is enforced to be used only with `no-store` to ensure proper cache behavior.

actionpack/lib/action_dispatch/middleware/cookies.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -610,8 +610,10 @@ def commit(name, options)
610610
end
611611

612612
def check_for_overflow!(name, options)
613-
if options[:value].bytesize > MAX_COOKIE_SIZE
614-
raise CookieOverflow, "#{name} cookie overflowed with size #{options[:value].bytesize} bytes"
613+
total_size = name.to_s.bytesize + options[:value].bytesize
614+
615+
if total_size > MAX_COOKIE_SIZE
616+
raise CookieOverflow, "#{name} cookie overflowed with size #{total_size} bytes"
615617
end
616618
end
617619
end

actionpack/test/dispatch/cookies_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -972,7 +972,7 @@ def test_raise_data_overflow
972972
error = assert_raise(ActionDispatch::Cookies::CookieOverflow) do
973973
get :raise_data_overflow
974974
end
975-
assert_equal "foo cookie overflowed with size 5522 bytes", error.message
975+
assert_equal "foo cookie overflowed with size 5525 bytes", error.message
976976
end
977977

978978
def test_tampered_cookies

actionpack/test/dispatch/session/cookie_store_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ def test_close_raises_when_data_overflows
203203
error = assert_raise(ActionDispatch::Cookies::CookieOverflow) {
204204
get "/raise_data_overflow"
205205
}
206-
assert_equal "_myapp_session cookie overflowed with size 5612 bytes", error.message
206+
assert_equal "_myapp_session cookie overflowed with size 5626 bytes", error.message
207207
end
208208
end
209209

0 commit comments

Comments
 (0)