首页 > 解决方案 > 子域上 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 之外运行。

标签: javascriptgoogle-chromerecaptchax-frame-options

解决方案


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.


推荐阅读