Skip to content

Use esc_like() when building option-meta LIKE patterns#462

Merged
cbravobernal merged 2 commits into
trunkfrom
fix/option-meta-like-escaping
Jun 12, 2026
Merged

Use esc_like() when building option-meta LIKE patterns#462
cbravobernal merged 2 commits into
trunkfrom
fix/option-meta-like-escaping

Conversation

@cbravobernal

@cbravobernal cbravobernal commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Summary

acf_get_option_meta() builds two wp_options LIKE patterns from a caller-supplied $prefix and escapes them by hand, replacing only the _ character:

$search = str_replace( '_', '\_', "{$prefix}_%" );

That leaves the other LIKE metacharacters (%, and the \ escape character) unescaped, so the prefix is not guaranteed to be matched purely as a literal. WordPress provides $wpdb->esc_like() for exactly this purpose — it escapes %, _ and \.

Change

$search  = $wpdb->esc_like( "{$prefix}_" ) . '%';
$_search = $wpdb->esc_like( "_{$prefix}_" ) . '%';

Escape the literal portion of the pattern, then append the single intended trailing wildcard. Behaviour for ordinary prefixes is unchanged.

Tests

  • Adds tests/php/includes/functions/test-acf-option-meta-like-escaping.php, which captures the generated SQL (via the dbless wpdb query filter, since the query is a no-op under WorDBless) and asserts the prefix is escaped through esc_like().
  • composer test:php: OK. composer test:phpstan: clean. phpcs (changed lines): clean.

Note

This file is derived from upstream; the same change applies there.

Use of AI Tools

This PR was authored by Claude Code (Claude Fable 5) under human direction.

@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 cbravobernal.

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

cbravobernal and others added 2 commits June 12, 2026 12:03
acf_get_option_meta() escaped only the `_` character when constructing
its wp_options LIKE patterns, leaving other LIKE metacharacters in the
caller-supplied prefix unescaped. Switch to $wpdb->esc_like(), the
WordPress primitive for LIKE-clause escaping (it covers `%`, `_` and
`\`), then append the single intended trailing wildcard so the prefix
matches as a literal.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Captures the SQL acf_get_option_meta() generates (via the dbless wpdb
query filter, since the query is a no-op under WorDBless) and asserts
the prefix is escaped through esc_like().

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@cbravobernal cbravobernal force-pushed the fix/option-meta-like-escaping branch from ad05abc to 545412a Compare June 12, 2026 10:03
@cbravobernal cbravobernal changed the title Fix LIKE-wildcard escaping in acf_get_option_meta() (wp_options information disclosure) Use esc_like() when building option-meta LIKE patterns Jun 12, 2026
@cbravobernal cbravobernal merged commit 0fc9c25 into trunk Jun 12, 2026
18 checks passed
@cbravobernal cbravobernal deleted the fix/option-meta-like-escaping branch June 12, 2026 10:11
@cbravobernal cbravobernal added the [Type] Bug Something isn't working label Jun 12, 2026
@cbravobernal cbravobernal modified the milestones: 6.9.0, 6.8.9 Jun 12, 2026
cbravobernal added a commit that referenced this pull request Jun 12, 2026
…low-up to #462) (#467)

* Escape remaining wp_options LIKE patterns with esc_like()

Two legacy code paths built wp_options LIKE patterns from a taxonomy
(and term) and escaped only the `_` wildcard via str_replace(), leaving
`%` and `\` active — the same class as #462:

- acf_form_taxonomy::delete_term() (legacy no-termmeta DELETE)
- acf_upgrade_550_taxonomy() (one-time admin upgrade SELECT)

Both are fed trusted input today (a core delete_term hook's integer term
id / a registered taxonomy name), so neither is reachable with hostile
wildcard bytes; this is parity hardening to the WordPress-standard
$wpdb->esc_like().

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

* Add regression tests for the wp_options LIKE escaping

Captures the SQL each path generates (via the dbless wpdb query filter,
since the query is a no-op under WorDBless) and asserts the dynamic part
is escaped through esc_like(). Confirmed to fail against the pre-fix code.

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

---------

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

[Type] Bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant