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

Relax allowed path restrictions for block metadata collections and make the allowed root list filterable #8130

Open
wants to merge 5 commits into
base: trunk
Choose a base branch
from

Conversation

felixarntz
Copy link
Member

@felixarntz felixarntz commented Jan 15, 2025

This PR implements a solution to allow block metadata collections in additional directories, based on the ideas from the Trac ticket:

  • By default, it allows block metadata collections within the wp-includes directory, as well as the root directories for plugins, must-use plugins, and themes.
  • The list of allowed root directories can be expanded via a new filter wp_allowed_block_metadata_collection_roots.
  • Note: Block metadata collections paths must never exactly match one of the root directories or their parent directories. Otherwise it would be possible to e.g. register a collection for the entire wp-content/plugins directory (or wp-content, or the root directory of WordPress etc.), which then would conflict with other collections within that directory.

Trac ticket: https://core.trac.wordpress.org/ticket/62140


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

Copy link

github-actions bot commented Jan 15, 2025

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props flixos90, swissspidy, gziolo.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copy link

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

Comment on lines 93 to 94
* must-use plugins, and themes. This filter can be used to expand the list, e.g. to custom directories with
* symlinked plugins.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dislike that symlinked plugins only work when using this filter.

That means developers will have to add some extra code to make their plugins work properly during local development or in other more sophisticated server setups.

What stops plugins and themes from just shipping something like add_filter( 'wp_allowed_block_metadata_collection_roots', static function( $roots ) { $roots[] = __DIR__; return $roots; } );?

I bet we'll see plugins in the directory with such code, intentionally or not.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An existing utility function get_block_asset_url is used with all block assets. It covers all the same edge cases discussed, so maybe it would be possible to mirror its functionality with the specific requirements of where the collection roots can live.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dislike that symlinked plugins only work when using this filter.

I have an idea for an alternative solution where this list is used more like a denylist than a mix of denylist and allowlist. That should address the limitation. Currently working on implementing it.

What stops plugins and themes from just shipping something like add_filter( 'wp_allowed_block_metadata_collection_roots', static function( $roots ) { $roots[] = __DIR__; return $roots; } );?

Nothing, but nothing in WordPress Core has ever stopped you from _doing_it_wrong - doesn't mean you should. There are other filters for allowlists that anyone could use to loosen the restrictions in a dangerous way, e.g. allowed_redirect_hosts.

Anyway, I think by using this as purely a denylist we should be able to simplify the usage, while still preventing (by default) the key problem this is supposed to prevent (see https://core.trac.wordpress.org/ticket/62140#comment:25).

…ling for exact matches and parent directories.
@felixarntz felixarntz requested a review from swissspidy January 16, 2025 17:59
@felixarntz
Copy link
Member Author

Ping @mreishus, since you worked on the original code. Would be great to get your review.

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.

3 participants