So I have built a form in Laravel and am hosting externally but I want to display this within a HTML page but am having issues with the X-Frame-Options.
The exact error message is:
Refused to display 'url' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'.
I have seen on previous StackOverflow answers that this is due to FrameGuard Middleware but this has since been removed and the issue line of code is not in that file.
Laravel Version 5.3.
I have also tried to set the X-Frame-Options in the Nginx config file using the flooring with no result:
sed -i 's/http\ {/http\ {\nadd_header X-Frame-Options SAMEORIGIN, false;\n\n/' /etc/nginx/nginx.conf
This error is occurring in multiple browsers, tested: Chrome & Safari
In my case, nginx was the one preventing the access.
Run:
And check the output:
After replacing DENY to SAMEORIGIN everything started working as expected.
Set your header on the response from the frame to
where example.com is the domain requesting the form.
You could use middleware in laravel to do this.
Generate a new middleware.
then in the handle function of the middleware you just created do something like:
You can then add this to one of the middleware arrays in Kernel.php
Or to one of the middleware group arrays if you want to add it only to specific routes.