CoreFiles by mySites.guru
BaseController.php47 lines, 1,443 bytes, from Joomla_6.1.0-alpha1-Alpha-Full_Package.zip
Raw History Compare with 6.0.0-alpha3
md5
4f7dd3cfc47bcf6a819179396d28eb45
sha1
6a125af17c9f9b985ec0c8b08f7355766e633310
sha256
63cfff15df8e9672f189bc319cefb4b3f713b7ab7117a6d92f9c7e484245cc01
<?php

/**
 * @package     Joomla.API
 * @subpackage  com_joomlaupdate
 *
 * @copyright   (C) 2025 Open Source Matters, Inc. <https://www.joomla.org>
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

namespace Joomla\Component\Joomlaupdate\Api\Controller;

use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\MVC\Controller\ApiController;
use Joomla\CMS\MVC\Controller\Exception\ResourceNotFound;
use Tobscure\JsonApi\Exception\InvalidParameterException;

abstract class BaseController extends ApiController
{
    /**
     * Validate if the update token is correct and auto update is enabled
     *
     * @return void
     *
     * @since 6.0.0
     *
     * @throws \Exception
     */
    protected function validateUpdateToken(): void
    {
        $config = ComponentHelper::getParams('com_joomlaupdate');

        if ($config->get('updatesource') !== 'default' || (int) $config->get('minimum_stability') !== 4 || !$config->get('autoupdate')) {
            throw new ResourceNotFound('Auto update is disabled', 404);
        }

        $token = $this->input->server->get('HTTP_X_JUPDATE_TOKEN', '', 'STRING');

        if (empty($token)) {
            throw new InvalidParameterException('Token is required', 403, null, 'token');
        }

        if ($config->get('update_token') !== $token) {
            throw new InvalidParameterException('Invalid token', 403, null, 'token');
        }
    }
}

The same content is in 46 releases, Joomla 6.0.0-beta2 to 6.2.1-rc1. See them all, or every version of this file.