Skip to content

Improve advanced cache file may be writable while directory may not #344

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

8ctopus
Copy link

@8ctopus 8ctopus commented May 6, 2025

This pull request addresses an issue where the advanced-cache.php file is not created because WP_CONTENT_DIR is not writable by the PHP process.

The installation is based on Roots Bedrock. For security reasons, file ownership was set to ubuntu:ubuntu, and PHP runs as www-data. As a result of this architecture, the create_advanced_cache_file function returns false.

public static function create_advanced_cache_file() {
if ( ! is_writable( WP_CONTENT_DIR ) ) {
return false;
}

Here’s a snapshot of the directory structure:

la /srv/wordpress/web/app
total 20
drwxrwxr-x  5 ubuntu ubuntu 4096 May  5 13:57 .
drwxrwxr-x  4 ubuntu ubuntu 4096 May  5 07:29 ..
lrwxrwxrwx  1 ubuntu ubuntu   49 May  5 13:57 advanced-cache.php -> ../../../storage/cache-enabler/advanced-cache.php
lrwxrwxrwx  1 ubuntu ubuntu   14 Jul 17  2023 cache -> ../../../cache
drwxrwxr-x  3 ubuntu ubuntu 4096 Apr  6  2023 mu-plugins
drwxrwxr-x 11 ubuntu ubuntu 4096 May  5 07:35 plugins
drwxrwxr-x  4 ubuntu ubuntu 4096 Jul 10  2023 themes
lrwxrwxrwx  1 ubuntu ubuntu   19 Jul 17  2023 uploads -> ../../../wp-uploads

In this setup, WP_CONTENT_DIR itself isn't writable by www-data, but the actual advanced-cache.php file is writable thanks to the symlink pointing to a directory owned by www-data.

Removing the above code block should have no consequences as the return value of the file_put_contents function is checked later on.

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

Successfully merging this pull request may close these issues.

1 participant