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

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

Closed
bwmarkle opened this issue Jul 11, 2019 · 1 comment · Fixed by #2564
Closed
Milestone

Comments

@bwmarkle
Copy link

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

@gsherwood gsherwood added this to the 3.5.0 milestone Jul 25, 2019
@gsherwood gsherwood changed the title Config.php __construct triggering open_basedir restriction warnings Searching for a phpcs.xml file can throw warnings due to open_basedir restrictions Jul 29, 2019
@gsherwood
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants