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

Theme previews: Escape theme activation nonce for output. #52537

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

Conversation

peterwilsoncc
Copy link
Contributor

@peterwilsoncc peterwilsoncc commented Jul 11, 2023

What?

Adds escaping to the nonce output used for activation of themes.

Why?

As the WordPress nonce functions are pluggable, plugins can introduce custom implementations. While the core implementation only uses alphanumeric characters, a custom version may use any number of special characters.

How?

Wraps output in wp_json_encode() -- note the removal of the quotes is intentional as the function adds them automatically.

Testing Instructions

  1. Add an mu-plugin that replaces the nonce create function function wp_create_nonce() { return "';"; }
  2. Visit the theme preview page (be aware this won't load entirely correctly due to the incomplete nonce implimentation)
  3. In the console ensure the constant is set correctly
    >> WP_BLOCK_THEME_ACTIVATE_NONCE
    "';" 
    
  4. Delete the mu-plugin so you don't end up wondering why everything is broken.

Testing Instructions for Keyboard

N/A -- no UI change.

Screenshots or screencast

@peterwilsoncc peterwilsoncc marked this pull request as ready for review July 11, 2023 23:23
Copy link
Member

@ramonjd ramonjd left a comment

Choose a reason for hiding this comment

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

LGTM

Nonce:

Screenshot 2023-07-12 at 12 08 54 pm

With wp_create_nonce overwritten:

Screenshot 2023-07-12 at 12 26 26 pm

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.

2 participants