简体   繁体   English

如何允许几个站点将我的应用加载到iframe中?

[英]How do i allow my app to be loaded in an iframe by a couple of sites?

I am developing a rails application that clients can embed on their sites using iframes. 我正在开发一个Rails应用程序,客户可以使用iframe将其嵌入到他们的网站中。 I am looking for a way to allow only my clients to embed the app. 我正在寻找一种只允许我的客户嵌入应用程序的方法。 I am familiar with the x-frame options, ie: 我熟悉x帧选项,即:

response.headers["X-Frame-Options"] = "ALLOW-FROM http://www.example.com"

(from X-Frame-Options ALLOW-FROM a specific site allows from all ) (从X-Frame-Options ALLOW-FROM允许特定站点从所有站点访问

Is there a way to allow a number of sites? 有没有办法允许多个站点?

ok, Octopus-Paul put me on the right track. 好吧,章鱼保罗让我走上了正轨。 I resolved this with the following code in application.rb: 我使用application.rb中的以下代码解决了此问题:

 config.action_dispatch.default_headers = {
   referer =  request.headers['Referer']
   site = 'http://www.example.com' 

   if (referer =~ Regexp.new "\\A#{site}")
    'X-Frame-Options' => 'ALLOWALL'
   else
    'X-Frame-Options' => 'SAMEORIGIN'
   end  
  }

now i just need to scan a list of allowed sites using this code, and i'm done, i guess. 现在,我只需要使用此代码来扫描允许的站点列表,我想我已经完成了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果我的应用程序正在由iframe加载-我可以检测到它吗? - If my app is being loaded by iframe - can I detect it? 如何为我的 Rails 应用程序构建 API,以便多个站点可以共享一个数据库? - How do I build an API for my Rails app, so that multiple sites can share one database? 如何安全,低成本地允许我的网站上的图像? - How do I allow safely and inexpensively allow images on my site? 如何允许从应用程序中的两个不同位置登录? - How do I allow logging in from two different locations in my app? 从高层次来看,我如何允许未登录用户在我的应用程序中执行某些操作 - Rails 3 - From a high-level, how do I allow non-logged in users to do certain things in my app - Rails 3 如何在我的项目中指定样式表被编译/加载? - How do I specify the stylesheets in my project are compiled/loaded? 如何使我的Rails应用程序/代码库可自定义以将其部署到其他站点 - How can I make my Rails app / codebase customisable to deploy it as different sites 如何让facebook页面管理员只选择他们希望我的应用管理的特定页面(manage_pages) - How do I allow a facebook page admin to select only the specific pages they want my app to manage(manage_pages) 为什么我需要在 EC2 安全组中允许“所有 TCP”才能访问我的应用程序? - Why do I need to allow `All TCP` in my EC2 security group for me to access my app? 如何在Rails 4应用程序的iframe中运行本地HTML文件 - How do run a local HTML file in an iframe within my rails 4 app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM