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.
    function (req, res, next) {
        var data = res.getViewData();
        if (data && data.csrfError) {
            return next();

For more information, see validateRequest and validateAjaxRequest in the JSDoc.