Skip to content

Searching for a phpcs.xml file can throw warnings due to open_basedir restrictions #2549

Closed
@bwmarkle

Description

@bwmarkle

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions