hCaptcha with Nodejs and React not working(csp)

1tuwyuhd  于 2023-06-22  发布在  Node.js
关注(0)|答案(1)|浏览(144)

我有nodejs,helmet作为后端,react使用前端的“@hcaptcha/react-hcaptcha”库
nodejs:

app.use(helmet());
app.use(helmet.contentSecurityPolicy({
    directives: {
        ...helmet.contentSecurityPolicy.getDefaultDirectives(),
        "script-src": [
            "'self'",
            "https://*.hcaptcha.com"
        ],
        "frame-src": [
            "'self'",
            "https://*.hcaptcha.com"
        ],
        "style-src": [
            "'self'",
            "https://*.hcaptcha.com",
            "'unsafe-inline'"
        ],
        "connect-src": [
            "'self'",
            "https://*.hcaptcha.com"
        ],
    },
}));

React:

import HCaptcha from "@hcaptcha/react-hcaptcha";

export default function Captcha({ onVerify }) {
  return (
    <HCaptcha
      sitekey="10000000-ffff-ffff-ffff-000000000001"
      theme="dark"
      onVerify={onVerify}
    />
  );
}

但是,不会显示验证码
我在chrome VM15:161 crbug/1173575, non-JS module files deprecated.中收到此警告
和火狐This error page has no error code in its security info
screenshot of actual captcha

pbwdgjma

pbwdgjma1#

我尝试复制你的错误,唯一的方法是通过端口3001而不是3000加载localhost(节点与React端口)我使用了你的代码的1:1副本,它产生了一个测试验证码:

当您尝试不同的端口时,或未指定端口时,会发生错误:

相关问题