Skip to content

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

Closed
peterwilsoncc wants to merge 1 commit into
trunkfrom
fix/theme-preview-escape-nonce
Closed

peterwilsoncc wants to merge 1 commit into
trunkfrom
fix/theme-preview-escape-nonce

Conversation

@peterwilsoncc

@peterwilsoncc peterwilsoncc commented Jul 11, 2023 •

Copy link
Copy Markdown
Contributor

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

@ramonjd ramonjd left a comment

Copy link
Copy Markdown
Member

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

@youknowriad

Copy link
Copy Markdown
Contributor

Thanks @peterwilsoncc for catching this! The Gutenberg compat copy of theme-previews.php was removed in #56464, and Core's wp_block_theme_activate_nonce() already outputs the nonce through wp_json_encode(). Nothing is left to change here, so I'm closing this.

@youknowriad youknowriad closed this Oct 8, 2026
@youknowriad
youknowriad deleted the fix/theme-preview-escape-nonce branch October 8, 2026 10:34
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