【发布时间】:2021-08-06 06:10:20
【问题描述】:
我正在尝试允许其他人在许多网站上嵌入我的 rails 应用程序中的页面。我可以使用 X-Frame-Options 让它在 Chrome 和 Firefox 中工作。是否有等效的内容安全策略
response.headers['X-Frame-Options'] = "ALLOW-FROM *"
这是使用 X-Frame-Options 的位
class PeopleController < ApplicationController
def embed
response.headers['X-Frame-Options'] = "ALLOW-FROM *"
@company = People.new
end
end
但在我使用内容安全策略时在 Chrome 和 Google 中使用内容安全策略时不起作用
class PeopleController < ApplicationController
content_security_policy do |p|
p.frame_ancestors "self", "*"
end
def embed
@company = People.new
end
end
使用内容安全策略时,会抛出此错误:
Refused to frame 'http://localhost:3000/' because an ancestor violates the following Content Security Policy directive: "frame-ancestors self".
这是嵌入代码的示例:
<iframe src="http://localhost:3000/people/embed"></iframe>
这是我尝试的另一个:
<iframe src="/people/embed"></iframe>
更新
使用内容安全策略,这仅适用于 Firefox:
content_security_policy do |p|
p.frame_ancestors 'self', "*"
end
【问题讨论】:
标签: ruby-on-rails google-chrome iframe content-security-policy x-frame-options