Skip to content

Translations API: Sanitize slug and version input - #800

Open
obenland wants to merge 4 commits into
WordPress:trunkfrom
obenland:api/security-translations
Open

Translations API: Sanitize slug and version input#800
obenland wants to merge 4 commits into
WordPress:trunkfrom
obenland:api/security-translations

Conversation

@obenland

Copy link
Copy Markdown
Member

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

  • Slugs and versions only feed prepared queries, cache keys, and version comparisons, so control characters are stripped rather than enforcing a format that could reject valid language-pack lookups; non-scalar input is still rejected with a 400.
  • Raw SERVER_PROTOCOL usage in error responses is replaced with http_response_code().
  • Nonce/unslash sniffs are disabled per file with justification: standalone endpoints, WordPress is not loaded.

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:05
@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 tightens input handling for the public Translations API endpoints on api.wordpress.org by sanitizing slug/version inputs and standardizing 400 responses via http_response_code() (instead of relying on $_SERVER['SERVER_PROTOCOL']), with PHPCS security sniff exceptions documented for these standalone endpoints.

Changes:

  • Add inline PHPCS rationale for nonce/unslash sniffs on standalone unauthenticated endpoints.
  • Sanitize slug and/or version inputs by stripping low ASCII control characters before use.
  • Replace status-line header construction with http_response_code( 400 ) and harden the HEAD request check.

Reviewed changes

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

File Description
api.wordpress.org/public_html/translations/themes/1.0/index.php Adds slug/version sanitization and uses http_response_code() for invalid parameter handling.
api.wordpress.org/public_html/translations/plugins/1.0/index.php Mirrors themes endpoint sanitization and 400 response handling updates.
api.wordpress.org/public_html/translations/core/1.0/index.php Sanitizes version, switches to http_response_code(), and avoids undefined REQUEST_METHOD notices.

💡 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/translations/plugins/1.0/index.php Outdated
Comment thread api.wordpress.org/public_html/translations/core/1.0/index.php
Comment thread api.wordpress.org/public_html/translations/themes/1.0/index.php Outdated
@obenland
obenland force-pushed the api/security-translations branch 3 times, most recently from d032ee3 to fc71481 Compare August 13, 2026 01:23
Slugs and versions only feed prepared queries, cache keys, and version
comparisons, so control characters are stripped rather than enforcing
a format that could reject valid language-pack lookups. Non-scalar
input is still rejected with a 400. Replaces raw SERVER_PROTOCOL
usage in error responses with http_response_code().

Nonce and unslash sniffs are disabled per file with justification:
these are standalone, unauthenticated endpoints where WordPress (and
thus slashing and nonces) does not exist.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
(cherry picked from commit 9a121053234437016566dd01d7c7118520fac1a6)
@obenland
obenland force-pushed the api/security-translations branch from fc71481 to 0a4616f Compare August 13, 2026 01:28
obenland and others added 3 commits August 12, 2026 20:51
… docblocks.

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

FILTER_FLAG_STRIP_LOW left spaces and high bytes intact, and those
values flow into memcached cache keys, which reject them — so a
request like ?version=1%20x bypassed the cache entirely and hit the
database on every request. Values outside [A-Za-z0-9._-] now get the
existing 400 response instead.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
PCRE's $ end-anchor matches before a trailing newline, which would
have let a newline back into the memcached cache keys these values
were just validated for.

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