fix: prevent oEmbed data leaking between posts on nested calls - #23587
Open
si-kui-a wants to merge 1 commit into
Open
fix: prevent oEmbed data leaking between posts on nested calls#23587si-kui-a wants to merge 1 commit into
si-kui-a wants to merge 1 commit into
Conversation
…nse_data calls Open_Graph_OEmbed::set_oembed_data() stored the oEmbed data, post ID, and post meta on shared instance properties instead of local variables. When the oembed_response_data filter fires re-entrantly within the same request (e.g. a theme rebuilding an excerpt by re-running content filters while the outer oEmbed response for a different post is still being assembled), the inner call overwrote the shared state, so the outer call's set_title/ set_description/set_image ran against the wrong post's meta and returned the wrong post's title/description/image -- which then gets cached indefinitely in that post's _oembed_* postmeta. Refactored set_oembed_data() and its three helpers to thread $data and $post_meta through as parameters/return values instead of touching instance state, removing the now-unused $data/$post_id/$post_meta properties entirely (confirmed via GitHub code search that nothing outside this class references them). Added a regression test simulating the nested-call scenario -- it fails against the old code (second post's data leaks into the first) and passes against this fix. Fixes Yoast#23527. No PHP/Composer toolchain is available in this environment, so composer check-branch-cs and the PHPUnit run were not executed locally; the test was hand-traced against the new code instead. Disclosed in the PR body per docs/workflows/create-pr.md step 2. CI will run the full suite. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HG5wiw3Z8QdjNWb5bFDLiA
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.
Context
Open_Graph_OEmbed::set_oembed_data()stored the oEmbed data, the post ID, and the post meta it was working with on shared instance properties ($this->data,$this->post_id,$this->post_meta) instead of local variables. If theoembed_response_datafilter fires re-entrantly within the same request — for example a theme rebuilding an excerpt by re-running content filters for a different post while the outer oEmbed response is still being assembled — the inner call overwrites that shared state. By the time the outer call resumes and runsset_title()/set_description()/set_image(), it operates on the wrong post's meta and returns the wrong post's title/description/image. WordPress then caches that wrong result indefinitely in the original post's_oembed_*postmeta, so the bug outlives the request that caused it.Summary
This PR can be summarized in the following changelog entry:
oembed_response_datafilter fired more than once in the same request.Relevant technical choices:
set_oembed_data()and its three helpers (set_title,set_description,set_image) now thread$dataand$post_metathrough as parameters and return values instead of reading/writing instance state. This makes a single call self-contained regardless of any nested call that happens inside it.$data,$post_id, and$post_metainstance properties entirely rather than keeping them alongside the new parameters — confirmed via GitHub code search (Open_Graph_OEmbedacross the repo) that nothing outside this class reads them, so they were purely internal, now-redundant state.test_set_oembed_data_is_reentrant_safe(), which mocksMeta_Surface::for_post()for post A to trigger a nestedset_oembed_data()call for post B before returning post A's meta — reproducing the exact re-entrancy scenario. It fails against the pre-fix code (post A's result contains post B's title/description) and passes against this fix.composer check-branch-csand the PHPUnit run could not be executed locally. The new test was hand-traced line-by-line against both the old and new implementations instead of run. The existingtest_set_oembed_data_with_no_data_setcases were re-traced the same way and are unaffected by the signature change from the caller's perspective (set_oembed_data()'s public signature is unchanged). Please let CI run the full suite before merge.Test instructions
Test instructions for the acceptance test before the PR gets merged
This PR can be acceptance tested by following these steps:
the_contentmore than once)./wp-json/oembed/1.0/embed?url=<post-url>) and confirm each response'stitle/description/thumbnail_urlmatches that post's own Open Graph settings, not the other post's.Open_Graph_OEmbed_Test), in particular the newtest_set_oembed_data_is_reentrant_safecase.Relevant test scenarios
Test instructions for QA when the code is in the RC
QA can test this PR by following these steps:
Impact check
This PR affects the following parts of the plugin, which may require extra testing:
oembed_response_datafilter) for any post with Open Graph title/description/image set — this is the only integration touched.Other environments
Documentation
Quality assurance
grunt build:imagesand committed the results, if my PR introduces or edits images or SVGs.Innovation
Fixes #23527
🤖 Generated with Claude Code
https://claude.ai/code/session_01HG5wiw3Z8QdjNWb5bFDLiA