相关疑难解决方法(0)

克服"X-Frame-Options禁止显示"

我正在写一个小网页,其目的是构建其他一些页面,只需将它们合并到一个浏览器窗口中以便于查看.我试图框架的一些页面禁止被框架并抛出"拒绝显示文档,因为X-Frame-Options禁止显示".Chrome中的错误.我知道这是一个安全限制(有充分理由),并且无权更改它.

是否有任何替代框架或非框架方法在单个窗口中显示不会被X-Frame-Options标头绊倒的页面?

iframe frames x-frame-options

412
推荐指数
12
解决办法
64万
查看次数

Safari 13+ iframe 阻止 CORS cookie

Safari 完全不允许您在与父域不同的域的 iframe 中设置 cookie,该死的服务器端 CORS 标头。

澄清一下:用户在 domainA.com 上。domainB.com 的 iframe 已打开,并尝试在 iframe 内对 domainB.com 上的用户进行身份验证。Set-Cookie 标头从 domainB.com iframe 内的服务器返回,带有所有必需的标头,但 Safari 不会在后续调用中将其发回。

一个旧的解决方法是从 iframe 提交表单,并在响应中设置 cookie。我猜他们喜欢用户点击某些东西来提交表单的事实。您必须轮询 cookie 以查看响应何时返回,因为表单提交没有回调,而在 HttpOnly cookie 的情况下,您不能,但是,嘿,它起作用了!直到没有。

然后,最近的解决方法是将用户重定向到全新窗口/选项卡中的 iframe 域,在那里设置一个随机 cookie,从那一刻起,该子域在 iframe 中被“信任”。同样,它需要单击才能打开新窗口/选项卡,甚至还有新选项卡打开的视觉指示。多安全,这样的标准。

现在,从 Safari 13 开始 - 没有更多的解决方法。没有更安全的 iframe cookie 设置

任何其他身份验证方案都不适合我们(例如 Auth-X 标头)。我们需要使用 HttpOnly 安全 cookie,因为我们不希望 javascript 客户端以任何方式访问该令牌。

需要明确的是,一切都在任何其他浏览器上运行良好。

相关的 WebKit Bugzilla

有没有人有什么建议?

编辑:

感谢@tomschmidt 的链接,这似乎是正确的方向。我尝试使用 Apple 的 Storage Access API,但不幸的是,虽然我确保在使用 API 初始化我的登录逻辑之前请求访问:

requestStorageAccess = async() => {
    return new Promise(resolve => { …
Run Code Online (Sandbox Code Playgroud)

javascript cookies safari iframe cors

22
推荐指数
1
解决办法
1万
查看次数

修复Rails oauth facebook x-frame-options sameorigin错误

我不能为我的生活让我的Facebook画布应用程序显示.Chrome控制台显示此错误,iframe中没有任何内容显示 - 它是空白的:

Refused to display 'http://mysite.dev/' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'.

我正在使用Rails 4.0.0.rc1omn​​iauth-facebook 1.4.1,以Facebook身份验证上Railscast作为指南.我没有使用任何Javascript代码,因为它是可选的,理想情况下应该只能在Facebook中访问应用程序.

的routes.rb

  match 'auth/:provider/callback', to: 'sessions#create', via: [:get, :post]
  match 'auth/failure', to: redirect('/'), via: [:get, :post]
  match 'signout', to: 'sessions#destroy', as: 'signout', via: [:get, :post]
Run Code Online (Sandbox Code Playgroud)

sessions_controller.rb

class SessionsController < ApplicationController

  def create
    user = User.from_omniauth(env["omniauth.auth"])
    session[:user_id] = user.id
    redirect_to root_url
  end

  def destroy
    session[:user_id] = nil
    redirect_to root_url
  end
Run Code Online (Sandbox Code Playgroud)

application_controller.rb

我不得不对此发表评论,因为我不断收到InvalidAuthenticityToken错误,这些错误让我失去了我一天的另一半.在这里再说一点.

  # …
Run Code Online (Sandbox Code Playgroud)

authentication facebook ruby-on-rails facebook-oauth

5
推荐指数
1
解决办法
5741
查看次数

Rails 6.允许任何其他域将特定页面嵌入到 iFrame 中

我希望允许任何人通过 iFrame 嵌入我的 Rails 网站。但我只想打开一些特定的路线,例如/emded/entity1/:entity1_id/emded/entity2/:entity2_id

例如,Youtube 就是这么做的。我可以嵌入以下代码:

<iframe width="420" height="315"src="https://www.youtube.com/embed/tgbNymZ7vqY">
</iframe>
Run Code Online (Sandbox Code Playgroud)

但如果我将src属性更改为 just https://www.youtube.com/,这个 iframe 将不会显示任何内容。

在 Rails 中做同样的事情的方法是什么?

我尝试遵循为 Rails 4 找到的指南:http ://jerodsanto.net/2013/12/rails-4-let-specific-actions-be-embedded-as-iframes/

我在应用程序控制器中创建了一个方法:

  def allow_iframe
    response.headers.delete "X-Frame-Options"
  end
Run Code Online (Sandbox Code Playgroud)

然后我将其添加到控制器中,并使用显示 iframe 内容(页面)的操作。after_action :allow_iframe,仅: :show_page_in_iframe

这是控制器操作本身:

  def show_page_in_iframe
    ...
    
    respond_to do |format|
      format.html { render layout: 'iframe' }
    end
  end
Run Code Online (Sandbox Code Playgroud)

然后我将这些更改部署到生产环境,将带有相应 URL 的 iframe 嵌入到“localhost”页面。

<iframe src="https://www.example.com/entity1/embed/66efdc3e-7cb7-436d-98e8-63275fa74ebd" height="500" width="100%" style="border:0"></iframe>
Run Code Online (Sandbox Code Playgroud)

但在 Chrome 控制台中我可以看到Refused to display 'https://www.example.com/' in a frame because it …

iframe ruby-on-rails x-frame-options ruby-on-rails-6

5
推荐指数
1
解决办法
2583
查看次数