Skip to content

Prevent endless expansion of cyclic synced patterns - #126

Merged
ingeniumed merged 3 commits into
trunkfrom
ingeniumed/audit-01-synced-patterns
Nov 19, 2026
Merged

ingeniumed merged 3 commits into
trunkfrom
ingeniumed/audit-01-synced-patterns

Conversation

@ingeniumed

Copy link
Copy Markdown
Contributor

Description

A synced pattern can reference itself, directly or through another pattern. WordPress stops these cycles while rendering, but this plugin subsequently loads the referenced patterns again to extract their blocks. That starts the cycle again after core’s recursion guard has finished, allowing an API request to keep expanding the same patterns rather than complete.

Track pattern references along the current ancestor path and stop expanding a reference already on that path. Separate occurrences of the same pattern remain supported.

The plugin also unnecessarily reloads and renders pattern children that WordPress 6.9+ already retains. Reuse those rendered children instead. WordPress 6.8 still needs the existing compatibility path, so its second rendering pass remains unchanged.

Scenario Before After
Pattern references itself, directly or indirectly API traversal repeatedly expands the cycle Traversal stops at the repeated reference
Same pattern appears in separate sibling blocks Both occurrences returned Both occurrences still returned
Pattern children on WordPress 6.9+ Loaded and rendered again Reuse core’s rendered children
Pattern children on WordPress 6.8 Rendered again for extraction Existing compatibility behavior preserved

Screenshots are not applicable to this API change.

Steps to Test

Run against WordPress 6.8, 6.9 and 7.1:

composer phpcs
composer test
composer test-multisite

The regression tests cover direct and indirect cycles, repeated sibling references, render counts, reentrant parsing, and blocks generated inside dynamic callbacks.

@ingeniumed
ingeniumed requested a review from a team as a code owner November 18, 2026 02:32
@ingeniumed ingeniumed self-assigned this Nov 18, 2026
Comment thread src/parser/content-parser.php Resolved
Comment thread src/parser/content-parser.php Resolved
Comment thread src/parser/content-parser.php Resolved

@alecgeatches alecgeatches left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ingeniumed Cool audit and fix! Added some suggestions to make comments and variable names a bit clearer about what's happening, and an odd recursion bug that's still possible.

@ingeniumed
ingeniumed merged commit b875cb2 into trunk Nov 19, 2026
20 checks passed
@ingeniumed
ingeniumed deleted the ingeniumed/audit-01-synced-patterns branch November 19, 2026 20:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants