Widget Options 4.2.6.1: A Marker Regex Divergence That Wiped Content on Save (CVE-2026-116615)
Widget Options 4.2.6.1 parsed its legacy freeform marker with two different regexes on save and render, so crafted content could be deleted on save while the renderer read a different string. Here is the root cause and how 4.2.7 fixes it.
On this page6
The marker that has two interpreters#
Widget Options supports a legacy "freeform" marker embedded directly in post_content:
<!--start_widgetopts {"class":{"logic":"<php expression>"}} end_widgetopts-->
The class.logic field is a PHP expression later evaluated by widgetopts_safe_eval() to decide whether a block renders. Because that is a privileged capability, the plugin strips class.logic from these markers for non-admin authors on every save path — wp_insert_post_data, rest_pre_insert_post, and rest_request_before_callbacks.
The defect is that the save-time strip and the render-time parser used two different regular expressions for the same marker. The save path matched with a greedy /<!--start_widgetopts\s+([\s\S]*?)\s*end_widgetopts-->/U form in widgetopts_strip_logic_from_blocks() (includes/widgets/gutenberg/gutenberg-toolbar.php), while the render path in blockopts_filter_before_display() used a different, permissive pattern and a str_replace-based extraction. Same input syntax, two incompatible interpretations.
What the greedy match actually did#
Both patterns were greedy over the marker body — the U modifier inverts laziness into greediness, and the render-side [\w\W]* is greedy by construction. A chunk containing two markers therefore matched as one span from the first <!--start_widgetopts to the last end_widgetopts-->.
The captured text is then no longer a single JSON value, so json_decode() fails. The save-time callback attempted a "last }" recovery; if the captured text still contained marker text (for example an inner end_widgetopts-->), that recovery also failed and the callback returned ''. preg_replace_callback() consequently deleted the entire matched region — including any benign content that sat between the two markers — and set $changed, so the corrupted content was written to the database.
Meanwhile the render-time parser reasoned about a different string than the one the save side sanitised. The result is a parsing differential: sanitisation and rendering never agree on what the marker payload is, so the non-admin logic-stripping guard stops corresponding to what actually executes. A single parse/strip/serialise pass is also not idempotent, so a marker skipped in pass one could reappear in pass two.
Root cause and the 4.2.7 fix#
The root cause is not the regex alone but the duplication of parsing logic across two call sites. The Radar entry records the affected range as <= 4.2.6.1 and the patched release as 4.2.7. The patch removes the divergence structurally:
- A shared
widgetopts_freeform_marker_pattern()returns one lazy pattern (noUmodifier), so([\s\S]*?)matches the first closer — the same span the render side now uses. - A shared
widgetopts_decode_freeform_marker()trims the payload, rejects any nested<!--start_widgetoptsopener as illegitimate, and returns the decoded array ornull. widgetopts_strip_logic_from_content()now loops the block-level strip up to five times until the content is stable, and if it will not converge, replaces<!--start_widgetoptswith<!--widgetopts-disabledand runs a final attribute-only pass.- Invalid markers are left untouched instead of deleted, and re-encoding uses
wp_json_encode($data, JSON_HEX_TAG)so a re-encoded payload can never contain marker delimiters. - The render-time parser is switched to the same shared pattern and decoder, so the render side can never see a payload the save side skipped.
Detecting this class of bug in your own plugins#
The transferable signal is two regexes for one syntax. If your plugin parses the same string on save and on render, that is a latent parsing differential. Practical checks:
- Grep for any
preg_match/preg_replacepair that targets the same delimiter on both the save and render paths; if the patterns are not literally the same function, treat it as unverified. - Audit every
Umodifier on a([\s\S]*?)capture: withUyou have inverted the laziness you probably wanted, and multi-marker input will collapse into one match. - Watch for
return '';inside apreg_replace_callback()on user-controlledpost_content— that is a delete-by-accident primitive, not a sanitiser. - Check whether the strip loop is idempotent. A single pass over re-serialised blocks can produce new markers that a second pass would have caught.
- On the defender side, log
post_contentmutations wherestrlen()drops sharply on a non-admin save; that is the observable fingerprint of this failure mode.
Prevention: one parser, one decoder, one loop#
Fixing individual regexes does not close this class. The pattern that does is to own a single parse/serialise pair and use it on every code path — save, render, REST, and CLI. In the Widget Options case that meant extracting the pattern and the decoder into named helpers and pointing both call sites at them.
Two design rules generalise beyond this plugin. First, make sanitisation convergent: loop the strip until $changed is false, with a hard cap and a safe fallback when convergence is impossible. Second, encode defensively on the way out — JSON_HEX_TAG guarantees the re-serialised payload cannot reintroduce the delimiter it just removed.
The bug is not the regex; it is that two code paths were allowed to disagree about what a stored string means, so any fix that patches only one of them is incomplete by construction.
Vulnerabilities covered
| Severity | Vulnerability | CVE | Published |
|---|---|---|---|
| High8.8 | Authenticated (Contributor+) Code Injection via 'post_content' Parameter | CVE-2026-116615 |
- High8.8VulnCrest analysisAuthenticated (Contributor+) Code Injection via 'post_content' Parameter
Widget Options
≤4.2.6.1Update to 4.2.7
