Fix cookies secure flag being set when served over Tor (#17992)
This commit is contained in:
parent
46633f1de1
commit
6e418bf346
|
@ -40,7 +40,6 @@ require_relative '../lib/devise/two_factor_pam_authenticatable'
|
||||||
require_relative '../lib/chewy/strategy/custom_sidekiq'
|
require_relative '../lib/chewy/strategy/custom_sidekiq'
|
||||||
require_relative '../lib/webpacker/manifest_extensions'
|
require_relative '../lib/webpacker/manifest_extensions'
|
||||||
require_relative '../lib/webpacker/helper_extensions'
|
require_relative '../lib/webpacker/helper_extensions'
|
||||||
require_relative '../lib/action_dispatch/cookie_jar_extensions'
|
|
||||||
require_relative '../lib/rails/engine_extensions'
|
require_relative '../lib/rails/engine_extensions'
|
||||||
require_relative '../lib/active_record/database_tasks_extensions'
|
require_relative '../lib/active_record/database_tasks_extensions'
|
||||||
require_relative '../lib/active_record/batches'
|
require_relative '../lib/active_record/batches'
|
||||||
|
|
|
@ -8,7 +8,6 @@ Warden::Manager.after_set_user except: :fetch do |user, warden|
|
||||||
value: session_id,
|
value: session_id,
|
||||||
expires: 1.year.from_now,
|
expires: 1.year.from_now,
|
||||||
httponly: true,
|
httponly: true,
|
||||||
secure: (Rails.env.production? || ENV['LOCAL_HTTPS'] == 'true'),
|
|
||||||
same_site: :lax,
|
same_site: :lax,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
@ -23,7 +22,6 @@ Warden::Manager.after_fetch do |user, warden|
|
||||||
value: session_id,
|
value: session_id,
|
||||||
expires: 1.year.from_now,
|
expires: 1.year.from_now,
|
||||||
httponly: true,
|
httponly: true,
|
||||||
secure: (Rails.env.production? || ENV['LOCAL_HTTPS'] == 'true'),
|
|
||||||
same_site: :lax,
|
same_site: :lax,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -265,7 +263,7 @@ Devise.setup do |config|
|
||||||
|
|
||||||
# Options to be passed to the created cookie. For instance, you can set
|
# Options to be passed to the created cookie. For instance, you can set
|
||||||
# secure: true in order to force SSL only cookies.
|
# secure: true in order to force SSL only cookies.
|
||||||
config.rememberable_options = { secure: true }
|
config.rememberable_options = {}
|
||||||
|
|
||||||
# ==> Configuration for :validatable
|
# ==> Configuration for :validatable
|
||||||
# Range for password length.
|
# Range for password length.
|
||||||
|
|
|
@ -2,5 +2,5 @@
|
||||||
|
|
||||||
Rails.application.config.session_store :cookie_store,
|
Rails.application.config.session_store :cookie_store,
|
||||||
key: '_mastodon_session',
|
key: '_mastodon_session',
|
||||||
secure: (Rails.env.production? || ENV['LOCAL_HTTPS'] == 'true'),
|
secure: false, # All cookies have their secure flag set by the force_ssl option in production
|
||||||
same_site: :lax
|
same_site: :lax
|
||||||
|
|
|
@ -1,25 +0,0 @@
|
||||||
# frozen_string_literal: true
|
|
||||||
|
|
||||||
module ActionDispatch
|
|
||||||
module CookieJarExtensions
|
|
||||||
private
|
|
||||||
|
|
||||||
# Monkey-patch ActionDispatch to serve secure cookies to Tor Hidden Service
|
|
||||||
# users. Otherwise, ActionDispatch would drop the cookie over HTTP.
|
|
||||||
def write_cookie?(*)
|
|
||||||
request.host.end_with?('.onion') || super
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
ActionDispatch::Cookies::CookieJar.prepend(ActionDispatch::CookieJarExtensions)
|
|
||||||
|
|
||||||
module Rack
|
|
||||||
module SessionPersistedExtensions
|
|
||||||
def security_matches?(request, options)
|
|
||||||
request.host.end_with?('.onion') || super
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
Rack::Session::Abstract::Persisted.prepend(Rack::SessionPersistedExtensions)
|
|
Loading…
Reference in New Issue