Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grav crashes on IIS (Windows) with open_basedir in effect #2053

Closed
lordrhodos opened this issue Jun 11, 2018 · 6 comments
Closed

Grav crashes on IIS (Windows) with open_basedir in effect #2053

lordrhodos opened this issue Jun 11, 2018 · 6 comments
Assignees

Comments

@lordrhodos
Copy link

lordrhodos commented Jun 11, 2018

On a recent project I came across the following issue with a provider using IIS on Windows and an active open_basedir setting related to the usage of GlobIterator.

UnexpectedValueException
GlobIterator::__construct(): open_basedir restriction in effect. File(D:/inetpub/vhosts/ingenieurbau-bohn.de/httpdocs/user/pages/*.md) is not within the allowed path(s): (D:/inetpub/vhosts/ingenieurbau-bohn.de/httpdocs;D:/inetpub/vhosts/ingenieurbau-bohn.de/httpdocs;D:/inetpub/vhosts/ingenieurbau-bohn.de/httpdocs/ssl/cache;C:\Windows\Temp;)

I think this is caused by this PHP issues which never got resolved.

We have tested the issue with PHP 5.6.x, 7.1.x and 7.2.x all with the same result.

You can easily reproduce the issue if you can get hands on an IIS with the open_basedir set. I have attached two files to recreate the issue which you should place inside the path of the open_basdir setting:

globiterator.php

<?php

try {
    /** @var SplFileInfo $fileInfo */
    foreach (new GlobIterator(__DIR__ . DIRECTORY_SEPARATOR . '*') as $fileInfo) {
        echo $fileInfo->getPathname()  . PHP_EOL;
    }
} catch (UnexpectedValueException $exception) {
    echo $exception->getMessage();
}

globl

<?php

foreach (glob(__DIR__ . DIRECTORY_SEPARATOR . '*') as $file) {
    echo $file . PHP_EOL;
}

The GlobIterator is used in Common/Page/Pages.php:1011 and in the Grav Problems Plugin with the latter actually being the first Exception to be thrown (which can be skipped with disabling the problems plugin).

I have used glob() to patch the code for my project for now, but as hosting on IIS in conjunction with open_basedir setting mare be a rare case I just wanted to get some feedback before providing a PR.

globiterator.zip

@rhukster
Copy link
Member

Hmm.. it's my understanding that the SPL iterators are far superior to the older glob() functions. In regards to performance especially. If you could create a PR with some specific detection and fallback to use the glob function for this IIS scenario, I would be interested in merging that.

@mahagr
Copy link
Member

mahagr commented Jun 13, 2018

To me this almost looks like misconfiguration of PHP. The weird thing is that...

D:/inetpub/vhosts/ingenieurbau-bohn.de/httpdocs/user/pages/*.md
D:/inetpub/vhosts/ingenieurbau-bohn.de/httpdocs
D:/inetpub/vhosts/ingenieurbau-bohn.de/httpdocs

... by looking into those three paths, the first path is inside of the allowed paths. But why is the same path two times in the configuration?

@lordrhodos
Copy link
Author

@rhukster totally agree. I am happy to come up with a PR for this special case.

@mahagr you are right, configuration includes unnecessary paths. But I guess this should not have any impact on the issue? I will contact the provider to fix this and update the error message once I got feedback.

@mahagr
Copy link
Member

mahagr commented Jun 13, 2018

Maybe just replace GlobIterator with FilesystemIterator with a proper filtering... As it seems to be buggy in Windows.

@mahagr
Copy link
Member

mahagr commented Jun 14, 2018

I ended up rewriting the logic on fetching markdown files and folders in Pages::recurse() method. It was looping through the files multiple times with two different iterators.

@rhukster If you have some multilanguage site available, please test if the right pages get picked up. On my tests, the logic seems to work just fine, but it doesn't hurt to have some extra testing.

I also removed extra filtering for .md files, so as long as the main page file is in the extension fallback list, it will get picked up.

@mahagr mahagr closed this as completed Jun 14, 2018
@mahagr mahagr added the fixed label Jun 14, 2018
@mahagr mahagr reopened this Jun 14, 2018
@rhukster
Copy link
Member

Multilang test site seems to work fine.

@mahagr mahagr closed this as completed Sep 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants