Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot display my rails 4 app in iframe even if 'X-Frame-Options' is 'ALLOWALL'

I am trying to test a responsive design. I am using Rails 4. I know it sets 'X-Frame-Options' to SAME ORIGIN. So I overrided it in development.rb using

config.action_dispatch.default_headers = {     'X-Frame-Options' => 'ALLOWALL'   } 

and it worked. I checked out the network request in the Chrome console and it is as follows:

enter image description here

But still websites like responsive.is and responsinator.com give me below error:

Refused to display 'http://localhost:3000/' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'. about:blank:1 

Whats going on??

like image 778
Steve Robinson Avatar asked Jul 09 '13 07:07

Steve Robinson


People also ask

How do I set X-Frame-options to allow all?

Allowing all domains is the default. Don't set the X-Frame-Options header at all if you want that. Note that the successor to X-Frame-Options — CSP's frame-ancestors directive — accepts a list of allowed origins so you can easily allow some origins instead of none, one or all. Save this answer.

Should I enable X-Frame-options?

It is recommended that you use the X-Frame-Options header on pages which should not be allowed to render a page in a frame.

Does Chrome support X-Frame-options allow-From?

Chrome does not support the ALLOW-FROM directive in X-Frame-Options. So if we are going to do anything involving other domains, we need something similar. We can stitch together a patchwork configuration involving both headers, which does something more than just allow same-origin framing.


2 Answers

Try just to delete this header 'X-Frame-Options'. Maybe this way in controller:

before_filter :allow_iframe_requests ... def allow_iframe_requests   response.headers.delete('X-Frame-Options') end 
like image 164
Timrael Avatar answered Sep 27 '22 22:09

Timrael


I had the same problem as you, and searched for a solution to this problem all night.

I finally found out why it happens. It's because of the Chrome cache.

You can see the header['X-Frame-Options'] is ALLOWALL but it doesn't work.

Just try to open a "New Incognito Window" and go the same page and it works!

This problem only happened in development mode in my test. It worked fine in production mode.

like image 39
Yi Feng Xie Avatar answered Sep 27 '22 22:09

Yi Feng Xie