Web CSRF实现和条带API
以下是CSRF令牌验证的安全实现吗?具体而言,我想调用此条带API端点:Web CSRF实现和条带API,web,stripe-payments,csrf,Web,Stripe Payments,Csrf,以下是CSRF令牌验证的安全实现吗?具体而言,我想调用此条带API端点: https://connect.stripe.com/express/oauth/authorize?redirect_uri=https://example.com&client_id=ca_11111&state={STATE_VALUE} 医生说 要防止CSRF攻击,请添加状态参数,并将唯一令牌作为值传递。我们将包括您在将用户重定向回您的站点时提供的状态 我正在考虑这样实施: -浏览器生成随机令牌并将其存储在cook
https://connect.stripe.com/express/oauth/authorize?redirect_uri=https://example.com&client_id=ca_11111&state={STATE_VALUE}
医生说
要防止CSRF攻击,请添加状态参数,并将唯一令牌作为值传递。我们将包括您在将用户重定向回您的站点时提供的状态
我正在考虑这样实施:
-浏览器生成随机令牌并将其存储在cookie(或本地存储器)中
-浏览器调用上述端点
-条带重定向到位于https://example.com
-当我得到响应时,我检查state
参数的内容,并将其与本地存储器或cookie中存储的值进行比较
这是CSRF的安全/正确实施吗?或者我是否需要某种方式涉及后端服务
(Stripe docs here:)注意,在Stripe自己在NodeJS中编写的Rocket Ride示例中,状态只是作为随机字符串在服务器上计算出来,并添加到用户会话中。当Stripe在redirect_uri处响应时,它们只是将用户会话的状态与响应中包含的状态进行比较。以下两段代码片段取自以下内容: 支票呢-
/**
* GET /pilots/stripe/token
*
* Connect the new Stripe account to the platform account.
*/
router.get('/token', pilotRequired, async (req, res, next) => {
// Check the `state` we got back equals the one we generated before proceeding (to protect from CSRF)
if (req.session.state != req.query.state) {
return res.redirect('/pilots/signup');
}
// more stuff below
});
/**
* GET /pilots/stripe/token
*
* Connect the new Stripe account to the platform account.
*/
router.get('/token', pilotRequired, async (req, res, next) => {
// Check the `state` we got back equals the one we generated before proceeding (to protect from CSRF)
if (req.session.state != req.query.state) {
return res.redirect('/pilots/signup');
}
// more stuff below
});