Skip to content

Cannot instantiate interface Magento\Csp\Model\Collector\MergerInterface when Magento_Csp is disabled #39104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
1 of 5 tasks
fritzmg opened this issue Aug 23, 2024 · 20 comments
Labels
Area: Content Component: Csp Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: ready for grooming Reported on 2.4.7-p2 Indicates original Magento version for the Issue report. Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch

Comments

@fritzmg
Copy link

fritzmg commented Aug 23, 2024

Preconditions and environment

  • Magento version: 2.4.7-p2
  • Magento_Csp disabled

Steps to reproduce

  1. Update or install Magento 2.4.7-p2.
  2. Execute bin/magento module:disable Magento_Csp.
  3. Go to the checkout.

Expected result

The checkout should be rendered.

Actual result

The following error is thrown:

Error: Cannot instantiate interface Magento\Csp\Model\Collector\MergerInterface in vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php:50
Stack trace:
#0 vendor/magento/framework/ObjectManager/ObjectManager.php(73): Magento\Framework\ObjectManager\Factory\Dynamic\Developer->create()
#1 vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php(170): Magento\Framework\ObjectManager\ObjectManager->get()
#2 vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php(276): Magento\Framework\ObjectManager\Factory\AbstractFactory->resolveArgument()
#3 vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php(239): Magento\Framework\ObjectManager\Factory\AbstractFactory->getResolvedArgument()
#4 vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php(34): Magento\Framework\ObjectManager\Factory\AbstractFactory->resolveArgumentsInRuntime()
#5 vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php(59): Magento\Framework\ObjectManager\Factory\Dynamic\Developer->_resolveArguments()
#6 vendor/magento/framework/ObjectManager/ObjectManager.php(73): Magento\Framework\ObjectManager\Factory\Dynamic\Developer->create()
#7 vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php(170): Magento\Framework\ObjectManager\ObjectManager->get()
#8 vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php(276): Magento\Framework\ObjectManager\Factory\AbstractFactory->resolveArgument()
#9 vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php(239): Magento\Framework\ObjectManager\Factory\AbstractFactory->getResolvedArgument()
#10 vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php(34): Magento\Framework\ObjectManager\Factory\AbstractFactory->resolveArgumentsInRuntime()
#11 vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php(59): Magento\Framework\ObjectManager\Factory\Dynamic\Developer->_resolveArguments()
#12 vendor/magento/framework/ObjectManager/ObjectManager.php(73): Magento\Framework\ObjectManager\Factory\Dynamic\Developer->create()
#13 vendor/magento/module-payment-services-paypal/Model/ConfigProvider.php(65): Magento\Framework\ObjectManager\ObjectManager->get()
…

Additional information

The cause are these lines within vendor/magento/module-payment-services-paypal/Model/ConfigProvider.php

    //TODO:Just to be compatible with 2.4.6. Remove in future
    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    try {
        $this->cspNonceProvider = $objectManager->get("\Magento\Csp\Helper\CspNonceProvider");
    } catch (\ReflectionException $e) {
        $this->cspNonceProvider = null;
    }

The error is not of type \ReflectionException, instead it is of type \Error - thus the error is not caught.

To fix it, it could be changed as follows:

    //TODO:Just to be compatible with 2.4.6. Remove in future
    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    try {
        $this->cspNonceProvider = $objectManager->get("\Magento\Csp\Helper\CspNonceProvider");
-   } catch (\ReflectionException $e) {
+   } catch (\Throwable) {
        $this->cspNonceProvider = null;
    }

Release note

No response

Triage and priority

  • Severity: S0 - Affects critical data or functionality and leaves users without workaround.
  • Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
  • Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
  • Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
  • Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.
Copy link

m2-assistant bot commented Aug 23, 2024

Hi @fritzmg. Thank you for your report.
To speed up processing of this issue, make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:


Join Magento Community Engineering Slack and ask your questions in #github channel.
⚠️ According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.
🕙 You can find the schedule on the Magento Community Calendar page.
📞 The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, join the Community Contributions Triage session to discuss the appropriate ticket.

@Franciscof-Serfe
Copy link
Contributor

Hi @fritzmg ,
I think that this could be related to this security improvement:
https://experienceleague.adobe.com/en/docs/commerce-operations/release/notes/magento-open-source/2-4-7#:~:text=Changes%20to%20Content%20Security%20Policy

Magento updated CSP to restrict mode at checkout.
You can use this module to bypass it meanwhile you fix the code to enable CSP.

https://github.com/yireo/Yireo_DisableCsp

@fritzmg
Copy link
Author

fritzmg commented Aug 23, 2024

Well Magento has support for CSP for some while now, not just recently. The issue is just with the Magento_PaymentServicesPaypal module that comes with Magento Community Edition. It currently has an erroneous hard dependency on Magento_Csp. Judging by the code it is supposed to be a soft dependency, but it currently does not work (due to the wrong catch type).

@engcom-Bravo engcom-Bravo added the Reported on 2.4.7-p2 Indicates original Magento version for the Issue report. label Aug 26, 2024
@github-project-automation github-project-automation bot moved this to Ready for Confirmation in Issue Confirmation and Triage Board Aug 26, 2024
@MarcusSchwarz
Copy link

I can confirm the issue with 2.4.6-p7 as well.

File affected: vendor/magento/module-paypal/Model/Config.php
Workaround:

             }
         }

-        $this->cspNonceProvider = $cspNonceProvider ?: ObjectManager::getInstance()->get(CspNonceProvider::class);
+        try {
+            $this->cspNonceProvider = $cspNonceProvider ?: ObjectManager::getInstance()->get(CspNonceProvider::class);
+        } catch (\Throwable $e) {
+            $this->cspNonceProvider = null;
+        }
     }

     /**

The checkout is also affected. A new Observer has been introduced: Magento\Checkout\Observer\CspPolicyObserver

File affected: vendor/magento/module-checkout/etc/frontend/events.xml
Workaround:

     <event name="customer_logout">
         <observer name="unsetAll" instance="Magento\Checkout\Observer\UnsetAllObserver" />
     </event>
-    <event name="controller_action_predispatch_checkout_index_index">
-        <observer name="cps_storefront_checkout_index_index_predispatch"
-                  instance="Magento\Checkout\Observer\CspPolicyObserver"/>
-    </event>
+<!--    <event name="controller_action_predispatch_checkout_index_index">-->
+<!--        <observer name="cps_storefront_checkout_index_index_predispatch"-->
+<!--                  instance="Magento\Checkout\Observer\CspPolicyObserver"/>-->
+<!--    </event>-->
 </config>

@Franciscof-Serfe
Copy link
Contributor

Marcus,
As I mentioned in my previous note, after M2.4.7 Adobe decided to force CSP in restricted mode for the checkout and payment line. It's not an error.

Default config:
https://developer.adobe.com/commerce/php/development/security/content-security-policies/#default-configuration

Commit REF: 25cf7f0#diff-32ed90c0e573d5dd4047b67db44768fca797fa1df717c8d883956d3a6b8d2fd6

I understand that someone from the Adobe team should clarify this.
@nathanjosiah can you add your 2 cents?

Previous discussion on Magento_Csp behavior change at checkout: #38823

Background info: https://m.academy/articles/magento-apsb24-40-security-patch-csp-checkout-updates/#:~:text=Impact%20on%20Checkout%20Functionality

@MarcusSchwarz
Copy link

@Franciscof-Serfe please note, we are not on 2.4.7. We are on 2.4.6-p7; In a security release there should never be such a breaking change.

@fritzmg
Copy link
Author

fritzmg commented Aug 27, 2024

Adobe decided to force CSP in restricted mode for the checkout and payment line. It's not an error.

Nevertheless, modules that have a hard dependency on Magento_Csp need to define it as such. Currently Magento_PaymentServicesPaypal has no dependency and thus Magento_Csp can be disabled, which leads to the aforementioned error.

@nathanjosiah
Copy link
Contributor

The new CSP changes are new PCI requirements for all payment pages per PCI version 4 section 6.4.3. Since all of our supported versions must be PCI compliant this change had to be made.

Having said that, it does appear there is an error with the type that violates our policies. But, I would strongly advise you to get your site working with CSP as this is the last line of defense against malware and card skimmers. Plus, it would put you at risk of PCI audit failure especially since the auditors will be on high alert since it's a new requirement.

@nathanjosiah
Copy link
Contributor

@magento export issue to Jira project AC as Bug

@github-jira-sync-bot
Copy link

❌ You don't have permission to export this issue.

@sidolov
Copy link
Contributor

sidolov commented Aug 27, 2024

@magento export issue to Jira project AC as Bug

@github-jira-sync-bot
Copy link

❌ Something went wrong. Cannot create Jira issue.

@Franciscof-Serfe
Copy link
Contributor

Is the Issue: Confirmed tab necessary first?

@fritzmg
Copy link
Author

fritzmg commented Aug 28, 2024

But, I would strongly advise you to get your site working with CSP as this is the last line of defense against malware and card skimmers. Plus, it would put you at risk of PCI audit failure especially since the auditors will be on high alert since it's a new requirement.

@nathanjosiah While I agree that CPS should be enabled in any case, CSP must not be a requirement, at least not for this reason. Your shop does not have to have an actual payment module. In our case the Magento instance is a B2C shop with a checkout that contains no payment options. In our case the fix is easy, as we can just disable the payment module itself (it was an error that we didn't).

The error is that Magento_PaymentServicesPaypal is missing the Magento_Csp dependency in its composer.json and etc/module.xml.

@engcom-Bravo engcom-Bravo added Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Component: Csp Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Area: Content labels Sep 20, 2024
@engcom-Bravo engcom-Bravo moved this from Ready for Confirmation to Confirmed in Issue Confirmation and Triage Board Sep 20, 2024
@github-jira-sync-bot
Copy link

✅ Jira issue https://jira.corp.adobe.com/browse/AC-13063 is successfully created for this GitHub issue.

Copy link

m2-assistant bot commented Sep 20, 2024

✅ Confirmed by @engcom-Bravo. Thank you for verifying the issue.
Issue Available: @engcom-Bravo, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

@nathanjosiah
Copy link
Contributor

We are working on this internally.

As a reference for any Adobe members, this was transferred from AC-13063 to PAY-5690

@fritzmg
Copy link
Author

fritzmg commented Oct 22, 2024

The same error happens within Magento\AdminAnalytics\ViewModel\Metadata:

$this->nonceProvider = $nonceProvider ?: ObjectManager::getInstance()->get(CspNonceProvider::class);
$this->nonce = $this->nonceProvider->generateNonce();

It also has a hard dependency on Magento_Csp, but it is missing from the module.xml:

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Magento_AdminAnalytics"/>
</config>

@amine-y
Copy link
Member

amine-y commented Dec 30, 2024

I have the same problem here on 2.4.6-p8. It is supposed to be just a security patch, but now we have a CSP problem.

@usuyukiso
Copy link

Also reproduced for 2.4.8-p1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Content Component: Csp Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: ready for grooming Reported on 2.4.7-p2 Indicates original Magento version for the Issue report. Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch
Projects
None yet
Development

No branches or pull requests

9 participants