Closed stevegrunwell closed 3 years ago
@stevegrunwell I have a quick question regarding the Cache_Enabler_Disk::mkdir_p()
method that you created. After going over this again recently I believe I found an issue but wanted to get your feedback in case I'm misunderstanding something and am wrong.
I understand that this method assumes that the directory and its parent should have 0755
permissions and will attempt to update any existing directories. However, the following code would have it return true
if the correct permissions aren't set, right?
For example, if the permissions were 0600
both if
statements would be skipped and true
would be returned. Are both of these if
statements supposed to be !==
instead of ===
?
@coreykn Looking at it again, you're absolutely correct: those should be !==
, not ===
.
(Something something Monday details). I'll get an updated PR together.
@stevegrunwell Looks like a small issue has arisen from this addition: https://wordpress.org/support/topic/error-on-1-7-0-update/
Thought I'd get your feedback again since you are the author. 🙂 Were the $wp_error
variables on line 889 supposed to be $wp_filesystem->errors
, which would get the first error code available, or are we trying to target a specific error in this object for this exception?
Also, is $wp_filesystem->get_error_message
on line 888 supposed to be $wp_filesystem->errors->get_error_message
as $wp_filesystem->errors
is the WordPress Error class?
You're absolutely correct, it should be referencing $wp_filesystem->errors
. I've opened #221 to update it.
To your first question, it's intentionally grabbing the first error in the WP_Error
object.
@stevegrunwell Can you think of any scenario where this is some how going back way to far in terms of parent directory? We use cache enabler on hundreds of sites and almost daily well find 5-10 random sites where there are several endlessly running PHP processes trying to chown the entire filesystem, this eventually fills up PHP error logs.
Example of what we see when running an strace on the PHP processes:
chmod("/sys/dev/char/1:3/subsystem/full/subsystem/full/subsystem/full/subsystem/full/subsystem/full/subsystem/full/subsystem/full/subsystem/full/subsystem/full/subsystem/full/subsystem/zero/subsystem/urandom/subsystem/random/subsystem/random/subsystem/full/subsystem/zero/subsystem/null/subsystem/urandom/subsystem/full/dev", 0755) = -1 EPERM (Operation not permitted
)
followed by endless output to logs:
[11-Jan-2022 22:58:25 UTC] PHP Warning: chmod(): Operation not permitted in /home/nginx/domains/domain.com/public/wp-admin/includes/class-wp-filesystem-direct.php on line 173 [11-Jan-2022 22:58:25 UTC] PHP Warning: chmod(): Operation not permitted in /home/nginx/domains/domain.com/public/wp-admin/includes/class-wp-filesystem-direct.php on line 173 [11-Jan-2022 22:58:25 UTC] PHP Warning: chmod(): Operation not permitted in /home/nginx/domains/domain.com/public/wp-admin/includes/class-wp-filesystem-direct.php on line 173 [11-Jan-2022 22:58:25 UTC] PHP Warning: chmod(): Operation not permitted in /home/nginx/domains/domain.com/public/wp-admin/includes/class-wp-filesystem-direct.php on line 173 [11-Jan-2022 22:58:25 UTC] PHP Warning: chmod(): Operation not permitted in /home/nginx/domains/domain.com/public/wp-admin/includes/class-wp-filesystem-direct.php on line 173 [11-Jan-2022 22:58:25 UTC] PHP Warning: chmod(): Operation not permitted in /home/nginx/domains/domain.com/public/wp-admin/includes/class-wp-filesystem-direct.php on line 173 [11-Jan-2022 22:58:25 UTC] PHP Warning: chmod(): Operation not permitted in /home/nginx/domains/domain.com/public/wp-admin/includes/class-wp-filesystem-direct.php on line 173 [11-Jan-2022 22:58:25 UTC] PHP Warning: chmod(): Operation not permitted in /home/nginx/domains/domain.com/public/wp-admin/includes/class-wp-filesystem-direct.php on line 173 [11-Jan-2022 22:58:25 UTC] PHP Warning: chmod(): Operation not permitted in /home/nginx/domains/domain.com/public/wp-admin/includes/class-wp-filesystem-direct.php on line 173 [11-Jan-2022 22:58:25 UTC] PHP Warning: chmod(): Operation not permitted in /home/nginx/domains/domain.com/public/wp-admin/includes/class-wp-filesystem-direct.php on line 173 [11-Jan-2022 22:58:25 UTC] PHP Warning: chmod(): Operation not permitted in /home/nginx/domains/domain.com/public/wp-admin/includes/class-wp-filesystem-direct.php on line 173 [11-Jan-2022 22:58:25 UTC] PHP Warning: chmod(): Operation not permitted in /home/nginx/domains/domain.com/public/wp-admin/includes/class-wp-filesystem-direct.php on line 173 [11-Jan-2022 22:58:25 UTC] PHP Warning: chmod(): Operation not permitted in /home/nginx/domains/domain.com/public/wp-admin/includes/class-wp-filesystem-direct.php on line 173 [11-Jan-2022 22:58:25 UTC] PHP Warning: chmod(): Operation not permitted in /home/nginx/domains/domain.com/public/wp-admin/includes/class-wp-filesystem-direct.php on line 173 [11-Jan-2022 22:58:25 UTC] PHP Warning: chmod(): Operation not permitted in /home/nginx/domains/domain.com/public/wp-admin/includes/class-wp-filesystem-direct.php on line 173 [11-Jan-2022 22:58:25 UTC] PHP Warning: chmod(): Operation not permitted in /home/nginx/domains/domain.com/public/wp-admin/includes/class-wp-filesystem-direct.php on line 173 [11-Jan-2022 22:58:25 UTC] PHP Warning: chmod(): Operation not permitted in /home/nginx/domains/domain.com/public/wp-admin/includes/class-wp-filesystem-direct.php on line 173 [11-Jan-2022 22:58:25 UTC] PHP Warning: chmod(): Operation not permitted in /home/nginx/domains/domain.com/public/wp-admin/includes/class-wp-filesystem-direct.php on line 173 [11-Jan-2022 22:58:25 UTC] PHP Warning: chmod(): Operation not permitted in /home/nginx/domains/domain.com/public/wp-admin/includes/class-wp-filesystem-direct.php on line 173 [11-Jan-2022 22:58:25 UTC] PHP Warning: chmod(): Operation not permitted in /home/nginx/domains/domain.com/public/wp-admin/includes/class-wp-filesystem-direct.php on line 173 [11-Jan-2022 22:58:25 UTC] PHP Warning: chmod(): Operation not permitted in /home/nginx/domains/domain.com/public/wp-admin/includes/class-wp-filesystem-direct.php on line 173
@jcatello Nothing immediately comes to mind; the Cache_Enabler_Disk::mkdir_p()
method intentionally limits its scope to the passed path and its children, and only gets called as new cache files are getting created.
Is it possible a CACHE_ENABLER_*
constant is misconfigured on those sites, causing Cache Enabler to try to store files outside of its typical locations?
The
wp_mkdir_p()
function will create new directories recursively based on the permissions of the parent directory; in the case of this plugin,wp-content/
.Unfortunately, that function doesn't expose a way to explicitly specify permissions, so a locked-down
wp-content/
directory can result in the directories being created with permissions that don't allow the web server to serve the files.This PR introduces a new
Cache_Enabler_Disk::mkdir_p()
method, which recursively creates the directories and ensures that the newly-created directory has0755
permissions, meaning/cache
,/cache/cache-enabler
,/settings
, and/settings/cache-enabler
will all explicitly be given0755
.Fixes #193.