Use esc_like() when building option-meta LIKE patterns#462
Merged
Conversation
|
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. |
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>
ad05abc to
545412a
Compare
This was referenced 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>
This was referenced Jun 12, 2026
Merged
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.
Summary
acf_get_option_meta()builds twowp_optionsLIKEpatterns from a caller-supplied$prefixand escapes them by hand, replacing only the_character:That leaves the other
LIKEmetacharacters (%, 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
Escape the literal portion of the pattern, then append the single intended trailing wildcard. Behaviour for ordinary prefixes is unchanged.
Tests
tests/php/includes/functions/test-acf-option-meta-like-escaping.php, which captures the generated SQL (via the dblesswpdbquery filter, since the query is a no-op under WorDBless) and asserts the prefix is escaped throughesc_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.