mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-09 22:40:36 +08:00
This patch logs what’s in the cookie when there is an overflow, as it happens sometimes during auth workflows. This should help us better understand what’s happening.
35 lines
1.1 KiB
Ruby
35 lines
1.1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class ActionDispatch::Session::DiscourseCookieStore < ActionDispatch::Session::CookieStore
|
|
def initialize(app, options = {})
|
|
super(app, options)
|
|
end
|
|
|
|
# By default, Rack/Rails will include the session cookie in every response,
|
|
# even if its content hasn't changed. This makes race conditions very likely when
|
|
# multiple requests are made in parallel
|
|
def commit_session?(request, session, options)
|
|
super(request, session, options) && session_has_changed?(request, session)
|
|
end
|
|
|
|
private
|
|
|
|
def set_cookie(request, session_id, cookie)
|
|
if Hash === cookie
|
|
cookie[:secure] = true if SiteSetting.force_https
|
|
unless SiteSetting.same_site_cookies == "Disabled"
|
|
cookie[:same_site] = SiteSetting.same_site_cookies
|
|
end
|
|
end
|
|
cookie_jar(request)[@key] = cookie
|
|
rescue ActionDispatch::Cookies::CookieOverflow
|
|
Rails.logger.error("Cookie overflow occurred for #{@key}: #{request.session.to_h.inspect}")
|
|
raise
|
|
end
|
|
|
|
def session_has_changed?(request, session)
|
|
_, original_session = load_session(request)
|
|
new_session = session.to_hash
|
|
original_session != new_session
|
|
end
|
|
end
|