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

Bypass DISALLOW_FILE_MODS introduced in 2.5.0 #512

Closed
Albvadi opened this issue Mar 14, 2024 · 5 comments
Closed

Bypass DISALLOW_FILE_MODS introduced in 2.5.0 #512

Albvadi opened this issue Mar 14, 2024 · 5 comments
Labels

Comments

@Albvadi
Copy link

Albvadi commented Mar 14, 2024

Description

On my site I have the DISALLOW_FILE_MODS constant activated because I control file modifications through GIT. In this way, I am blocked from editing the theme files, installing / updating WordPress, plugins, themes, etc...

The problem is that with this constant configured, in the latest version of the plugin the error appears indicating that the file system is not writable as checked in

/**
* Determines whether object cache file modifications are allowed.
*
* @return bool
*/
function is_file_mod_allowed() {
return apply_filters(
'file_mod_allowed',
! defined( 'DISALLOW_FILE_MODS' ) || ! DISALLOW_FILE_MODS,
'object_cache_dropin'
);
}
/**
* Test if we can write in the WP_CONTENT_DIR and modify the `object-cache.php` drop-in
*
* @return true|WP_Error
*/
public function test_filesystem_writing() {
/** @var \WP_Filesystem_Base $wp_filesystem */
global $wp_filesystem;
if ( ! $this->is_file_mod_allowed() ) {
return new WP_Error( 'disallowed', __( 'File modifications are not allowed.', 'redis-cache' ) );
}

image

I don´t consider that writing the object-cache.php file to manage the cache should be prohibited even if the rest of the modifications to WordPress files are.

Expected Behavior

Can enable Redis cache with DISALLOW_FILE_MODS

Actual Behavior

Filesystem not writable error

Possible Fix

Not sure. Maybe create a new constant like WP_REDIS_SKIP_DISABLE_FILE_MODS or something like that. Or maybe use the actual WP_REDIS_DISABLE_DROPIN_CHECK to skip DISALLOW_FILE_MODS.

Steps to Reproduce

  1. Install new wordpress site and add the plugin
  2. Configure DISALLOW_FILE_MODS to true in wp-config.php
  3. Trye to enable plugin

Additional context

Environment

  • Plugin version: 2.5.1
  • PHP version: 7.4.30
  • WordPress version: 6.4.3
@Albvadi Albvadi added the bug label Mar 14, 2024
@tillkruss
Copy link
Member

Right, when DISALLOW_FILE_MODS this doesn't need to be a red warning. We we just gray it out?

Because the "Enable Cache" button will be disabled regardless if DISALLOW_FILE_MODS is set.

@Albvadi
Copy link
Author

Albvadi commented Mar 15, 2024

Right, when DISALLOW_FILE_MODS this doesn't need to be a red warning. We we just gray it out?

Yes and no... You can have DISALLOW_FILE_MODS and at the same time (that was my case), have permissions problems in your server and the filesystem not be writeable too.

What I try to say it´s that are two totally different cases and should be treated that way.

For example, as I said, in my server I uploaded all files with my user and the server is running with apache user. I detected it becauses when I try to enable cache, It´s says the filesystem is not writable and I need a sysadmin to correcte the permissions.

And then, If I enable DISALLOW_FILE_MODS I can't enable cache it either becauses in the test writable filesystem is checking if the constant is defined, but it´s not a problem with the writability of the system.

I need any way to enable cache with DISALLOW_FILE_MODS, that's why I suggested adding a new constant that, when checking the system, can allow the cache to be activated even with DISALLOW_FILE_MODS defined, such as WP_REDIS_SKIP_DISABLE_FILE_MODS

And, sorry for my language, it's difficult to explain well when it's not your native language.

@tillkruss
Copy link
Member

Thanks for the details!

If DISALLOW_FILE_MODS WordPress should not modify the filesystem and the only way to enable the object-cache.php drop-in is using the wp redis enable command. Or of course copying it by hand.

I think you're right. If DISALLOW_FILE_MODS the warning should not be so aggressive.

@tillkruss tillkruss closed this as not planned Won't fix, can't repro, duplicate, stale Mar 15, 2024
@Albvadi
Copy link
Author

Albvadi commented Mar 19, 2024

Thank you for your explanation. One last question.

If DISALLOW_FILE_MODS WordPress should not modify the filesystem and the only way to enable the object-cache.php drop-in is using the wp redis enable command. Or of course copying it by hand.

I believed that in order to activate the cache it was necessary to be able to write to the object-cache.php file and by not allowing writing with DISALLOW_FILE_MODS, it was not going to work.

So, can I activate the cache with the wp redis enable command and/or copying the file by hand and even if it is DISALLOW_FILE_MODS defined, will it still work? Because if that's the case and I can activate it from the console, for me it is the solution.

Thank you very much again.

@tillkruss
Copy link
Member

Yep, that works!

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

No branches or pull requests

2 participants