Skip to content

Escape remaining wp_options LIKE patterns with esc_like() (parity follow-up to #462)#467

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

Escape remaining wp_options LIKE patterns with esc_like() (parity follow-up to #462)#467
cbravobernal merged 2 commits into
trunkfrom
fix/like-escaping-parity

Conversation

@cbravobernal

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #462. A scoping pass found two more legacy code paths that build wp_options LIKE patterns and escape only the _ wildcard via str_replace( '_', '\_', … ), leaving % and the \ escape character active — the same pattern that #462 fixed:

  • includes/forms/form-taxonomy.phpacf_form_taxonomy::delete_term() (a DELETE … WHERE option_name LIKE), on the legacy pre-termmeta path.
  • includes/upgrades.phpacf_upgrade_550_taxonomy() (a one-time admin SELECT … LIKE).

Both migrate to $wpdb->esc_like(), which escapes %, _ and \.

Reachability

Neither is reachable with hostile wildcard bytes today: delete_term()'s $term is the integer term id passed by core's delete_term action and $taxonomy is a registered taxonomy name; acf_upgrade_550_taxonomy() runs only during an admin-triggered one-time DB upgrade with a registered taxonomy name. This is parity hardening so the whole codebase uses the correct primitive — not a fix for a live, untrusted-input-reachable issue.

Tests

Adds tests/php/includes/test-like-escaping-parity.php, which captures the SQL each path generates (the queries are no-ops under WorDBless) and asserts the dynamic part is escaped through esc_like(). Both tests were confirmed to fail against the pre-fix code.

  • composer test:php: OK (2825 tests). composer test:phpstan: clean. phpcs (changed lines): clean.

Note

These files are derived from upstream; the same change applies there.

Use of AI Tools

Authored by Claude Code (Claude Fable 5) under human direction.

cbravobernal and others added 2 commits June 12, 2026 14:10
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>
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>
@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 cbravobernal added this to the 6.8.9 milestone Jun 12, 2026
@cbravobernal cbravobernal added the [Type] Bug Something isn't working label Jun 12, 2026
@cbravobernal cbravobernal merged commit f1a19cb into trunk Jun 12, 2026
19 checks passed
@cbravobernal cbravobernal deleted the fix/like-escaping-parity branch June 12, 2026 12:13
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