我正在编写一个小网页,其目的是构建一些其他页面,只是将它们合并到一个浏览器窗口中以便于查看。我尝试框架的一些页面禁止被框架并抛出“拒绝显示文档,因为 X-Frame-Options 禁止显示”。 Chrome 中的错误。我知道这是一个安全限制(有充分的理由),并且无权更改它。
是否有任何替代的框架或非框架方法可以在单个窗口中显示页面,而不会被 X-Frame-Options 标头绊倒?
I'm writing a tiny webpage whose purpose is to frame a few other pages, simply to consolidate them into a single browser window for ease of viewing. A few of the pages I'm trying to frame forbid being framed and throw a "Refused to display document because display forbidden by X-Frame-Options." error in Chrome. I understand that this is a security limitation (for good reason), and don't have access to change it.
Is there any alternative framing or non-framing method to display pages within a single window that won't get tripped up by the X-Frame-Options header?
发布评论
评论(26)
如果一个网站拒绝被框架,就没有办法克服这个问题。
(这篇文章之前包含了错误的建议,建议添加另一个值为
GOFORIT
的X-Frame-Options
标头,但在所有实现中,这也会导致网站拒绝被框架并且实际上并没有解决OP的问题。)If a website refuses to be framed, there is no way to overcome that.
(This post previously contained incorrect advice suggesting adding another
X-Frame-Options
header whose value isGOFORIT
, but in all implementations that would also result in the website refusing to be framed and didn't actually address the question from OP.)如果您在 YouTube 视频中遇到此错误,请不要使用完整的 url,而是使用共享选项中的嵌入 url。它看起来像
http://www.youtube.com/embed/eCfDxZxTBW4
您也可以将
watch?v=
替换为embed/
,这样http://www.youtube.com/watch?v=eCfDxZxTBW4
变为http://www.youtube.com/embed/eCfDxZxTBW4
If you are getting this error for a YouTube video, rather than using the full url use the embed url from the share options. It will look like
http://www.youtube.com/embed/eCfDxZxTBW4
You may also replace
watch?v=
withembed/
sohttp://www.youtube.com/watch?v=eCfDxZxTBW4
becomeshttp://www.youtube.com/embed/eCfDxZxTBW4
如果您在尝试将 Google 地图嵌入
iframe
时遇到此错误,则需要将&output=embed
添加到源链接。If you are getting this error while trying to embed a Google Map in an
iframe
, you need to add&output=embed
to the source link.更新 2019:您可以仅使用客户端绕过
中的
X-Frame-Options
JavaScript 和我的 X-Frame-Bypass Web 组件。这是一个演示:X-Frame-Bypass
中的黑客新闻< /a>. (在 Chrome 和 Firefox 中测试。)UPDATE 2019: You can bypass
X-Frame-Options
in an<iframe>
using just client-side JavaScript and my X-Frame-Bypass Web Component. Here is a demo: Hacker News in anX-Frame-Bypass
. (Tested in Chrome & Firefox.)在 facebook 选项卡中添加
到我的链接解决了我的问题...
Adding a
to my link in the facebook tab fixed the issue for me...
如果您在尝试嵌入 Vimeo 内容时遇到此错误,请更改 iframe 的 src,
来自:https://vimeo。 com/63534746
至:http://player.vimeo.com/video/63534746
If you're getting this error trying to embed Vimeo content, change the src of the iframe,
from: https://vimeo.com/63534746
to: http://player.vimeo.com/video/63534746
当我尝试在 iframe 中嵌入moodle 2时,我遇到了同样的问题,解决方案是
站点管理►安全►HTTP安全
并选中允许框架嵌入
I had same issue when I tried embed moodle 2 in iframe, solution is
Site administration ► Security ► HTTP security
and checkAllow frame embedding
我尝试了几乎所有的建议。然而,唯一真正解决问题的是:
在 PHP 文件所在的同一文件夹中创建一个
.htaccess
。将此行添加到 htaccess:
标头始终未设置 X-Frame-Options
通过 iframe 嵌入 PHP来自另一个域的应该随后可以工作。
另外,您可以在 PHP 文件的开头添加:
但是,在我的情况下没有必要。
I tried nearly all suggestions. However, the only thing that really solved the issue was:
Create an
.htaccess
in the same folder where your PHP file lies.Add this line to the htaccess:
Header always unset X-Frame-Options
Embedding the PHP by an iframe from another domain should work afterwards.
Additionally you could add in the beginning of your PHP file:
Which was, however, not necessary in my case.
将外部网站加载到 iFrame 的解决方案,即使 x-frame 选项设置为拒绝外部网站。
如果您想将其他网站加载到 iFrame 中,您会得到
显示被 X-Frame-Options 禁止”
错误,那么您实际上可以通过创建服务器端代理脚本来克服这个问题。iFrame 的 src 属性可能有一个如下所示的 url:
/proxy.php?url=https://www.example.com/page&key=somekey
然后 proxy.php 看起来像这样:
这绕过了块,因为它只是一个 GET 请求,可能是一个普通的浏览器页面访问。
请注意:您可能希望提高此脚本的安全性。因为黑客可以通过您的代理脚本开始加载网页。
Solution for loading an external website into an iFrame even tough the x-frame option is set to deny on the external website.
If you want to load a other website into an iFrame and you get the
Display forbidden by X-Frame-Options”
error then you can actually overcome this by creating a server side proxy script.The
src
attribute of the iFrame could have an url looking like this:/proxy.php?url=https://www.example.com/page&key=somekey
Then proxy.php would look something like:
This by passes the block, because it is just a GET request that might as wel have been a ordinary browser page visit.
Be aware: You might want to improve the security in this script. Because hackers could start loading in webpages via your proxy script.
这就是解决方案!
唯一适用于 Facebook 应用程序的东西!
This is the solution guys!!
The only thing that worked for facebook apps!
如果您使用 Content-Security-Policy,X-Frame-Options Allow-From https://... 似乎已被贬值并被替换(并被忽略)标题代替。
以下是完整参考:https://content-security-policy.com/
It appears that X-Frame-Options Allow-From https://... is depreciated and was replaced (and gets ignored) if you use Content-Security-Policy header instead.
Here is the full reference: https://content-security-policy.com/
我在使用 mediawiki 时遇到了同样的问题,这是因为服务器出于安全原因拒绝将页面嵌入到 iframe 中。
我解决了它写入
mediawiki php 配置文件。
希望有帮助。
I had the same problem with mediawiki, this was because the server denied embedding the page into an iframe for security reasons.
I solved it writing
into the mediawiki php config file.
Hope it helps.
未提及,但在某些情况下可以提供帮助:
Not mentioned but can help in some instances:
FWIW:
当这个“破坏者”代码出现时,我们需要杀死我们的
iFrame
。因此,我使用 PHPfunction get_headers($url);
来检查远程 URL,然后再将其显示在iFrame
中。为了获得更好的性能,我将结果缓存到一个文件中,这样我就不会每次都建立 HTTP 连接。FWIW:
We had a situation where we needed to kill our
iFrame
when this "breaker" code showed up. So, I used the PHPfunction get_headers($url);
to check out the remote URL before showing it in aniFrame
. For better performance, I cached the results to a file so I was not making a HTTP connection each time.我使用的是 Tomcat 8.0.30,所有建议都不适合我。由于我们希望更新
X-Frame-Options
并将其设置为ALLOW
,因此我配置为允许嵌入 iframe:I was using Tomcat 8.0.30, none of the suggestions worked for me. As we are looking to update the
X-Frame-Options
and set it toALLOW
, here is how I configured to allow embed iframes:如果您不控制 iframe 中所需源的标头,唯一真正的答案就是代理它。让服务器充当客户端,接收源,去除有问题的标头,根据需要添加 CORS,然后 ping 您自己的服务器。
还有另一个答案解释了如何编写这样的代理。这并不困难,但我确信以前一定有人这样做过。由于某种原因,很难找到它。
我终于找到了一些来源:
https://github.com/Rob-- W/cors-anywhere/#documentation
^ 首选。如果你很少需要使用,我想你可以使用他的heroku应用程序。否则,它是在您自己的服务器上自行运行的代码。请注意限制是什么。
whateverorigin.org
^ 第二选择,但相当旧。据说Python中较新的选择: https://github.com/Eiledon/alloworigin
然后是第三个选择:
http://anyorigin.com/
这似乎允许一点免费使用,但会将您置于公开状态耻辱名单如果您没有支付并使用了一些未指定的金额,只有支付费用后才能将您从该金额中删除......
The only real answer, if you don't control the headers on your source you want in your iframe, is to proxy it. Have a server act as a client, receive the source, strip the problematic headers, add CORS if needed, and then ping your own server.
There is one other answer explaining how to write such a proxy. It isn't difficult, but I was sure someone had to have done this before. It was just difficult to find it, for some reason.
I finally did find some sources:
https://github.com/Rob--W/cors-anywhere/#documentation
^ preferred. If you need rare usage, I think you can just use his heroku app. Otherwise, it's code to run it yourself on your own server. Note sure what the limits are.
whateverorigin.org
^ second choice, but quite old. supposedly newer choice in python: https://github.com/Eiledon/alloworigin
then there's the third choice:
http://anyorigin.com/
Which seems to allow a little free usage, but will put you on a public shame list if you don't pay and use some unspecified amount, which you can only be removed from if you pay the fee...
唯一有一堆答案的问题。欢迎来到我希望在截止日期晚上 10:30 工作时我希望能看到的指南……FB 使用画布应用程序做了一些奇怪的事情,好吧,你已经被警告了。如果您还在这里并且您有一个将出现在 Facebook Canvas 后面的 Rails 应用程序,那么您将需要:
Gemfile:
config/facebook.yml
config/ application.rb
config/initializers/omniauth.rb
application_controller.rb
您需要一个控制器来从 Facebook 的画布设置进行调用,我使用了
/canvas/
并使路由成为此应用程序的主要SiteController
:login.html.erb
Sources
您没有将此标头放入应用程序控制器中。
The only question that has a bunch of answers. WElcome to the guide i wish i had when i was scrambling for this to make it work at 10:30 at night on the deadline day... FB does some weird things with canvas apps, and well, you've been warned. If youa re still here and you have a Rails app that will appear behind a Facebook Canvas, then you will need:
Gemfile:
config/facebook.yml
config/application.rb
config/initializers/omniauth.rb
application_controller.rb
You need a controller to call from Facebook's canvas settings, i used
/canvas/
and made the route go the mainSiteController
for this app:login.html.erb
Sources
you don't put this header in the app controller.
使用 Kevin Vella 的想法,我尝试在 PayPal 按钮生成器制作的表单元素上使用上述内容。为我工作,这样 Paypal 就不会在新的浏览器窗口/选项卡中打开。
更新
以下是一个示例:
从今天(2021 年 1 月 19 日)生成按钮后,PayPal 会自动在
表单
target="_top" > 元素,但如果这不适用于您的上下文,请尝试不同的target
值。我建议_parent
—— 至少在我使用这个 PayPal 按钮时是有效的。有关详细信息,请参阅表单目标值。
Using Kevin Vella's idea, I tried using the above on the form element made by PayPal's button generator. Worked for me so that Paypal does not open in a new browser window/tab.
Update
Here's an example:
Generating a button as of today (01-19-2021), PayPal automatically includes
target="_top"
on theform
element, but if that doesn't work for your context, try a differenttarget
value. I suggest_parent
-- at least that worked when I was using this PayPal button.See Form Target Values for more info.
网站所有者使用
X-Frame-Options
响应标头,以便无法在 Iframe 中打开其网站。这有助于保护用户免受点击劫持攻击您可以采用以下几种方法如果您想在自己的计算机上禁用 X-Frame-Options,请尝试。
服务器端配置
如果您拥有服务器或可以与站点所有者合作,那么您可以要求设置一个配置,以便根据某些条件不发送 Iframe buster 响应标头。条件可以是附加请求标头或 URL 中的参数。
例如 - 网站所有者可以添加额外的代码,以便在使用
?in_debug_mode=true
查询参数打开网站时不发送 Iframe buster 标头。使用像 Requestly 这样的浏览器扩展来删除响应标头
您可以使用任何浏览器扩展,例如 Requestly,它允许您修改请求和响应头。响应标头。这是一个 Requestly 博客,解释了如何通过绕过 Iframe buster 标头将网站嵌入到 Iframe。
配置直通代理并从中删除标头
如果您需要为多个人绕过 Iframe buster 标头,那么您还可以配置一个直通代理,仅删除 Frame buster 响应标头并返回返回响应。然而,这编写和设置起来非常复杂。通过代理在 Iframe 中打开的网站还存在一些其他挑战,例如身份验证等,但这种方法可以很好地适用于简单的网站。
PS - 我已经构建了这两种解决方案,并且对这两种解决方案都有第一手经验。
Site owners use the
X-Frame-Options
response header so that their website cannot be opened in an Iframe. This helps to secure the users against clickjacking attackThere are a couple of approaches that you can try if you want to disable X-Frame-Options on your own machine.
Configuration at Server-Side
If you own the server or can work with the site owner then you can ask to set up a configuration to not send the Iframe buster response headers based on certain conditions. Conditions could be an additional request header or a parameter in the URL.
For example - The site owner can add an additional code to not send Iframe buster headers when the site is opened with
?in_debug_mode=true
query param.Use Browser extension like Requestly to remove response headers
You can use any browser extension like Requestly which allows you to modify the request & response headers. Here's a Requestly blog that explains how to embed sites in Iframe by bypassing Iframe buster headers.
Configure a Pass-through Proxy and remove headers from it
If you need to bypass Iframe buster headers for multiple folks, then you can also configure a pass-through proxy that just removes the frame buster response headers and return back the response. This is however a lot complicated to write, set up. There are some other challenges like authentication etc with the sites opened in Iframe through a proxy but this approach can work for simple sites pretty well.
PS - I have built both solutions and have first-hand experience with both.
我不确定它有多相关,但我为此构建了一个解决方法。在我的网站上,我想在包含加载 URL 的 iframe 的模式窗口中显示链接。
我所做的是,我将链接的点击事件链接到这个 javascript 函数。所有这一切都是向 PHP 文件发出请求,该文件在决定是否在模式窗口中加载 URL 或重定向之前检查 URL 标头中的 X-FRAME-Options。
这是该函数:
这是检查它的 PHP 文件代码:
希望这会有所帮助。
I'm not sure how relevant it is, but I built a work-around to this. On my site, I wanted to display link in a modal window that contained an iframe which loads the URL.
What I did is, I linked the click event of the link to this javascript function. All this does is make a request to a PHP file that checks the URL headers for X-FRAME-Options before deciding whether to load the URL within the modal window or to redirect.
Here's the function:
Here's the PHP file code that checks for it:
Hope this helps.
我在运行 WordPress 网站时遇到了这个问题。我尝试了各种方法来修复它,但不确定如何解决,最终问题是因为我使用带屏蔽的 DNS 转发,并且没有正确处理到外部站点的链接。即我的网站托管在 http://123.456.789/index.html 但被屏蔽以运行http://somewebSite.com/index.html。当我在浏览器中输入 http://123.456.789/index.html 时,单击这些相同的链接会导致JS 控制台中没有 X-frame-origins 问题,但运行 http://somewebSite.com/index.html 做到了。为了正确屏蔽,您必须将主机的 DNS 名称服务器添加到域服务中,即 godaddy.com 应该具有名称服务器,例如 ns1.digitalocean.com、ns2.digitalocean.com、ns3.digitalocean.com(如果您是)使用 digitalocean.com 作为您的托管服务。
I came across this issue when running a wordpress web site. I tried all sorts of things to fix it and wasn't sure how, ultimately the issue was because I was using DNS forwarding with masking, and the links to external sites were not being addressed properly. i.e. my site was hosted at http://123.456.789/index.html but was masked to run at http://somewebSite.com/index.html. When i entered http://123.456.789/index.html in the browser clicking on those same links resulted in no X-frame-origins issues in the JS console, but running http://somewebSite.com/index.html did. In order to properly mask you must add your host's DNS name servers to your domain service, i.e. godaddy.com should have name servers of example, ns1.digitalocean.com, ns2.digitalocean.com, ns3.digitalocean.com, if you were using digitalocean.com as your hosting service.
令人惊讶的是,这里没有人提到
Apache
服务器的设置(*.conf
文件)或.htaccess
文件本身是导致此问题的原因错误。搜索.htaccess
或Apache
配置文件,确保您没有将以下内容设置为DENY
:始终标头设置 X-Frame-Options DENY
将其更改为
SAMEORIGIN
,使事情按预期工作:标头始终设置 X-Frame-Options SAMEORIGIN
It's surprising that no one here has ever mentioned
Apache
server's settings (*.conf
files) or.htaccess
file itself as being a cause of this error. Search through your.htaccess
orApache
configuration files, making sure that you don't have the following set toDENY
:Header always set X-Frame-Options DENY
Changing it to
SAMEORIGIN
, makes things work as expected:Header always set X-Frame-Options SAMEORIGIN
我遇到了这个问题,并通过编辑 httd.conf 解决了它,
我将 SAMEORIGIN 更改为 GOFORIT
并重新启动服务器
i had this problem, and resolved it editing httd.conf
i changed SAMEORIGIN to GOFORIT
and restarted server
如果要从整个目录中删除 X-Frame-Options,请编辑 .htaccess。
并添加行: 标头始终取消设置 X-Frame-Options
[内容来自: 克服“X-Frame-Options禁止显示”
Edit .htaccess if you want to remove X-Frame-Options from an entire directory.
And add the line: Header always unset X-Frame-Options
[contents from: Overcoming "Display forbidden by X-Frame-Options"
使用下面给出的这一行代替
header()
函数。Use this line given below instead of
header()
function.试试这个东西,我认为没有人在主题中建议这个,这将解决你问题的 70%,对于其他一些页面,你必须废弃,我有完整的解决方案,但不适合公众,
请在下面添加到你的 iframe
沙箱="允许相同来源允许脚本允许弹出窗口允许表单"
Try this thing, i dont think anyone suggested this in the Topic, this will resolve like 70% of your issue, for some other pages, you have to scrap, i have the full solution but not for public,
ADD below to your iframe
sandbox="allow-same-origin allow-scripts allow-popups allow-forms"