Php_codesniffer: Searching for a phpcs.xml file can throw warnings due to open_basedir restrictions

Created on 11 Jul 2019  路  1Comment  路  Source: squizlabs/PHP_CodeSniffer

Hi!

Within this loop: https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Config.php#L349-L360

            do {
                foreach ($defaultFiles as $defaultFilename) {
                    $default = $currentDir.DIRECTORY_SEPARATOR.$defaultFilename;
                    if (is_file($default) === true) {
                        $this->standards = [$default];
                        break(2);
                    }
                }
                $lastDir    = $currentDir;
                $currentDir = dirname($currentDir);
            } while ($currentDir !== '.' && $currentDir !== $lastDir);

... The $default file becomes:

$default = /home/tria2wxw20z4/public_html/wp-admin/.phpcs.xml
$default = /home/tria2wxw20z4/public_html/wp-admin/phpcs.xml
$default = /home/tria2wxw20z4/public_html/wp-admin/.phpcs.xml.dist
$default = /home/tria2wxw20z4/public_html/wp-admin/phpcs.xml.dist

$default = /home/tria2wxw20z4/public_html/.phpcs.xml
$default = /home/tria2wxw20z4/public_html/phpcs.xml
$default = /home/tria2wxw20z4/public_html/.phpcs.xml.dist
$default = /home/tria2wxw20z4/public_html/phpcs.xml.dist

$default = /home/tria2wxw20z4/.phpcs.xml
$default = /home/tria2wxw20z4/phpcs.xml
$default = /home/tria2wxw20z4/.phpcs.xml.dist
$default = /home/tria2wxw20z4/phpcs.xml.dist

$default = /home/.phpcs.xml

Once the files go outside of the user's home directory, they trigger the following warning:

Warning: is_file(): open_basedir restriction in effect. File(/home/.phpcs.xml) is not within the allowed path(s):

In my particular instance, the warning is corrupting the ajax response of this WordPress plugin: https://github.com/WPTRT/theme-sniffer

Bug

Most helpful comment

Thanks for the report. PR #2564 fixes this issue. I also discovered a related issue with searching for the composer autoloader during my testing, so I've fixed that up as well.

>All comments

Thanks for the report. PR #2564 fixes this issue. I also discovered a related issue with searching for the composer autoloader during my testing, so I've fixed that up as well.

Was this page helpful?
0 / 5 - 0 ratings