1

can you please suggest me I have transferred my site from one server to another, all Magento functionality works except add to cart.

And checkout cart add controller return 500 error

I am getting below error in debug.log

Request validation failed for action "Magento\Framework\App\Action\Forward\Interceptor" {"exception":"[object] (Magento\Framework\App\Request\InvalidRequestException(code: 0): Invalid request received at /home/simplecity/public_html/vendor/magento/framework/App/Request/CsrfValidator.php:105)"} []

4
  • Please add the error you're getting, check error and systemlog. Check in the network and console tab on dev console ito check if you're getting any error there. Commented Jun 16, 2020 at 11:09
  • yes @VivekKumar error addedd Commented Jun 16, 2020 at 11:39
  • can you add url here where you get this error and menu.xml file for the same ? Commented Jun 16, 2020 at 15:41
  • This error is in debug.log not in any console or network error Commented Jun 16, 2020 at 19:40

1 Answer 1

1

I Ignored Validation use plugin as below :

Module_Name/etc/di.xml add:

<type name="Magento\Framework\App\Request\CsrfValidator">
    <plugin name="csrf_validator_skip" type="Module\Name\Plugin\CsrfValidatorSkip" />
</type>

Module_Name/Plugin/CsrfValidatorSkip.php

namespace Module\Name\Plugin;

class CsrfValidatorSkip
{
    /**
     * @param \Magento\Framework\App\Request\CsrfValidator $subject
     * @param \Closure $proceed
     * @param \Magento\Framework\App\RequestInterface $request
     * @param \Magento\Framework\App\ActionInterface $action
     */
    public function aroundValidate(
        $subject,
        \Closure $proceed,
        $request,
        $action
    ) {
        /* Magento 2.1.x, 2.2.x */
        if ($request->getModuleName() == 'name') {
            return; // Skip CSRF check
        }
        $proceed($request, $action); // Proceed Magento 2 core functionalities
    }
}

My Error was as below:

main.DEBUG: Request validation failed for action "Module\Name\Controller\HtmlRedirect\Response\Interceptor" {"exception":"[object] (Magento\Framework\App\Request\InvalidRequestException(code: 0): Invalid request received at MagentoRoot/vendor/magento/framework/App/Request/CsrfValidator.php:105)"} []

1
  • 1
    thanks it's solved my issue
    – mrfizh
    Commented Jun 9, 2021 at 18:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.