Skip to content

Commit

Permalink
Fix mastodon#26849 by adding the domain of the current SSO provider t…
Browse files Browse the repository at this point in the history
…o the form-action CSP (mastodon#26857)
  • Loading branch information
CSDUMMI authored and audiodude committed Oct 23, 2023
1 parent 172ba2e commit 3d71791
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/controllers/concerns/web_app_controller_concern.rb
Expand Up @@ -11,7 +11,7 @@ module WebAppControllerConcern
end

def skip_csrf_meta_tags?
!(ENV['OMNIAUTH_ONLY'] == 'true' && Devise.omniauth_providers.length == 1) && current_user.nil?
!(ENV['ONE_CLICK_SSO_LOGIN'] == 'true' && ENV['OMNIAUTH_ONLY'] == 'true' && Devise.omniauth_providers.length == 1) && current_user.nil?
end

def set_app_body_class
Expand Down
2 changes: 1 addition & 1 deletion app/serializers/initial_state_serializer.rb
Expand Up @@ -113,6 +113,6 @@ def instance_presenter
end

def sso_redirect
"/auth/auth/#{Devise.omniauth_providers[0]}" if ENV['OMNIAUTH_ONLY'] == 'true' && Devise.omniauth_providers.length == 1
"/auth/auth/#{Devise.omniauth_providers[0]}" if ENV['ONE_CLICK_SSO_LOGIN'] == 'true' && ENV['OMNIAUTH_ONLY'] == 'true' && Devise.omniauth_providers.length == 1
end
end
24 changes: 23 additions & 1 deletion config/initializers/content_security_policy.rb
Expand Up @@ -19,6 +19,22 @@ def host_to_url(str)
media_host ||= host_to_url(ENV['S3_HOSTNAME']) if ENV['S3_ENABLED'] == 'true'
media_host ||= assets_host

def sso_host
return unless ENV['ONE_CLICK_SSO_LOGIN'] == 'true'
return unless ENV['OMNIAUTH_ONLY'] == 'true'
return unless Devise.omniauth_providers.length == 1

provider = Devise.omniauth_configs[Devise.omniauth_providers[0]]
@sso_host ||= begin
# using CAS
provider.cas_url if ENV['CAS_ENABLED'] == 'true'
# using SAML
provider.options[:idp_sso_target_url] if ENV['SAML_ENABLED'] == 'true'
# or using OIDC
ENV['OIDC_AUTH_ENDPOINT'] || (OpenIDConnect::Discovery::Provider::Config.discover!(ENV['OIDC_ISSUER']).authorization_endpoint if ENV['OIDC_ENABLED'] == 'true')
end
end

Rails.application.config.content_security_policy do |p|
p.base_uri :none
p.default_src :none
Expand All @@ -29,7 +45,13 @@ def host_to_url(str)
p.media_src :self, :https, :data, assets_host
p.frame_src :self, :https
p.manifest_src :self, assets_host
p.form_action :self

if sso_host.present?
p.form_action :self, sso_host
else
p.form_action :self
end

p.child_src :self, :blob, assets_host
p.worker_src :self, :blob, assets_host

Expand Down

0 comments on commit 3d71791

Please sign in to comment.