Repository navigation
Fix: sanitize field_id input and escape rel attribute in oEmbed handler #1559
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jtsternberg
merged 7 commits into
CMB2:develop
from
thisismyurl:fix/oembed-field-id-sanitize-escape
Jun 4, 2026
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6d0f7d0
Fix: sanitize field_id input and escape rel attribute in oEmbed handler
thisismyurl 7e91829
Fix: add is_string() guard before sanitize_text_field() on field_id
thisismyurl 739949f
Test: assert field_id is escaped in oEmbed rel attribute
jtsternberg 217c6f4
Fix: guard and sanitize $_REQUEST['object_id'] in oEmbed handler
jtsternberg c95d013
Refactor: wp_unslash() oembed_url before sanitize for consistency
jtsternberg 05c3bef
Revert redundant is_string() guard on field_id; prove array-safety wi…
jtsternberg 3a06cbf
Test: reset CMB2_Ajax singleton state in tear_down to prevent leak
jtsternberg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Revert redundant is_string() guard on field_id; prove array-safety wi…
…th a test 7e91829 added `&& is_string( $_REQUEST['field_id'] )` to guard against a claimed PHP 8 TypeError from sanitize_text_field( wp_unslash( array ) ). That premise is incorrect: WordPress's _sanitize_text_fields() returns '' for array/object input (wp-includes/formatting.php), and wp_unslash() (stripslashes_deep → map_deep) is array-safe. So the existing isset() guard already collapses an array field_id to the empty-string default with no error, on every supported WP (the array/object early-return has been in core since WP 4.7; CMB2 supports WP 6.3+). Restore the clean isset() + sanitize_text_field( wp_unslash() ) pattern, keeping field_id consistent with the object_id line. Adds test_oembed_handler_handles_array_field_id, which drives oembed_handler() with field_id = array(...) and asserts it returns success with an empty rel="" (no PHP error). Verified green both with the guard present and after removing it, proving the removal is behavior-preserving and pinning the behavior so the guard is not reintroduced on the same false premise. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- Loading branch information
commit 05c3bef1fb2288697b24ac09315f0fa2960cd69e
There are no files selected for viewing
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
$_REQUEST['field_id']is passed as an array (e.g.,?field_id[]=value), passing it directly towp_unslash()andsanitize_text_field()will trigger a PHP warning or aTypeErroron PHP 8.x becausesanitize_text_field()expects a string.To ensure robustness and prevent potential crashes on PHP 8.x, verify that the input is a string using
is_string()before sanitizing.