CoreFiles by mySites.guru
BaseController.php46 lines, 1,386 bytes, from Joomla_6.0.0-alpha2-Alpha-Full_Package.zip
Raw History Compare with 6.0.0-alpha1
md5
5125efae7af31ffeef0b5d7f57bed673
sha1
cddf69066e79117252fec49f545d6e8913595f4c
sha256
1d3d2e9beb0495432669fecbadb6ba4f9a90a98a652fb396c1c85955c35d39b3
<?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 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 \RuntimeException('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 4 releases, Joomla 6.0.0-alpha1 to 6.0.0-beta1. See them all, or every version of this file.