Securing Forms
Use the new CSRF (Cross-Site Request Forgery) framework to add fields that are protected from request forgery.
CSRF in SFRA is provided as middleware by B2C Commerce. CSRF checks are performed as the
middleware step csrfProtection.validateAjaxRequest.
Example: CSRF check is made for login information. This example is available in the
Account.js
controller.
server.post(
'Login',
server.middleware.https,
csrfProtection.validateAjaxRequest,
function (req, res, next) {
var data = res.getViewData();
if (data && data.csrfError) {
res.json();
return next();
}
For more information, see validateRequest
and
validateAjaxRequest
in the JSDoc.