javascript - 子域上 iframe 中的 chrome recaptcha allowall
问题描述
我正在使用谷歌的 reCaptcha,它在子域中运行良好,但是当我尝试使用 iframe 在主站点中显示该子域的页面时,api.js 和 webworker.js 最终使用 SAMEORIGIN 并导致 chrome 不显示文件。子域在 x-frame-options 上显示为 ALLOWALL,但是这两个返回 SAMEORIGIN,导致 chrome 恼火并将其放回 Deny。
我能够将 api.js 文件复制到子域站点中,这会导致该文件的 x-frame-options 为 ALLOWALL,但 reCaptcha 代码最终会加载从谷歌加载的 webworker.js,而我不能改变这一点。我什至不确定它在哪里加载,因为它不在 api.js 文件中。
除了将子域代码完全移动到主站点之外,还有什么建议吗?我将无法将 recaptcha 移动到主站点,因为它会在 iframe 之外运行。
解决方案
Chrome and other browsers don't really support anything but DENY and SAMEORIGIN. The solution is to set Content-Security-Policy with the frame-ancestors directive set to all the (sub)domains that should be allowed to frame. This would typically be either "'self' subdomain.example.com" or simply "*.example.com". IE won't understand it and consequently ignore it, the other browsers that understand it will now ignore X-Frame-Options.
推荐阅读
- java - 访问地址时出现服务器错误,但没有堆栈跟踪
- java - 动态设置子网格的寻呼机
- c# - 如何在 WHERE 子句中使用多个可选 AND 条件格式化查询
- jquery - 通过 jQuery EACH 循环添加多个 WooCommerce 产品
- php - 我如何在 PHP 中使用动态变量
- node.js - Mongodb:仅FindOne那些与mongodb中的条件匹配的数组对象
- angular - 如何修复angular2-signaturePad中的“无法读取未定义的属性'toDataURL'”
- django - modelchoicefield 显示没有名称的对象 1 和对象 2 的问题?
- python - 如何使多线程我的树莓派之间的通信代码?
- php - wordpress 帖子无法在自定义模板上检索