【问题标题】:Create a whitelist of sites that can iFrame mysite.com创建可以 iFrame mysite.com 的站点白名单
【发布时间】:2013-12-20 12:31:42
【问题描述】:

我拥有一个网站,人们可以在其中创建内容并将其嵌入到他们的网站上。我们称之为“mysite.com”。

用户可以创建类似“mysite.com/1”的页面并将其嵌入到他们的网站“acceptable.com”中。如何防止“forbidden.com”等其他网站在 iframe 中显示“mysite.com/1”?

tl;dr 如何为尝试 iframe 我自己的网站的网站创建“白名单”?

【问题讨论】:

    标签: ruby-on-rails iframe


    【解决方案1】:

    一般来说,您可以在服务器响应中发送X-Frame-Options 标头,该响应提供以下选项:

    DENY
    The page cannot be displayed in a frame, regardless of the site attempting to do so.
    
    SAMEORIGIN
    The page can only be displayed in a frame on the same origin as the page itself.
    
    ALLOW-FROM uri
    The page can only be displayed in a frame on the specified origin.
    

    https://developer.mozilla.org/en-US/docs/HTTP/X-Frame-Options

    要在 Rails 中执行此操作,您可以为所有页​​面设置 (source)

    config.action_dispatch.default_headers.merge!({'X-Frame-Options' => '[OPTION HERE]'})

    或仅针对某些页面,请参阅How to override X-Frame-Options for a controller or action in Rails 4

    【讨论】:

      猜你喜欢
      • 2016-01-02
      • 2017-01-21
      • 1970-01-01
      • 1970-01-01
      • 2020-12-15
      • 2010-11-05
      • 1970-01-01
      • 1970-01-01
      • 2021-12-08
      相关资源
      最近更新 更多