Skip to content

Use CONTEXT_DOCUMENT_ROOT for scanning dir tree #5051

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

Closed
wants to merge 1 commit into from

Conversation

Ragnoroct
Copy link

This allows people to use the CONTEXT_DOCUMENT_ROOT variable to scan recursively for .user.ini files.

There is a bug report open here https://bugs.php.net/bug.php?id=64865 and plenty of other references to this issue on stackoverflow and other forums.

I'm not sure if this should be an RFC or not. So I just created a pull request to start the process.

@nikic
Copy link
Member

nikic commented Jan 10, 2020

Looks reasonable to me for master, but I don't think we should land this change on stable versions. It seems quite likely that people rely on the current behavior as a workaround if nothing else.

* If CONTEXT_DOCUMENT_ROOT is set use that rather than DOCUMENT_ROOT to
  scan up the dir tree looking for .user.ini files.
@Ragnoroct Ragnoroct changed the base branch from PHP-7.3 to master January 14, 2020 17:44
@Ragnoroct
Copy link
Author

Okay, I've rebased my PHP-7.3 to master and changed the pull request target.
In hindsight I should have created a new branch to avoid this confusing setup. I can always create another pull request and close this one.

@php-pulls php-pulls closed this in 98bfad7 Jan 24, 2020
@carusogabriel carusogabriel added this to the PHP 8.0 milestone May 29, 2020
@bukka
Copy link
Member

bukka commented Aug 3, 2020

Just noticed this. Can someone tell why was this was add it to php-fpm (just noticed that in changes for 8.0)? This is just CGI, right so this shouldn't impact fastcgi.

Please let me know. Otherwise I will remove the FPM specific changes.

@bukka
Copy link
Member

bukka commented Aug 3, 2020

CC @Ragnoroct @nikic

@nikic
Copy link
Member

nikic commented Aug 3, 2020

I don't think cgi vs fcgi makes a difference here. Not sure whether it's relevant for fpm specifically though.

@bukka
Copy link
Member

bukka commented Aug 3, 2020

Ok it looks that Apache actually passes that variable. I guess it probably makes some sense.

@bukka
Copy link
Member

bukka commented Aug 3, 2020

I mean it sets it for fcgi as well...

@Ragnoroct
Copy link
Author

The bug report said it was happening on PHP-CGI. I've also experienced it on fcgi.

@Ragnoroct
Copy link
Author

Ragnoroct commented Aug 4, 2020

I'm not sure what the question is.

@nikic
Copy link
Member

nikic commented Sep 17, 2020

It looks like using CONTEXT_DOCUMENT_ROOT is not always desirable: https://bugs.php.net/bug.php?id=80113

@Ragnoroct
Copy link
Author

What should we do in this situation? Is it possible to scan both?..

@RealityRipple
Copy link

Can a check be introduced to see if the user_ini_filename value in question is even in a subdirectory of either DOCUMENT_ROOT or CONTEXT_DOCUMENT_ROOT? If both, use CONTEXT_. If one and not the other, you have your answer. If neither... well, hopefully that's functionally impossible (or at least unlikely), but maybe don't traverse any directories at all because something's already not right?

@wf-mattr
Copy link

Or alternately, check if CONTEXT_DOCUMENT_ROOT is a substring of SCRIPT_FILENAME before choosing to use it instead of DOCUMENT_ROOT? I don't have a site with mod_userdir to check the behavior that way, but this would fix the sites I see with CGI configured as described in the PHP bug 80113. @Ragnoroct, is it still possible for this to be addressed before PHP 8.0 is released?

@Ragnoroct
Copy link
Author

Ragnoroct commented Oct 15, 2020 via email

@wf-mattr
Copy link

I have never seen SCRIPT_FILENAME unset myself on cgi, fcgi, mod_php, or the CLI; but I don't know if it is possible in different configurations from what I'm used to. (It is actually an empty string if I run the CLI interactively, but that is expected.)

@bukka
Copy link
Member

bukka commented Oct 18, 2020

There is already a check if doc_root is prefix for path (which is from paht_translated which is effectively SCRIPT_FILENAME without SCRIPT_NAME). What should be done is to refactore the php_cgi_ini_activate_user_config to get context root and document root and compare the prefix first for the context and if it doesn't match, then for the doc root. Then I think it should address the reported issue.

The thing that I don't really like is that this got in without any test. It should be doable to write a test for this in FPM as we have got user.ini tests already. Especially if there is more logic coming, the test is really required IMO.

php-pulls pushed a commit that referenced this pull request Oct 19, 2020
This reverts commit 98bfad7.

This doesn't work well in some setups, see bug #80113 and GH-5051.
Reverting this for now.
@nikic
Copy link
Member

nikic commented Oct 19, 2020

I have reverted this change in c97da0f. We can reland once there is a solution that satisfies all scenarios. But for now, let's get back to the status quo of previous versions.

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

Successfully merging this pull request may close these issues.

6 participants