WordPress / WordPress/WordPress-Coding-Standards
Security: ensure second arg of wp_localize_script() is properly escaped
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 2.8k
- Forks
- 521
- Avg merge
- 5d 20h
- Merged PRs (30d)
- 1
Description
The second arg of the wp_localize_script() function, $object_name, is directly interpolated into the JS without any escaping. Per the docs:
* @param string $object_name Name for the JavaScript object. Passed directly, so it should be qualified JS variable.
* Example: '/[a-zA-Z0-9_]+/'.
Believe it or not, some plugins use dynamic object names, even incorporating untrusted data. I think it makes sense add a sniff that requires the value to be properly escaped.
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 by locating the sniff implementations and tests that cover wp_localize_script(), then inspect how arguments are checked for escaping. The change is complete when the $object_name argument is required to be properly escaped, including dynamic values, and the relevant tests verify the rule.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- security, tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100