REST API: Allow inline rich text in Notes content#11843
Conversation
Notes (block-comment type) ship a lightweight rich-text input from Gutenberg supporting bold, italic, links, and inline code. Regular `pre_comment_content` sanitization (`wp_filter_kses`) would strip those tags for users without the `unfiltered_html` capability. Install a narrower, note-specific kses allowlist on `pre_comment_content` for the duration of any REST request that targets a note, leaving non-note comments on their existing filter chain. Force `rel="noopener nofollow"` on outbound links via the HTML API to prevent SEO manipulation and window.opener attacks. Backports the server-side piece of Gutenberg PR WordPress/gutenberg#78242. Props adamsilverstein, mamaduka, jasmussen. See #XXXXX.
|
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 Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Trac Ticket MissingThis pull request is missing a link to a Trac ticket. For a contribution to be considered, there must be a corresponding ticket in Trac. To attach a pull request to a Trac ticket, please include the ticket's full URL in your pull request description. More information about contributing to WordPress on GitHub can be found in the Core Handbook. |
Test using WordPress PlaygroundThe 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
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
Replace the preg_replace_callback rewrite of <a rel="..."> with WP_HTML_Tag_Processor. The HTML API handles attribute quoting and edge cases (multiple/duplicated rels, attribute-name boundaries) without the regex risk, and matches the core backport in WordPress/wordpress-develop#11843.
Summary
Backports the server-side piece of Gutenberg PR WordPress/gutenberg#78242, which adds a minimal rich-text input to Notes (bold/italic/link/code) in the editor. Without a matching server-side filter, the default `pre_comment_content` sanitization (`wp_filter_kses`) strips those tags for users without `unfiltered_html`.
This change installs a narrower, note-specific kses allowlist on `pre_comment_content` for the duration of any REST request that targets a note, leaving non-note comments on their existing filter chain. Outbound links get a forced `rel="noopener nofollow"` normalized via the HTML API.
What changed
Why HTML API (not regex)
The Gutenberg compat version used a regex to rewrite ``. The core version uses `WP_HTML_Tag_Processor` per the project guidance to favor WordPress APIs over native PHP APIs, and to handle quoting/attribute edge cases correctly.
Testing
Manual
Trac
Needs a Trac ticket — the test annotations use `@ticket XXXXX` as a placeholder. Will swap in the real number once filed.
Related