Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/controllers/discourse_sso_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ def sso
sso.external_id = user.id # unique to your application
sso.sso_secret = T.must(secret)

redirect_to sso.to_url("#{ENV.fetch('DISCOURSE_URL', nil)}/session/sso_login")
# Sending the user to Discourse (help.morph.io) is the whole point of
# this endpoint, so this cross-host redirect is intended.
redirect_to sso.to_url("#{ENV.fetch('DISCOURSE_URL', nil)}/session/sso_login"), allow_other_host: true
end
end
10 changes: 9 additions & 1 deletion config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,15 @@
module Morph
class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 6.1
config.load_defaults 7.0

# Held back from the 7.0 defaults: Rails 6.1 cannot read 7.0-format
# cache entries, and production memcached outlives a
# `cap production deploy:rollback`, so adopting the new format would
# break rollback to the previous release. Flip to 7.0 once this hop
# has soaked in production (or in the Rails 7.1 upgrade, where 7.0
# becomes the floor anyway).
config.active_support.cache_format_version = 6.1

# Settings in config/environments/* take precedence over those specified here.
# Application configuration can go into files in config/initializers
Expand Down
31 changes: 31 additions & 0 deletions config/initializers/cookie_rotator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Be sure to restart your server when you modify this file.

# Rails 7.0 derives cookie encryption and signing keys with SHA256 where
# Rails 6.1 used SHA1 (active_support.key_generator_hash_digest_class).
# Without this rotator every session and remember-me cookie issued before
# the change becomes unreadable at deploy, logging everyone out. The
# rotator reads cookies under the old SHA1-derived secrets and rewrites
# them under the new ones, exactly as the 7.0 upgrade guide prescribes:
# https://guides.rubyonrails.org/v7.0/upgrading_ruby_on_rails.html
#
# Remove this file once it has been in production long enough for live
# sessions to have been rewritten (they rewrite on first request).
Rails.application.config.after_initialize do
Rails.application.config.action_dispatch.cookies_rotations.tap do |cookies|
authenticated_encrypted_cookie_salt = Rails.application.config.action_dispatch.authenticated_encrypted_cookie_salt
signed_cookie_salt = Rails.application.config.action_dispatch.signed_cookie_salt

secret_key_base = Rails.application.secret_key_base

key_generator = ActiveSupport::KeyGenerator.new(
secret_key_base, iterations: 1000, hash_digest_class: OpenSSL::Digest::SHA1
)
key_len = ActiveSupport::MessageEncryptor.key_len

old_encrypted_secret = key_generator.generate_key(authenticated_encrypted_cookie_salt, key_len)
old_signed_secret = key_generator.generate_key(signed_cookie_salt)

cookies.rotate :encrypted, old_encrypted_secret
cookies.rotate :signed, old_signed_secret
end
end
3 changes: 1 addition & 2 deletions config/initializers/cookies_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@

# Specify a serializer for the signed and encrypted cookie jars.
# Valid options are :json, :marshal, and :hybrid.
# FIXME: Change to :json 1 hour after after next deploy (for seamless upgrade of user session cookies)
Rails.application.config.action_dispatch.cookies_serializer = :hybrid
Rails.application.config.action_dispatch.cookies_serializer = :json
143 changes: 0 additions & 143 deletions config/initializers/new_framework_defaults_7_0.rb

This file was deleted.

Loading