joomla / joomla-cms

Home of the Joomla! Content Management System
https://www.joomla.org
GNU General Public License v2.0
4.7k stars 3.63k forks source link

Try to set the force_ssl via Joomla! CLI fails #43736

Open Yiannistaos opened 2 weeks ago

Yiannistaos commented 2 weeks ago

Steps to reproduce the issue

With Joomla! CLI I'm trying to set the force_ssl to the entire site.

php cli/joomla.php config:set sef=false mailonline=false force_ssl=2 -vvv

But I get an error in administrator/components/com_config/src/Model/ApplicationModel.php line 364:

[Error] Call to undefined method Joomla\CMS\Application\ConsoleApplication::setUserState()

Expected result

Screenshot 2024-07-03 at 14 42 04

Actual result

Screenshot 2024-07-03 at 14 41 38

Comments

It works fine with any other config variables. The problem is only with force_ssl.

richard67 commented 1 week ago

The exception happens here: https://github.com/joomla/joomla-cms/blob/5.1-dev/administrator/components/com_config/src/Model/ApplicationModel.php#L364

But the reason that the code goes into that catch block is because Uri::getInstance()->getHost() returns 'joomla.invalid' here https://github.com/joomla/joomla-cms/blob/5.1-dev/administrator/components/com_config/src/Model/ApplicationModel.php#L340 when running in the CLI, and so the later HTTP request in line 354 fails, and we end in that catchblock where the setUserState call fails.

So the question is what to do with that complete check at all when we are in the CLI.

brbrbr commented 1 week ago

A missing live site in the CLI might occur in more situations.

I think populateHttpHost should not set the SERVER if live_site is unset. and Uri should throw an exception if $_SERVER['HTTP_HOST'] is unset for $uri == 'SERVER'

Enforcing users to set the live_site when ever needed.