WordPress / WordPress/WordPress-Coding-Standards

Security: ensure second arg of wp_localize_script() is properly escaped

Open
#1,253 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Component: Extra Focus: Security Type: Enhancement
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.