Theme Directory: Validate the locale parameter in the themes API. - #745
Closed
obenland wants to merge 1 commit into
Closed
Theme Directory: Validate the locale parameter in the themes API.#745obenland wants to merge 1 commit into
obenland wants to merge 1 commit into
Conversation
The themes API accepts a `locale` request parameter and filters it into `get_locale()` for the remainder of the request, but the only check it receives is `is_scalar()`, so any string is used as-is. Validate it with `sanitize_locale_name()` and fall back to the site default when it isn't a well-formed locale name, matching how the `locale-detection` plugin already handles its `locale` parameter. The check lives in the constructor alongside the other request filtering so it covers every caller: the `themes/info/1.x` endpoints, the `themes/1.x` REST routes, and internal `wporg_themes_query_api()` calls. Adds tests for the constructor's request handling. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The themes API accepts a
localerequest parameter and filters it intoget_locale()for the remainder of the request. The only check it currently receives isis_scalar(), so any string is passed through and used as-is.This validates it with
sanitize_locale_name()and falls back to the site default when the value isn't a well-formed locale name. That matches how thelocale-detectionplugin already handles its ownlocaleparameter on these sites.Notes
Themes_API::__construct()is the shared funnel for thethemes/info/1.xendpoints, thethemes/1.xREST routes, and internalwporg_themes_query_api()calls. A route-levelargsschema would only cover the REST routes — theinfo/1.xendpoints are plain PHP and also accept a serialized POST body.bad_input. Flagging it would turn requests that currently succeed into 400s for clients sending values likede_DE.UTF-8, which seemed like the wrong trade for this change.de_DE,ca,bal,de_DE_formal, andzh-Hansall pass through unchanged.Tests
Adds
tests/Themes_API_Test.php, covering the constructor's request handling as a whole: scalar-only fields, locale validation, favorites requests, array-of-string fields, andfieldsnormalisation.Full suite passes at 36 tests / 72 assertions. Reverting the production change fails 10 of the new tests and leaves the other 15 green, so the added coverage isn't coupled to the change.
🤖 Generated with Claude Code