Page 1 of 1

open_basedir error in edit module configuration

Posted: Mon Nov 18, 2024 10:10 am
by cut-n-paste
I get the following error when trying to configure this holiday message module by @raiwa. I have double checked my config and also done some basic debugging to check the value of DIR_FS_CATALOG etc. I am hosting on a shared host and I think this could be related to a symlinked www basedir.

Code: Select all

Fatal error: Uncaught RuntimeException: SplFileInfo::isFile(): open_basedir restriction in effect. File(/usr/www/users/xxxxmhfc/..) is not within the allowed path(s):

(/usr/www/wwws/users/xxxxmhfc:/usr/wwws/users/xxxxmhfc:/usr/www/users/xxxxmhfc:/usr/home/xxxxmhfc:/usr/local/rmagic:/usr/share/php:/usr/local/lib/php:/tmp:/usr/bin:/usr/local/bin:/usr/local/share/www:/usr/www/share/www:/usr/share/misc:/dev/urandom:/var/www/php_profiler/xhgui) in /usr/www/users/xxxxmhfc/includes/system/versioned/1.0.5.6/page_selection.php:30

Stack trace: 
#0 /usr/www/users/xxxxmhfc/includes/system/versioned/1.0.5.6/page_selection.php(30): SplFileInfo->isFile() 
#1 /usr/www/users/xxxxmhfc/admin/includes/actions/modules/infoboxes/edit.php(20) : eval()'d code(1): page_selection::_edit_pages('index.php', 'MODULE_CONTENT_...') 
#2 /usr/www/users/xxxxmhfc/admin/includes/actions/modules/infoboxes/edit.php(20): eval() 
#3 /usr/www/users/xxxxmhfc/admin/includes/components/infobox.php(15): require('/usr/www/users/...') 
#4 /usr/www/users/xxxxmhfc/admin/modules.php(199): require('/usr/www/users/...') 
#5 {main} thrown in /usr/www/users/xxxxmhfc/includes/system/versioned/1.0.5.6/page_selection.php on line 30
Installed Version: CE Phoenix v1.0.8.20
PHP 8.1

With some help from @raiwa I modified core script page_selection.php from:

Code: Select all

      // main files
      foreach (new DirectoryIterator(DIR_FS_CATALOG) as $file) {
        if ($file->isFile() && ($file->getExtension() === 'php')) {
          $files[] = $file->getFilename();
        }
      }
to:

Code: Select all

      foreach (new DirectoryIterator(DIR_FS_CATALOG) as $file) {
        if ($file->isDot()) { // Skip '.' and '..'
          continue;
        }
        if ($file->isFile() && ($file->getExtension() === 'php')) {
          $files[] = $file->getFilename();
        }
      }

Re: open_basedir error in edit module configuration

Posted: Mon Nov 18, 2024 10:40 am
by burt
Does this error present itself on any core module that uses the core (ie UNCHANGED) page selector?

EG, try it on admin > modules > header tags > No Index

Re: open_basedir error in edit module configuration

Posted: Mon Nov 18, 2024 10:59 am
by cut-n-paste
I get the same error on the core module admin > modules > header tags> No Index > Edit if I don't make the mod.

I did a bit more research and it seems like DirectoryIterator does turn up . and .. by default, and so I suppose this is expected behaviour when my host has an open_basedir limit on my www folder.

Re: open_basedir error in edit module configuration

Posted: Mon Nov 18, 2024 11:11 am
by burt
I suppose so.

You could try this;

Code: Select all

// main files
$dir = new RecursiveDirectoryIterator(DIR_FS_CATALOG, RecursiveDirectoryIterator::SKIP_DOTS);
foreach ($dir as $file) {
  if ($file->isFile() && ($file->getExtension() === 'php')) {
    $files[] = $file->getFilename();
  }
}

Re: open_basedir error in edit module configuration

Posted: Mon Nov 18, 2024 11:40 am
by cut-n-paste
This works and looks a lot better.

Re: open_basedir error in edit module configuration

Posted: Mon Nov 18, 2024 12:52 pm
by cut-n-paste
Is likely to be a changed in the core file or will I need to do a system override?

Re: open_basedir error in edit module configuration

Posted: Mon Nov 18, 2024 4:06 pm
by burt
Just do an override for now.

I don't want to change it now (maybe in the future if more users experience the same), when it's been OK for many hundreds of users since 1.0.5.6.

TY.