Skip to content
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

Despite "Allow Guest Checkout" set to "No" it's possible to place a guest order with the guest-carts REST API #36691

Closed
1 of 5 tasks
C4rter opened this issue Dec 30, 2022 · 34 comments
Labels
Area: APIs Component: Checkout Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Priority: P1 Once P0 defects have been fixed, a defect having this priority is the next candidate for fixing. Progress: done Reported on 2.4.5-p1 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

@C4rter
Copy link

C4rter commented Dec 30, 2022

Preconditions and environment

  • Magento 2.4.4 and 2.4.5-p1

We just had a hacker that tried to use the vulnerability "APSB22-12" to hack our store.

Thankfully we had the patches applied on 2.4.4 (and now upgraded to 2.4.5-p1) and he was not successful.
But he was able to try out the vulnerability by placing a guest order via the Rest API despite the guest-checkout being disabled in the backend.

Why is this still possible via API? It's a big risk because it allows unwanted guest orders being placed and in my case letting a hacker try out vulnerabilities.

How do I know that he did it via API?
There is no way to place a guest order via the frontend and you can see it in the access log how he did it:

"POST /checkout/cart/add/uenc/aHR0cHM6Ly93d3cucGxhdGV3cml0ZS5kZS9jdHAtZHJ1Y2twbGF0dGVuYmVsaWNodHVuZy9kcnVja3BsYXR0ZS0yNTB4MzcwLmh0bWw%2C/product/500/ HTTP/1.1" 200 1025 "-"
"GET /checkout HTTP/1.1" 302 1388 "-"
"GET /checkout/cart/ HTTP/1.1" 200 34064 "-"
"POST /rest/default/V1/customers/isEmailAvailable HTTP/1.1" 400 354 "-"
"POST /rest/italian/V1/customers/isEmailAvailable HTTP/1.1" 400 4619 "-"
"POST /rest/de/V1/customers/isEmailAvailable HTTP/1.1" 200 4840 "-"
"POST /rest/de/V1/guest-carts/Qgfa1jFEf8m430Vlo0xnFLz2uIyqAUPI/estimate-shipping-methods HTTP/1.1" 200 1021 "-"
"POST /rest/de/V1/guest-carts/Qgfa1jFEf8m430Vlo0xnFLz2uIyqAUPI/shipping-information HTTP/1.1" 200 3374 "-"
"POST /rest/de/V1/guest-carts/Qgfa1jFEf8m430Vlo0xnFLz2uIyqAUPI/payment-information HTTP/1.1" 200 4843 "-"
"POST /b2b.php HTTP/1.1" 302 5380 "-"

At the end he even tries to call the b2b.php file that he tried to create with his injection.

Steps to reproduce

  1. Make sure "Allow Guest Checkout" is set to "No" in Backend Config (Stores->Configuration->Sales->Checkout->Allow Guest Checkout)
  2. Check if guest checkout is possible when going through the frontend (should not and is not possible)
  3. Do a guest-checkout with the use of the Rest API.

Get a new Cart:
POST https://[YOUR-SHOP-URL]/rest/[YOUR-STORE-VIEW-CODE]/V1/guest-carts
You receive a basket ID here that you need in every step.

Add a product to the Cart:
POST https://[YOUR-SHOP-URL]/rest/[YOUR-STORE-VIEW-CODE]/V1/guest-carts/[YOUR-BASKET-ID]/items

Body:

{
  "cartItem": {
    "sku": "[SOME-EXISTING-SKU]",
    "qty": 1
  }
}

Set shipping and billing address:
POST https://[YOUR-SHOP-URL]/rest/[YOUR-STORE-VIEW-CODE]/V1/guest-carts/[YOUR-BASKET-ID]/shipping-information

Body:
(Make sure you use a shipping method that exists. Maybe adjust the country to one that's allowed in your setup.)

{
  "addressInformation": {
    "shipping_address": {
      "region": "New York",
      "region_id": 0,
      "region_code": "",
      "country_id": "DE",
      "street": [
        "123 Oak Ave"
      ],
      "postcode": "10577",
      "city": "Purchase",
      "firstname": "Jane",
      "lastname": "Doe",
      "email": "jdoe@example.com",
      "telephone": "512-555-1111"
    },
    "billing_address": {
      "region": "New York",
      "region_id": 0,
      "region_code": "",
      "country_id": "DE",
      "street": [
        "123 Oak Ave"
      ],
      "postcode": "10577",
      "city": "Purchase",
      "firstname": "Jane",
      "lastname": "Doe",
      "email": "jdoe@example.com",
      "telephone": "512-555-1111"
    },
    "shipping_carrier_code": "freeshipping",
    "shipping_method_code": "freeshipping"
  }
}

Place Order:
POST https://[YOUR-SHOP-URL]/rest/[YOUR-STORE-VIEW-CODE]/V1/guest-carts/[YOUR-BASKET-ID]/payment-information

Body:
(You will have to adjust the agreement IDs or leave them out entirely and make sure you use a payment method that exists)

{
  "email": "jdoe@example.com",
  "paymentMethod": {
    "method": "banktransfer",
    "extension_attributes": {"agreement_ids": ["1","2","5"]}
  },
  "billing_address": {
    "email": "jdoe@example.com",
    "region": "New York",
    "region_id": 0,
    "region_code": "",
    "country_id": "DE",
    "street": [
      "123 Oak Ave"
    ],
    "postcode": "10577",
    "city": "Purchase",
    "telephone": "512-555-1111",
    "firstname": "Jane",
    "lastname": "Doe",
    "same_as_billing": 0
  }
}
  1. Guest Order will be placed.

Expected result

Guest checkout should not be possible via the API when the guest checkout is disabled in the configuration.

Actual result

Guest checkout can be used and an order can be placed as a guest.

Additional information

Maybe somewhere in vendor/magento/module-checkout/Model/GuestPaymentInformationManagement.php in the savePaymentInformationAndPlaceOrder function there can be a condition, that checks if guest checkout is even allowed.

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”.
@m2-assistant
Copy link

m2-assistant bot commented Dec 30, 2022

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

  • Summary of the issue
  • Information on your environment
  • Steps to reproduce
  • Expected and actual results

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.


⚠️ 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.

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

@m2-assistant
Copy link

m2-assistant bot commented Jan 2, 2023

Hi @engcom-Bravo. 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: 👇

  • 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).

    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.

  • 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • 4. Verify that the issue is reproducible on 2.4-develop branch

    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!

  • 5. Add label Issue: Confirmed once verification is complete.

  • 6. Make sure that automatic system confirms that report has been added to the backlog.

@engcom-Bravo engcom-Bravo added the Reported on 2.4.5-p1 Indicates original Magento version for the Issue report. label Jan 2, 2023
@engcom-Bravo
Copy link
Contributor

@magento give me 2.4-develop instance

@magento-deployment-service
Copy link

Hi @engcom-Bravo. Thank you for your request. I'm working on Magento instance for you.

@magento-deployment-service
Copy link

@engcom-Bravo
Copy link
Contributor

Hi @C4rter,

Thank you for reporting and collaboration.
Verified the issue on Magento 2.4-develop instance and the issue is not reproducible.Kindly refer the screenshots.

Using frontend not able to place the order as a Guest.

Screenshot 2023-01-03 at 2 50 43 PM

Using API not able to place the order as a Guest.

Screenshot 2023-01-03 at 2 52 55 PM

Kindly let us know if we miss anything.

Thanks.

@engcom-Bravo engcom-Bravo added the Issue: needs update Additional information is require, waiting for response label Jan 3, 2023
@viktorlantos
Copy link

The same thing happened to us a few days ago on 2.4.5-p1. Guest checkout was set as NO. Pretty worrying.

@C4rter
Copy link
Author

C4rter commented Jan 3, 2023

Hi @engcom-Bravo

thank you for testing. As I see from your screenshots you used the GraphQL endpoint.
I mentioned that the hacker used the REST API endpoint and my "Steps to reproduce" also show the Rest API.

It might be that it's not possible via the GraphQL endpoint but I'm sure it's possible via the Rest API.

The error that's visible in your screenshot is a GQL specific error, thrown in a file only used when using the GQL API:
vendor/magento/module-quote-graph-ql/Model/Cart/CheckCartCheckoutAllowance.php

    public function execute(Quote $quote): void
    {
        if (!$quote->getCustomerIsGuest()) {
            return;
        }

        $isAllowedGuestCheckout = (bool)$this->checkoutHelper->isAllowedGuestCheckout($quote);
        if (false === $isAllowedGuestCheckout) {
            throw new GraphQlAuthorizationException(
                __(
                    'Guest checkout is not allowed. ' .
                    'Register a customer account or login with existing one.'
                )
            );
        }
    }

So it makes sense, that it's not possible when using GQL Api. But it's unfortunately possible when using REST API.

Can you please verify it via the REST API endpoint?
Thanks

@viktorlantos
Copy link

viktorlantos commented Jan 3, 2023

To confirm, we had Rest API guest order as well. Just finished the Sansec scan, and with M2.4.5-p1 only the order was placed. No other harm was detected. Sansec Scrutinize mode found it in the db:quote
10% MALWARE m2_template_attack_payload_cc6e3

@engcom-Bravo
Copy link
Contributor

Hi @C4rter,

Thanks for your update.

@viktorlantos Thanks for your contribution & collaboration over here.

Verified the issue on Magento 2.4-develop instance and the issue is reproducible.Kindly refer the screenshots.

Steps to reproduce
1.Make sure "Allow Guest Checkout" is set to "No" in Backend Config (Stores->Configuration->Sales->Checkout->Allow Guest Checkout)
2.Check if guest checkout is possible when going through the frontend (should not and is not possible)
3.Do a guest-checkout with the use of the Rest API.

Using frontend we are not able to place the order as a guest.

Screenshot 2023-01-04 at 12 55 44 PM

Using Rest Api we are able to place the order as a guest.

Screenshot 2023-01-04 at 12 57 07 PM

Screenshot 2023-01-04 at 12 55 53 PM

Hence confirming this issue.

Thanks.

@engcom-Bravo engcom-Bravo removed the Issue: needs update Additional information is require, waiting for response label Jan 4, 2023
@engcom-Bravo engcom-Bravo added Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed and removed Issue: ready for confirmation labels Jan 4, 2023
@github-jira-sync-bot
Copy link

❌ Cannot export the issue. This GitHub issue is already linked to Jira issue(s): https://jira.corp.adobe.com/browse/AC-7577

@mabt
Copy link

mabt commented Jan 18, 2023

Same here on 2.4.5-1 Guest Checkout disabled

BUT Also: WEB API - Allow Anonymus Guest Access: No

I do not know what the later means, but it looks like both checks failed!

Complete access.log that might helps to understand a bit more (going trough all the pages makes it not anonymous guest anymore?):

"GET / HTTP/1.1" 200 29438 "-" 
"GET / HTTP/1.1" 200 29438 "-" 
"POST /pr-cookie-consent/consent_guest/update/ HTTP/1.1" 302 31 "-" 
"GET / HTTP/1.1" 200 29438 "-" 
"GET /someproducturl.html HTTP/1.1" 200 20423 "-" 
"POST /checkout/cart/add/uenc/aHR0cHM6Ly93d3cudHJhZGVzZXJ2aWNlLmh1L3R6NGstbXQ4L2ZwbTgwMy5odG1s/product/9108/ HTTP/1.1" 200 89 "-" 
"GET /checkout HTTP/1.1" 302 31 "-" 
"GET /checkout/cart/ HTTP/1.1" 200 64515 "-" 
"POST /rest/default/V1/customers/isEmailAvailable HTTP/1.1" 200 35 "-" 
"POST /rest/default/V1/guest-carts/SEJoFR1LPXT1VpcBXqP8q1suSllJMvoG/estimate-shipping-methods HTTP/1.1" 200 219 "-" 
"POST /rest/default/V1/guest-carts/SEJoFR1LPXT1VpcBXqP8q1suSllJMvoG/shipping-information HTTP/1.1" 200 547 "-" 
"POST /b2b.php HTTP/1.1" 404 368 "-"

We are facing everyday the same hack (same requests) on multiple magento2, does someone have a fix?

@anthonyvdg-se
Copy link

anthonyvdg-se commented Jan 26, 2023

@mabt If you don't have guest orders, you can block requests to the guest endpoints. See https://developer.adobe.com/commerce/webapi/rest/use-rest/anonymous-api-security/

(Search on /V1/guest-carts)

@C4rter
Copy link
Author

C4rter commented Feb 1, 2023

@mabt If you don't have guest orders, you can block requests to the guest endpoints. See https://developer.adobe.com/commerce/webapi/rest/use-rest/anonymous-api-security/

(Search on /V1/guest-carts)

If you mean the "Allow Anonymous Guest Access" config mentioned there, that does not block access to the guest-carts API.

It says so on the page:
"The following APIs remain accessible to anonymous users" and then lists all guest-cart endpoints.

Only way would be to block them manually via a custom plugin.

@anthonyvdg-se
Copy link

@mabt If you don't have guest orders, you can block requests to the guest endpoints. See https://developer.adobe.com/commerce/webapi/rest/use-rest/anonymous-api-security/
(Search on /V1/guest-carts)

If you mean the "Allow Anonymous Guest Access" config mentioned there, that does not block access to the guest-carts API.

It says so on the page: "The following APIs remain accessible to anonymous users" and then lists all guest-cart endpoints.

Only way would be to block them manually via a custom plugin.

The mostly easiest solution is to block on server level (nginx, apache, etc)

@glo05363
Copy link
Contributor

glo05363 commented Mar 17, 2023

@C4rter thank you for addressing the issue: we have reproduced it with following steps:

We have disabled guest-cart-checkout in admin which disables storefront access.
image

API:

  1. POST [domain]/rest/default/V1/guest-carts : response: cartid-> 8Sa8iH70go696ng0TqWZVyyNSWTSnzMc
  2. POST [domain]/rest/default/V1/guest-carts/{cartid}/items with payload
    { "cartItem": { "sku": "simple", "qty": 1 } }
  3. POST [domain]/rest/default/V1/guest-carts/{cartid}/shipping-information with appropriate payload
    { "addressInformation": { "shipping_address": { "region": "New York", "region_id": 0, "region_code": "", "country_id": "DE", "street": [ "123 Oak Ave" ], "postcode": "10577", "city": "Purchase", "firstname": "Jane", "lastname": "Doe", "email": "jdoe@example.com", "telephone": "512-555-1111" }, "billing_address": { "region": "New York", "region_id": 0, "region_code": "", "country_id": "DE", "street": [ "123 Oak Ave" ], "postcode": "10577", "city": "Purchase", "firstname": "Jane", "lastname": "Doe", "email": "jdoe@example.com", "telephone": "512-555-1111" }, "shipping_carrier_code": "flatrate", "shipping_method_code": "flatrate" } }
  4. POST [domain]/rest/default/V1/guest-carts/{cartid}/payment-information with payload
    { "email": "jdoe@example.com", "paymentMethod": { "method": "checkmo" }, "billing_address": { "email": "jdoe@example.com", "region": "New York", "region_id": 0, "region_code": "", "country_id": "DE", "street": [ "123 Oak Ave" ], "postcode": "10577", "city": "Purchase", "telephone": "512-555-1111", "firstname": "Jane", "lastname": "Doe", "same_as_billing": 0 } }
    Response:

image

image

And we see that every guest-cart API is functioning .

We have also disabled WEB API Anonymous guest access though it works only for CMS, Catalog and store APIs.
image

To add to this please check https://developer.adobe.com/commerce/webapi/rest/use-rest/anonymous-api-security/
Here it is mentioned that:
image

we conclude it to be working as it is suppose to.

@anthonyvdg-se
Copy link

I thought the payment-information endpoint created the order, did you check that despite the shipping endpoint failing? (maybe there are some extra checks preventing the shipping flow from continuing, every store can be configured differently)

Not sure if I'm missing anything but not able to reproduce it image

Steps I followed is like below,

  1. POST http://magento-github.local/rest/V1/guest-carts => GOT cart ID h8YLEHwbzZ9ewbXjhr29B6iBO2ksNs01
  2. GET http://magento-github.local/rest/V1/guest-carts/h8YLEHwbzZ9ewbXjhr29B6iBO2ksNs01 => Got quote ID
  3. POST http://magento-github.local/rest/default/V1/guest-carts/h8YLEHwbzZ9ewbXjhr29B6iBO2ksNs01/items
  4. POST http://magento-github.local/rest/default/V1/guest-carts/h8YLEHwbzZ9ewbXjhr29B6iBO2ksNs01/estimate-shipping-methods
  5. POST http://magento-github.local/rest/default/V1/guest-carts/h8YLEHwbzZ9ewbXjhr29B6iBO2ksNs01/shipping-information
  6. POST http://magento-github.local/rest/default/V1/guest-carts/2FHsrl9MF58IKc8AIxk70Psvl4EYyoLW/payment-information

It's stopping me at step 5 with proper message

@yogesh-valiya
Copy link
Member

I'm not able to reproduce it on 2.4-develop branch as it seems to be get fixed by this commit - 47c388a

@github-jira-sync-bot github-jira-sync-bot added Progress: PR Created Indicates that Pull Request has been created to fix issue and removed Progress: ready for grooming labels Mar 17, 2023
@glo05363
Copy link
Contributor

glo05363 commented Mar 17, 2023

@C4rter @yogesh-valiya Yes The issue is no longer there on 2.4-develop as the commit #47c388a

@m2-community-project m2-community-project bot removed the Progress: PR Created Indicates that Pull Request has been created to fix issue label Mar 20, 2023
@engcom-Hotel
Copy link
Contributor

Hello,

As I can see this issue got fixed in the scope of the internal Jira ticket ACP2E-1339 by the internal team
Related commits: https://github.com/magento/magento2/search?q=ACP2E-1339&type=commits

Thanks

@LucScu
Copy link

LucScu commented Apr 23, 2024

@yogesh-valiya @glo05363 @engcom-Bravo It isn't merged with 2.4.6-p3 right?
What is the best way to merge this commit into own environment?

@s-renz
Copy link

s-renz commented Jul 25, 2024

@yogesh-valiya @glo05363 @engcom-Bravo It isn't merged with 2.4.6-p3 right? What is the best way to merge this commit into own environment?

There's aparently quality patch with the ID ACSD-47920 that you can manually apply (see KB article linked below). However, it's not marked as compatible with 2.4.6-p*, so not sure if that's actually working.

But actually I think the better question would actually be, why is a security fix not merged in 2.4.6 including p6 even though it should be?

In my opinion this isn't just a "quality" patch, this is a potential security issue, as any attacker can still send orders without authentication. Which might include payloads (like stated in the original post regarding APSB22-12). So next time a similar exploit is found it can be executed even though guest checkout is disabled already.

The KB article even states that this should be fixed in 2.4.6: https://experienceleague.adobe.com/en/docs/commerce-knowledge-base/kb/support-tools/patches/v1-1-24/acsd-47920-guest-order-allow-guest-checkout-off

Please note that the issue is scheduled to be fixed in Adobe Commerce 2.4.6

@rintoug
Copy link

rintoug commented Aug 6, 2024

There are some of the endpoints still used by magento even if you are only using the web UI. For example, rest/storecode/V1/guest-carts/quote-id/estimate-shipping-methods which used in the /checkout/cart page to retrieve the shipping charges. In case you completely blocked the guest APIs, this feature will not work.

@frostitution
Copy link

This is still an issue, I received a "guest" order just fine despite having guest checkout disabled. 2.4.6-p5

@76ludwig
Copy link

I received a hacker's guest order via API in my Magento shop yesterday. The shop was updated to 2.4.6-p6 two days ago...

@rintoug
Copy link

rintoug commented Aug 15, 2024

I received a hacker's guest order via API in my Magento shop yesterday. The shop was updated to 2.4.6-p6 two days ago...

We are running the same version and received a couple of orders last week. However, we are not using the APIs at the moment, so went ahead in Cloudflare and blocked the guest checkout APIs.

You can try executing the guest apis yourself in Postman or any other clients, and see it yourself(Quick endpoint ref to make quick guest order).

@dphilipps
Copy link

dphilipps commented Aug 15, 2024

We've blocked access to guest cart APIs as we don't use them by adding the following rules to .htaccess after RewriteEngine on. This results in a 404 (before Magento's htaccess converts 403s to 404s)

RewriteCond %{REQUEST_METHOD} POST
RewriteRule ^rest/V1/guest-carts - [F,NC,L]
RewriteRule ^rest/default/V1/guest-carts - [F,NC,L]

@bafmaamy
Copy link

I managed to deal with this, creating a custom module and block order execution if firstname or lastname contain characters like "}","{", <.. etc. and log the attempt too.

Added also validation of the shpping address, billing address, post code, city, order comments and disallow more than 30 characters in firstname and lastname.

#39002 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: APIs Component: Checkout Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Priority: P1 Once P0 defects have been fixed, a defect having this priority is the next candidate for fixing. Progress: done Reported on 2.4.5-p1 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
Development

No branches or pull requests