Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force https links in iframe #3472

Open
paul-mesnilgrente opened this issue Mar 31, 2020 · 6 comments
Open

Force https links in iframe #3472

paul-mesnilgrente opened this issue Mar 31, 2020 · 6 comments

Comments

@paul-mesnilgrente
Copy link

paul-mesnilgrente commented Mar 31, 2020

I am currently using refinery 4 with rails 5.1 and the application is leaving under CloudFront -> AWS load balancers -> Nginx.

My problem is that CloudFront terminates SSL and the stack doesn't let the header X-Fowarded-Proto: https to come through. This has the consequence that iframes in refinery have links in http when the main page is https, browsers don't allow that and blocks the links.

So I am trying to find a way to force links to be https in the iframe but I can't find a way to do it without monkey patching something. I know that the last line being called by Refinery is that one: https://github.com/refinery/refinerycms/blob/master/core/config/initializers/will_paginate_monkeypatch.rb#L16

Is there any settings I can use to force https links in production?

I already tried Rails.application.routes.default_url_options[:protocol] = 'https' but it didn't work. Do you know why maybe?

@bricesanchez
Copy link
Member

Hi @paul-mesnilgrente !

Did you set the Rails config force_ssl = true in config/environments/production.rb ?

@paul-mesnilgrente
Copy link
Author

force_ssl = true causes an infinite loop in our case. The rails application is getting http requests because CloudFront is terminating SSL. This setting also has a lot of side effects that I'd like to avoid. Do you think there is something a bit more specific to what I want?

@parndt
Copy link
Member

parndt commented Jul 8, 2021

Did you ever figure this out?

@paul-mesnilgrente
Copy link
Author

paul-mesnilgrente commented Jul 15, 2021

I've done this very monkey patch:

# frozen_string_literal: true

return unless Rails.env == 'production'

module ActionDispatch
  class Request
    def ssl?
      Rails.logger.info('SSL TRUE')
      true
    end
  end
end

I believe we found a nicer fix in another project but I can't remember what it is.

@fabriazza
Copy link

@paul-mesnilgrente Do you remember which file you placed this block of code in?

@parndt
Copy link
Member

parndt commented Oct 20, 2023

you could probably put code like that in config/initializers/patch_action_dispatch_request.rb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants