I tried the solutions listed here and none really worked for me. di compile
isn't working because there are tons of syntax errors in the code. We're on version 2.3.4 and our webhosts did the most recent upgrade. Near term, we're going to move off M2.
In Magento documentation is mention of webapi.xml controlling access. I performed a find
command looking for "webapi.xml" as the file name. Of the 60 results, vendor/magento/module-customer/etc/webapi.xml
looked promising, especially seeing the createAccount
method.
<!-- Customer Account -->
<route url="/V1/customers/:customerId" method="GET">
<service class="Magento\Customer\Api\CustomerRepositoryInterface" method="getById"/>
<resources>
<resource ref="Magento_Customer::customer"/>
</resources>
</route>
<route url="/V1/customers" method="POST">
<service class="Magento\Customer\Api\AccountManagementInterface" method="createAccount"/>
<resources>
<resource ref="anonymous"/>
</resources>
</route>
Near line 128, I noticed the anonymous
... copied this file to save the original and then edited that section to:
<!-- Customer Account -->
<route url="/V1/customers/:customerId" method="GET">
<service class="Magento\Customer\Api\CustomerRepositoryInterface" method="getById"/>
<resources>
<resource ref="Magento_Customer::customer"/>
</resources>
</route>
<route url="/V1/customers" method="POST">
<service class="Magento\Customer\Api\AccountManagementInterface" method="createAccount"/>
<resources>
<resource ref="Magento_Customer::customer"/>
</resources>
</route>
Since this change, there have only been a couple of spam customer accounts created overnight. These seem to have some kind of programmatic syntax like ThomasHap ThomasHapZM
. I am next going to see if I can delete accounts via SQL... there are several thousand of this kind of account. To get these, I'll see how the customer table is populated in the admin and then also search for empty state, etc, along with the first and last names containing the same sequence.
Before experimenting with this kind of approach, try to contemplate the wider affects of the restriction. I do not know if changing all anonymous
to something more contextually relevant for the module will crash your site. We haven't yet had anyone complain about not creating an account, so my change worked for our website.
If you have ssh
access, this command can help you find anonymous Web APIs:
find . -name webapi.xml -print0 | xargs -0 grep -n 'anonymous'