Skip to content

Themes API: Validate actions and protocol input, document trusted output paths - #801

Open
obenland wants to merge 8 commits into
WordPress:trunkfrom
obenland:api/security-themes
Open

Themes API: Validate actions and protocol input, document trusted output paths#801
obenland wants to merge 8 commits into
WordPress:trunkfrom
obenland:api/security-themes

Conversation

@obenland

Copy link
Copy Markdown
Member

Part of a sweep resolving all WordPress.Security PHPCS findings on the unauthenticated api.wordpress.org endpoints.

  • API actions are validated against their expected [a-z_] format across 1.0 and 1.2.
  • SERVER_PROTOCOL is format-validated before being echoed into status headers.
  • JSONP callbacks are sanitized at the source in 1.1.
  • The serialized/JSON response paths carry narrow justified ignores (escaping would corrupt the payloads), and parsing the request before WordPress loads is documented via justified file-level unslash/nonce disables.

All files report zero WordPress.Security violations.

🤖 Generated with Claude Code

Copilot AI lite review requested due to automatic review settings August 13, 2026 01:06
@github-actions

Copy link
Copy Markdown

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 props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props obenland.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens the unauthenticated Themes API endpoints by validating user-controlled inputs (actions, protocol strings, JSONP callback) and adding narrowly scoped PHPCS ignores where escaping/sanitizing would corrupt serialized/JSON payloads or where WordPress isn’t loaded yet.

Changes:

  • Adds stricter validation for SERVER_PROTOCOL and action parameters in the Themes Info endpoints (1.0/1.2).
  • Documents and justifies output-not-escaped paths for JSON/serialized responses and pre-WordPress request parsing.
  • Sanitizes CORS origin and JSONP callback handling paths, adding targeted PHPCS ignores.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
api.wordpress.org/public_html/themes/theme-directory/1.0/index.php Sanitizes Origin/JSONP callback output and refactors action/nonce/theme input handling for authenticated theme-favorite actions.
api.wordpress.org/public_html/themes/info/1.2/index.php Adds file-level PHPCS rationale and validates protocol/action when normalizing “flat” GET requests before delegating to 1.1.
api.wordpress.org/public_html/themes/info/1.1/index.php Adds file-level PHPCS rationale, refines JSONP callback sanitization, and documents trusted output of 1.0 payload.
api.wordpress.org/public_html/themes/info/1.0/index.php Documents pre-WordPress request parsing, validates SERVER_PROTOCOL and action, and adds justified output/unsanitized-input ignores for serialized/JSON payloads.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread api.wordpress.org/public_html/themes/theme-directory/1.0/index.php Outdated
Comment thread api.wordpress.org/public_html/themes/theme-directory/1.0/index.php Outdated
Comment thread api.wordpress.org/public_html/themes/info/1.1/index.php Outdated
Comment thread api.wordpress.org/public_html/themes/info/1.2/index.php
@obenland
obenland force-pushed the api/security-themes branch 3 times, most recently from 0a0aba4 to 04e75ba Compare August 13, 2026 01:23
…put paths.

API actions are validated against their expected format, the server
protocol is validated before being echoed into status headers, and
JSONP callbacks are sanitized at the source. The serialized/JSON
response paths carry narrow, justified ignores since escaping would
corrupt the payloads, and request parsing before WordPress loads is
documented via justified file-level unslash/nonce disables.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
(cherry picked from commit 5c8b73f740980cc1047bcbba93c09ec636feff3a)
@obenland
obenland force-pushed the api/security-themes branch from 04e75ba to fe7ccd6 Compare August 13, 2026 01:28
JSONP callbacks that are not valid JavaScript identifiers (e.g.
starting with a digit) now fall back to plain JSON instead of emitting
invalid script. The theme-directory action and theme parameters are
validated against their expected formats and rejected when malformed,
rather than sanitize_key() silently transforming a malformed value
into a valid one — which had made `add-favorite@@` executable where
trunk rejected it. The 1.2 endpoint now rejects every non-GET/HEAD
method, not just POST. Inline ignores are restored to single-line
form, since an annotation inside a multi-line block comment does not
apply to the code following the comment.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@obenland
obenland requested a lite review from Copilot August 13, 2026 01:43

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

obenland and others added 6 commits August 12, 2026 20:51
…ocks.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Replaces the strip-then-check-first-character dance with one
identifier validation; a callback that isn't a valid JavaScript
identifier falls back to plain JSON instead of being partially
salvaged into a different (wrong) function name.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…s justification.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…ites.

An invalid or array `theme` parameter was coerced to an empty string
or false by the validation fallback and still written to the user's
favorites meta with a success response; it now returns bad_request.
The slug pattern also allows underscores, which
sanitize_title_with_dashes() preserves and the themes info endpoint
already accepts. The 1.2 method guard no longer rejects OPTIONS —
trunk served preflights — and the Allow header lists the permitted
methods.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
PCRE's $ end-anchor matches before a trailing newline, letting values
like "twentytwenty\n" pass slug and protocol validation.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants