CoreFiles by mySites.guru
BaseController.php46 lines, 1,386 bytes, from Joomla_5.4.0-beta1-Beta-Full_Package.zip
Raw History Compare with 5.3.0-beta3
md5
297c6d661239d3097a8e948da06ecf70
sha1
26a74555cb406e7f69355229e4cdbf0a70376c59
sha256
3ce510c79fbcdb7927e88f9dd2e93cfb211875bdad3c41a63a1d40d8b6259695
<?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 5.4.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 5.4.0-alpha1 to 5.4.0-beta1. See them all, or every version of this file.