Add: Global styles user content escaping #1821
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds global styles user content escaping porting the logic we had on the Gutenberg plugin implemented on WordPress/gutenberg#28061 to the core.
The logic tries to follow what was done for normal post content.
Testing
With an admin user with unfiltered HTML capability I tested I was able to pass store unsafe content on global styles by storing an SVG as background using the gradient property:
I reloaded the post editor and frontend and verified an SVG was being used as background.
I removed the unfiltered HTML capability from the admin, by adding the following code in a file that is executed everywhere on WordPress.
I issued the same request:
I verified the text color style was applied but the unsafe gradient rule was discarded.
I readded the unfiltered_html to adding by adding the following code in a file that is executed everywhere on WordPress:
Questions:
Why use this mechanism instead of filtering and escaping the content on the endpoints?
There are other situations where a user may write a global styles CPT without using the endpoint. For example during a site import. A user without unfiltered_html capability may import a website and in that case, it makes sense to import the styles. If there is unsafe content on the styles we want to remove it. We may have other situations that we may not even be aware so trying to replicate what happens for HTML seems like a good option.