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

Deprecate standalone endpoints to match PrestaShop 9.0 new security policy #983

Merged
merged 3 commits into from Feb 16, 2024

Conversation

jolelievre
Copy link
Contributor

Questions Answers
Description? Allow executing only the specific PHP files as external endpoints, required since PrestaShop 9.0 because additional security was added in this PR PrestaShop/PrestaShop#34184 The idea in this PR is to allow access to very specific files to prevent unwanted accesses on malicious files
Type? bug fix
BC breaks? no
Deprecations? no
Fixed ticket? ~
How to test? Install a shop based on develop branch, go to the module administration of faceted search and try to build indexes or clear the cache. An error message should appear and when you check the network in browser developer tools you should see that the ajax request was forbidden (403 error). Now use the branch from this PR and do the same, the ajax calls should now be successful.

@jolelievre jolelievre added this to the 3.15.0 milestone Feb 13, 2024
@kpodemski
Copy link
Contributor

My understanding is that we should create ModuleFrontControllers as a replacement for .PHP files, not to show how to omit the rules for developers in the ecosystem :D

@kpodemski
Copy link
Contributor

I'll also repeat what @matks already wrote:

I hope the people who participated in this discussion to advocate for this change will be helping this task to be complete 😝 . I plan to submit a few PRs to fix some of the modules listed but I will not do all of them.

maybe we should ping @jf-viguier @clotairer @touchweb-vincent

boherm
boherm previously approved these changes Feb 13, 2024
@Hlavtox
Copy link
Contributor

Hlavtox commented Feb 13, 2024

@kpodemski With French efficiency, we will be in grave by then :D

@Hlavtox
Copy link
Contributor

Hlavtox commented Feb 13, 2024

@jolelievre Inspiration here - https://github.com/PrestaShop/gsitemap/pull/175/files

Just throw some deprecation messages and create three simple files like:

class Ps_facetedsearchPriceindexerModuleFrontController extends ModuleFrontController
{
    public function postProcess()
    {
      if (substr(Tools::hash('ps_facetedsearch/index'), 0, 10) != Tools::getValue('token')) {
          exit('Bad token');
      }

      Shop::setContext(Shop::CONTEXT_ALL);
      $this->module->indexAttributes();
      $this->module->indexFeatures();
      $this->module->indexAttributeGroup();
    }
}

matks
matks previously approved these changes Feb 13, 2024
Copy link
Contributor

@matks matks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Message deleted by @matks, see #983 (comment) for context.

@clotairer
Copy link
Contributor

clotairer commented Feb 13, 2024

Not sure comments opposing dev secops and opensource dev or a "national cliche" serve the cause... I'm all days on Slack if you want request me about something bet not at the same frequency on Github. Neverminds.
Could you please define me a dead line ? I'll try to find a developper for this issue.

@jolelievre
Copy link
Contributor Author

@kpodemski @Hlavtox hmm, you're right introducing dedicated controllers would be cleaner, I'm gonna do that to show the example

@jolelievre jolelievre marked this pull request as draft February 14, 2024 09:24
@matks
Copy link
Contributor

matks commented Feb 14, 2024

Not sure comments opposing dev secops and opensource dev or a "national cliche" serve the cause... I'm all days on Slack if you want request me about something bet not at the same frequency on Github. Neverminds. Could you please define me a dead line ? I'll try to find a developper for this issue.

Hello here,

Thank you @clotairer for reaching out to me, both in this GitHub thread and in private messages on Slack.

As I explained to Clotaire, yesterday I wrote the message above because I felt kindof like I had been let down. During discussion PrestaShop/PrestaShop#34184 there was a lot of people arguing and a lot of time was spent discussing the change. Initially I was not thrilled with the idea of the change. However I took a step forward and I approved the PR, knowing that it would request some time and energy to reverberate that change into all of the project. Yesterday when I found out the only people who worked on reverberating this change were me and Hlavtox, I felt let down. This is why I wrote I was disappointed. I felt like I was compelled to carry out the changes even though initially I was not pushing for them. So yesterday I expressed my feelings.

Today I regret writing this message. There's a saying "never write an email when you're irritated" I should have listened to this piece of wisdom.

@clotairer has already reached out to me and offered help so things will probably turn out a lot better than I thought. Thank you again for that.

My apologies for the above message, it was snarky and I regret that. Venting off on the internet is never a good thing, the right thing to do is to wait 24 hours and write a better and more constructive message later. I should have done that.

@clotairer
Copy link
Contributor

clotairer commented Feb 14, 2024

@jolelievre Why not create Command ?
For website in PS 9, already compliant. For previous PS release, the old script could be stay in place and deprecated.

@jolelievre
Copy link
Contributor Author

@clotairer creating command to be run in CLI would be nice, but it's not the same behaviour as the current one which is based on URLs that can be called (I guess it's mainly for merchants who do not have access to cron editing on their server and use external third party services that call the URL as a webhook), so in this PR I only focused on making a similar behaviour

@kpodemski @Hlavtox I created a module front controller to replace these endpoints, I tried to create an Admin one for this but couldn't make it work on develop branch since we now have an automatic CQRF token checking on each request and it requires having a logged session to be validated So external calls are not compatible with CSRF protection which makes sense, so the only solution I found was to put this endpoint on the FO side, it sill integrates its custom token validation system which is the same as the standalone endpoint

The standalone endpoints have been deprecated and should be cleaned in the next major version of this module along with the .htaccess file

@jolelievre jolelievre marked this pull request as ready for review February 14, 2024 14:50
@jolelievre jolelievre changed the title Allow execution of specific endpoints to match PrestaShop 9.0 new security policy Deprecate standalone endpoints to match PrestaShop 9.0 new security policy Feb 14, 2024

public function postProcess()
{
if (substr(Tools::hash('ps_facetedsearch/index'), 0, 10) != Tools::getValue('token') || !Module::isInstalled('ps_facetedsearch')) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that !Module::isInstalled('ps_facetedsearch') can be removed, the controller should not be callable if the module is not active or installed.

matks
matks previously approved these changes Feb 15, 2024
@@ -17,6 +17,14 @@
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
*/

/*
* This standalone endpoint is deprecated, it should not be sued anymore and should be removed along with the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* This standalone endpoint is deprecated, it should not be sued anymore and should be removed along with the
* This standalone endpoint is deprecated, it should not be used anymore and should be removed along with the

Yes please don't sue it the poor guy

@@ -17,6 +17,14 @@
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
*/

/*
* This standalone endpoint is deprecated, it should not be sued anymore and should be removed along with the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* This standalone endpoint is deprecated, it should not be sued anymore and should be removed along with the
* This standalone endpoint is deprecated, it should not be used anymore and should be removed along with the

@@ -17,6 +17,14 @@
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
*/

/*
* This standalone endpoint is deprecated, it should not be sued anymore and should be removed along with the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* This standalone endpoint is deprecated, it should not be sued anymore and should be removed along with the
* This standalone endpoint is deprecated, it should not be used anymore and should be removed along with the

'full_price_indexer_url' => $moduleUrl . 'ps_facetedsearch-price-indexer.php' . '?token=' . substr(Tools::hash('ps_facetedsearch/index'), 0, 10) . '&full=1',
'attribute_indexer_url' => $moduleUrl . 'ps_facetedsearch-attribute-indexer.php' . '?token=' . substr(Tools::hash('ps_facetedsearch/index'), 0, 10),
'clear_cache_url' => $moduleUrl . 'ps_facetedsearch-clear-cache.php' . '?token=' . substr(Tools::hash('ps_facetedsearch/index'), 0, 10),
'price_indexer_url' => $this->context->link->getModuleLink('ps_facetedsearch', 'cron', ['ajax' => true, 'action' => 'indexPrices', 'token' => $cronToken]),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@jolelievre
Copy link
Contributor Author

Thanks @matks and @Hlavtox all should be good now

@AureRita AureRita self-assigned this Feb 16, 2024
@AureRita
Copy link

Hi @jolelievre

Thank you for your PR, I tested it and it seems to works on develop and also on 8.1.x, as we can see :

recording.104.webm

Because the PR seems to works as expected, It's QA ✔️

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
8 participants