Fix stored XSS on order notes in REST API v4#63661
Conversation
Add wp_kses_post sanitize_callback to the note field in the v4 OrderNoteSchema, matching the fix applied to v1/v2/v3 in #63616. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Testing GuidelinesHi @mikejolley @woocommerce/rubik, Apart from reviewing the code changes, please make sure to review the testing instructions (Guide) and verify that relevant tests (E2E, Unit, Integration, etc.) have been added or updated as needed. Reminder: PR reviewers are required to document testing performed. This includes:
|
📝 WalkthroughWalkthroughThese changes add XSS protection to order notes in WooCommerce's REST API v4 by sanitizing note content using Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment Tip CodeRabbit can approve the review once all CodeRabbit's comments are resolved.Enable the |
Test using WordPress PlaygroundThe changes in this pull request can be previewed and tested using a WordPress Playground instance. Test this pull request with WordPress Playground. Note that this URL is valid for 30 days from when this comment was last updated. You can update it by closing/reopening the PR or pushing a new commit. |
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sanitize note content with wp_kses_post() in the v4 OrderNotes controller's create_item method, matching the fix applied to v1/v2/v3 in #63616. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Submission Review Guidelines:
Changes proposed in this Pull Request:
Extends the stored XSS fix from #63616 (which covers REST API v1/v2/v3) to the v4 REST API.
Adds
wp_kses_post()sanitization to the note content in the v4OrderNotes\Controller::create_item()method before passing it toadd_order_note(). This strips dangerous tags like<script>while preserving safe HTML.Note: Unlike the v1 fix which uses
sanitize_callbackin route args viaarray_merge, the v4 fix sanitizes directly increate_item(). This is because v4's schema-driven architecture doesn't usearray_mergeto override endpoint args, and WordPress core'srest_get_endpoint_args_for_schema()hardcodessanitize_callbacktorest_sanitize_request_arg— ignoring anysanitize_callbackset in the schema. Sanitizing at the point of use is cleaner for v4 and provides defense in depth.Also adds a unit test verifying the sanitization behavior.
Screenshots or screen recordings:
N/A
How to test the changes in this Pull Request:
<script>tag:notefield does not contain<script>tags.<b>bold</b>is preserved.Testing that has already taken place:
test_create_item_sanitizes_note_contentverifies XSS payloads are stripped and safe HTML is preserved.Milestone
Changelog entry
Automatically create a changelog entry from the details below.
This Pull Request does not require a changelog entry. (Comment required below)
Changelog Entry Details
Significance
Type
Message
Prevent stored XSS on order notes added via REST API v4
Changelog Entry Comment
Comment