magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.45k stars 9.29k forks source link

Admin user can call arbitrary Module class's constructor via Cart Price Rules #35135

Open oskar-olaussen opened 2 years ago

oskar-olaussen commented 2 years ago

Preconditions (*)

  1. Magento 2.4.3

Steps to reproduce (*)

  1. Create a new Cart Price Rule Screenshot from 2022-02-24 09-30-10

  2. Modify value of Conditions option value in browser's inspect. For example: Screenshot from 2022-02-24 09-09-23

  3. Select the option that you have modified.

Expected result (*)

  1. Validation error

Actual result (*)

  1. Inserted class is created and Magento tries to call methods on it. Have not found an actual exploit but this seems to be really bad practice at best. Screenshot from 2022-02-24 09-40-01

Please provide Severity assessment for the Issue as Reporter. This information will help during Confirmation and Issue triage processes.

m2-assistant[bot] commented 2 years ago

Hi @oskar-olaussen. Thank you for your report. To speed up processing of this issue, make sure that you provided the following information:

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:

@magento give me 2.4-develop instance - upcoming 2.4.x release

For more details, review the Magento Contributor Assistant documentation.

Add a comment to assign the issue: @magento I am working on this

To learn more about issue processing workflow, refer to the Code Contributions.


:clock10: You can find the schedule on the Magento Community Calendar page.

:telephone_receiver: 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.

:pencil2: Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel

m2-assistant[bot] commented 2 years ago

Hi @engcom-November. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

engcom-November commented 2 years ago

Verified the issue on Magento 2.4-develop branch On modifying option value of Conditions section in browser's inspect of Cart Price Rule, and selecting the same value in UI that has been modified, error is displayed and user is redirected to dashboard page. image

image

Exception stack trace: ` [2022-02-24T08:57:03.500455+00:00] main.ERROR: Class Magento\Quote\Model\CoponManagement does not exist [] [] [2022-02-24T08:57:03.501371+00:00] main.CRITICAL: ReflectionException: Class Magento\Quote\Model\CoponManagement does not exist in /var/www/html/mg24/magento2/lib/internal/Magento/Framework/Code/Reader/ClassReader.php:34 Stack trace:

0 /var/www/html/mg24/magento2/lib/internal/Magento/Framework/Code/Reader/ClassReader.php(34): ReflectionClass->__construct()

1 /var/www/html/mg24/magento2/lib/internal/Magento/Framework/ObjectManager/Definition/Runtime.php(54): Magento\Framework\Code\Reader\ClassReader->getConstructor()

2 /var/www/html/mg24/magento2/lib/internal/Magento/Framework/ObjectManager/Factory/Compiled.php(100): Magento\Framework\ObjectManager\Definition\Runtime->getParameters()

3 /var/www/html/mg24/magento2/lib/internal/Magento/Framework/ObjectManager/ObjectManager.php(56): Magento\Framework\ObjectManager\Factory\Compiled->create()

4 /var/www/html/mg24/magento2/app/code/Magento/SalesRule/Controller/Adminhtml/Promo/Quote/NewConditionHtml.php(30): Magento\Framework\ObjectManager\ObjectManager->create()

5 /var/www/html/mg24/magento2/lib/internal/Magento/Framework/Interception/Interceptor.php(58): Magento\SalesRule\Controller\Adminhtml\Promo\Quote\NewConditionHtml->execute()

6 /var/www/html/mg24/magento2/lib/internal/Magento/Framework/Interception/Interceptor.php(138): Magento\SalesRule\Controller\Adminhtml\Promo\Quote\NewConditionHtml\Interceptor->___callParent()

7 /var/www/html/mg24/magento2/lib/internal/Magento/Framework/Interception/Interceptor.php(153): Magento\SalesRule\Controller\Adminhtml\Promo\Quote\NewConditionHtml\Interceptor->Magento\Framework\Interception{closure}()

8 /var/www/html/mg24/magento2/generated/code/Magento/SalesRule/Controller/Adminhtml/Promo/Quote/NewConditionHtml/Interceptor.php(23): Magento\SalesRule\Controller\Adminhtml\Promo\Quote\NewConditionHtml\Interceptor->___callPlugins()

9 /var/www/html/mg24/magento2/lib/internal/Magento/Framework/App/Action/Action.php(111): Magento\SalesRule\Controller\Adminhtml\Promo\Quote\NewConditionHtml\Interceptor->execute()

10 /var/www/html/mg24/magento2/app/code/Magento/Backend/App/AbstractAction.php(151): Magento\Framework\App\Action\Action->dispatch()

11 /var/www/html/mg24/magento2/lib/internal/Magento/Framework/Interception/Interceptor.php(58): Magento\Backend\App\AbstractAction->dispatch()

12 /var/www/html/mg24/magento2/lib/internal/Magento/Framework/Interception/Interceptor.php(138): Magento\SalesRule\Controller\Adminhtml\Promo\Quote\NewConditionHtml\Interceptor->___callParent()

13 /var/www/html/mg24/magento2/app/code/Magento/Backend/App/Action/Plugin/Authentication.php(145): Magento\SalesRule\Controller\Adminhtml\Promo\Quote\NewConditionHtml\Interceptor->Magento\Framework\Interception{closure}()

14 /var/www/html/mg24/magento2/lib/internal/Magento/Framework/Interception/Interceptor.php(135): Magento\Backend\App\Action\Plugin\Authentication->aroundDispatch()

15 /var/www/html/mg24/magento2/lib/internal/Magento/Framework/Interception/Interceptor.php(153): Magento\SalesRule\Controller\Adminhtml\Promo\Quote\NewConditionHtml\Interceptor->Magento\Framework\Interception{closure}()

16 /var/www/html/mg24/magento2/generated/code/Magento/SalesRule/Controller/Adminhtml/Promo/Quote/NewConditionHtml/Interceptor.php(32): Magento\SalesRule\Controller\Adminhtml\Promo\Quote\NewConditionHtml\Interceptor->___callPlugins()

17 /var/www/html/mg24/magento2/lib/internal/Magento/Framework/App/FrontController.php(245): Magento\SalesRule\Controller\Adminhtml\Promo\Quote\NewConditionHtml\Interceptor->dispatch()

18 /var/www/html/mg24/magento2/lib/internal/Magento/Framework/App/FrontController.php(212): Magento\Framework\App\FrontController->getActionResponse()

19 /var/www/html/mg24/magento2/lib/internal/Magento/Framework/App/FrontController.php(147): Magento\Framework\App\FrontController->processRequest()

20 /var/www/html/mg24/magento2/lib/internal/Magento/Framework/Interception/Interceptor.php(58): Magento\Framework\App\FrontController->dispatch()

21 /var/www/html/mg24/magento2/lib/internal/Magento/Framework/Interception/Interceptor.php(138): Magento\Framework\App\FrontController\Interceptor->___callParent()

22 /var/www/html/mg24/magento2/lib/internal/Magento/Framework/Interception/Interceptor.php(153): Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception{closure}()

23 /var/www/html/mg24/magento2/generated/code/Magento/Framework/App/FrontController/Interceptor.php(23): Magento\Framework\App\FrontController\Interceptor->___callPlugins()

24 /var/www/html/mg24/magento2/lib/internal/Magento/Framework/App/Http.php(116): Magento\Framework\App\FrontController\Interceptor->dispatch()

25 /var/www/html/mg24/magento2/lib/internal/Magento/Framework/App/Bootstrap.php(264): Magento\Framework\App\Http->launch()

26 /var/www/html/mg24/magento2/pub/index.php(30): Magento\Framework\App\Bootstrap->run()

27 {main} {"report_id":"1c3786db3e0b891f7f12cd3a55831f0964f8f4721c03158dcb3493cb1e05eef7"} []

`

hostep commented 2 years ago

@nathanjosiah, just tagging you in here, sounds security related.

github-jira-sync-bot commented 2 years ago

:x: You don't have permission to export this issue.

nathanjosiah commented 2 years ago

@hostep I don't see an issue with this. When the rule model loads the post data there is a check that the requested class implements the ConditionInterface. The error in this report is due to a typo (Magento\Quote\Model\CoponManagement should be Magento\Quote\Model\CouponManagement) but even if it was correct, the class is loaded into memory but never instantiated because it doesn't implement that interface. In fact, it will throw a Class does not implement condition interface error which is simply logged and then completely ignored. Any class that implements that interface seems like it should be allowed in this context.

oskarolaussen commented 2 years ago

@nathanjosiah Thanks for the response! Not currently on my work computer but I'm fairly certain that by following the steps I provided the error logged was about the method setId not existing in the class provided, implying that the class was instantiated and then the method was called on it. The code uses the object manager directly so are you sure the flow goes through the factory referenced?

engcom-November commented 2 years ago

Verified the issue again on Magento 2.4-develop branch by correcting typo mistake. Please find the observations below: On modifying option value of Conditions section in browser's inspect of Cart Price Rule, and selecting the same value in UI that has been modified, error is displayed and user is redirected to dashboard page. image

image

` [2022-03-07T08:08:28.132405+00:00] main.CRITICAL: Error: Call to undefined method Magento\Quote\Model\CouponManagement::setId() in /var/www/html/mg24/magento2/app/code/Magento/SalesRule/Controller/Adminhtml/Promo/Quote/NewConditionHtml.php:31 Stack trace:

0 /var/www/html/mg24/magento2/lib/internal/Magento/Framework/Interception/Interceptor.php(58): Magento\SalesRule\Controller\Adminhtml\Promo\Quote\NewConditionHtml->execute()

1 /var/www/html/mg24/magento2/lib/internal/Magento/Framework/Interception/Interceptor.php(138): Magento\SalesRule\Controller\Adminhtml\Promo\Quote\NewConditionHtml\Interceptor->___callParent()

2 /var/www/html/mg24/magento2/lib/internal/Magento/Framework/Interception/Interceptor.php(153): Magento\SalesRule\Controller\Adminhtml\Promo\Quote\NewConditionHtml\Interceptor->Magento\Framework\Interception{closure}()

3 /var/www/html/mg24/magento2/generated/code/Magento/SalesRule/Controller/Adminhtml/Promo/Quote/NewConditionHtml/Interceptor.php(23): Magento\SalesRule\Controller\Adminhtml\Promo\Quote\NewConditionHtml\Interceptor->___callPlugins()

4 /var/www/html/mg24/magento2/lib/internal/Magento/Framework/App/Action/Action.php(111): Magento\SalesRule\Controller\Adminhtml\Promo\Quote\NewConditionHtml\Interceptor->execute()

5 /var/www/html/mg24/magento2/app/code/Magento/Backend/App/AbstractAction.php(151): Magento\Framework\App\Action\Action->dispatch()

6 /var/www/html/mg24/magento2/lib/internal/Magento/Framework/Interception/Interceptor.php(58): Magento\Backend\App\AbstractAction->dispatch()

7 /var/www/html/mg24/magento2/lib/internal/Magento/Framework/Interception/Interceptor.php(138): Magento\SalesRule\Controller\Adminhtml\Promo\Quote\NewConditionHtml\Interceptor->___callParent()

8 /var/www/html/mg24/magento2/app/code/Magento/Backend/App/Action/Plugin/Authentication.php(145): Magento\SalesRule\Controller\Adminhtml\Promo\Quote\NewConditionHtml\Interceptor->Magento\Framework\Interception{closure}()

9 /var/www/html/mg24/magento2/lib/internal/Magento/Framework/Interception/Interceptor.php(135): Magento\Backend\App\Action\Plugin\Authentication->aroundDispatch()

10 /var/www/html/mg24/magento2/lib/internal/Magento/Framework/Interception/Interceptor.php(153): Magento\SalesRule\Controller\Adminhtml\Promo\Quote\NewConditionHtml\Interceptor->Magento\Framework\Interception{closure}()

11 /var/www/html/mg24/magento2/generated/code/Magento/SalesRule/Controller/Adminhtml/Promo/Quote/NewConditionHtml/Interceptor.php(32): Magento\SalesRule\Controller\Adminhtml\Promo\Quote\NewConditionHtml\Interceptor->___callPlugins()

12 /var/www/html/mg24/magento2/lib/internal/Magento/Framework/App/FrontController.php(245): Magento\SalesRule\Controller\Adminhtml\Promo\Quote\NewConditionHtml\Interceptor->dispatch()

13 /var/www/html/mg24/magento2/lib/internal/Magento/Framework/App/FrontController.php(212): Magento\Framework\App\FrontController->getActionResponse()

14 /var/www/html/mg24/magento2/lib/internal/Magento/Framework/App/FrontController.php(147): Magento\Framework\App\FrontController->processRequest()

15 /var/www/html/mg24/magento2/lib/internal/Magento/Framework/Interception/Interceptor.php(58): Magento\Framework\App\FrontController->dispatch()

16 /var/www/html/mg24/magento2/lib/internal/Magento/Framework/Interception/Interceptor.php(138): Magento\Framework\App\FrontController\Interceptor->___callParent()

17 /var/www/html/mg24/magento2/lib/internal/Magento/Framework/Interception/Interceptor.php(153): Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception{closure}()

18 /var/www/html/mg24/magento2/generated/code/Magento/Framework/App/FrontController/Interceptor.php(23): Magento\Framework\App\FrontController\Interceptor->___callPlugins()

19 /var/www/html/mg24/magento2/lib/internal/Magento/Framework/App/Http.php(116): Magento\Framework\App\FrontController\Interceptor->dispatch()

20 /var/www/html/mg24/magento2/generated/code/Magento/Framework/App/Http/Interceptor.php(23): Magento\Framework\App\Http->launch()

21 /var/www/html/mg24/magento2/lib/internal/Magento/Framework/App/Bootstrap.php(264): Magento\Framework\App\Http\Interceptor->launch()

22 /var/www/html/mg24/magento2/pub/index.php(30): Magento\Framework\App\Bootstrap->run()

23 {main} [] []

`

nathanjosiah commented 2 years ago

@oskarolaussen @engcom-November I see the issue, it is with the Html retrieval controller https://github.com/magento/magento2/blob/2.4-develop/app/code/Magento/SalesRule/Controller/Adminhtml/Promo/Quote/NewActionHtml.php#L32

This is definitely not ideal and there should be a validation check here but I don't see how this could be attacked with how it is currently written. I have created a ticket for this internally as a defense-in-depth ticket but it looks very unlikely to be exploitable as-is. There would need to be a class that can cause harm by having setId and/or setType methods and the arguments to those method have to be strings that are solely used to perform some type of malicious behavior. It's theoretically possible but would require some terrible class design for it to be plausible.

Ticket created https://jira.corp.magento.com/browse/AC-2571

engcom-November commented 2 years ago

Thanks for the update @nathanjosiah. Confirming the issue.

github-jira-sync-bot commented 2 years ago

:white_check_mark: Jira issue https://jira.corp.magento.com/browse/AC-2581 is successfully created for this GitHub issue.

m2-assistant[bot] commented 2 years ago

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

m2-assistant[bot] commented 2 years ago

Hi @SergeyP18. Thank you for working on this issue. Looks like this issue is already verified and confirmed. But if you want to validate it one more time, please, go though the following instruction: