sails.js - 在 Sails 处于生产模式时,Recaptcha POST 请求返回 Forbidden
问题描述
我的 Sails 应用程序有一个受 Google Recaptcha v2 保护的表单。我有一个具有不同域的开发应用程序和一个生产应用程序。两个域都在同一台服务器上,并具有共享的 https 证书。这两个域都在 Recaptcha 域列表中。
这是表单控制器:
var formdata = this.req.body;
const https = require('https');
const options = {
host: 'www.google.com',
path: '/recaptcha/api/siteverify',
port: 443,
method: 'POST',
body: {
secret: "wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww",
response: this.req.body['g-recaptcha-response'],
remoteid: this.req.connection.remoteAddress,
},
};
const req = await https.request(options, (res) => {
res.on('data', async function(d) {
var emailAddress = formdata.emailAddress.toLowerCase();
await Eoi.create({
name: formdata.name,
company: formdata.company,
emailAddress: emailAddress
})
});
});
req.on('error', (e) => {
console.error(e);
});
req.end();
throw {redirect: '/'};
当我在开发应用程序上提交表单时,它提交并验证正常,检查 csrf 并从 Google 返回 200 结果。但是生产应用程序(目前具有完全相同的代码)不起作用。相反,它显示:
https://example.com/eoi
在地址栏中和页面上的“禁止”。
我已将sails 日志级别更改为详细,它显示的唯一错误是:
Error: Could not parse session id from cookie of connecting socket, and then failed again when trying to use a generated cookie. Something has possibly gone wrong with your session store configuration.
我认为这与这个问题没有太大关系。在生产模式下,我可以看到这两个应用程序之间的唯一区别。
我在这里想念什么?
更新 2021-05-24: 我刚刚在生产模式下提升了我的开发应用程序并得到了同样的错误。因此,这肯定与 Sails 在开发与生产模式中的行为方式不同有关。
解决方案
推荐阅读
- eigen3 - eigen 可以支持不一致的输入输出类型吗?
- power-automate - 在 Microsoft Flow 中使用“获取用户配置文件 V2”操作时访问被拒绝 403 错误
- linux - 编写用户在会话期间执行的所有语句
- excel - 使用 getElementsByTagName() 进行网页抓取
- c# - 从身份服务器注销后如何将用户重定向到客户端应用程序?
- java - 如何拦截 org.apache.cxf.interceptor.Fault
- nosql - 在 nosql DB 中使用索引文档跟踪多个文档
- python - Python中的PLS-DA加载图
- docker - sh: ./bc2influx: 进入停止的容器时未找到
- unity3d - HoloLens - Unity:如何更改光标的颜色?