reCAPTCHA 的 CORS

Ven*_*ius 1 google-chrome cross-domain recaptcha cors

我正在开发一个网站,希望在其中包含 Google 的 reCAPTCHA。

如果我将以下<script>标签添加到我的<head>

<script crossorigin="anonymous" src='https://www.google.com/recaptcha/api.js'> </script>

我收到以下错误:

Access to Script at 'https://www.google.com/recaptcha/api.js' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access.

好吧,好吧,够公平的。在 localhost 上工作时,我始终可以在 Chrome 上禁用 CORS。但域名是 www.google.com。我不太愿意将 access-control-allow-origin 标头发送到 google 根域上的任何内容 - 这感觉就像是一个可以让公交车通过的安全漏洞。

如何通过合理的生产设置来解决此问题,以处理此处的跨源问题?

Que*_*tin 5

消除crossorigin="anonymous"

您的页面只需要运行脚本。它不需要请求提升权限,因此您的 JS 可以访问更多有关它的信息。如果它抛出错误,那么您将无法访问 Google 的服务器来纠正它。