-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 NEFARIOUSPLAN-CANONICAL-V1 {"body_md":"## The mfunc feature runs eval() on the content of HTML comments\n\nW3 Total Cache ships a feature called Dynamic Fragment Caching. The plugin's own developer notes describe it as the way to keep one snippet of a cached page live while everything around it stays static. Developers wrap a piece of PHP in HTML comments using a tag form ``. When W3TC serves the page from cache, it scans the cached HTML for that tag, extracts the PHP between the opening and closing comments, and passes it to `eval()`. The eval output replaces the comment in the response.\n\nThe \"security\" of this feature is a token. The site administrator defines `W3TC_DYNAMIC_SECURITY` in `wp-config.php` and the tag must carry that token between `mfunc` and the code. If the token is absent or wrong, the comment is supposed to pass through unprocessed. The threat model: legitimate plugin authors who know the token embed dynamic snippets; everyone else cannot reach `eval()`.\n\nThe threat model breaks when two regexes disagree about what counts as a tag.\n\n## Two regexes for the same tag\n\n`strip_dynamic_fragment_tags_from_string()` lives in `Generic_Plugin.php`. W3TC registers it as a filter on `preprocess_comment`, `the_content_feed`, `the_excerpt_rss`, and `comment_text_rss`. Anywhere user-supplied content can land in the published page, this function gets a pass at it. Its job is to remove any mfunc or mclude tag before the content reaches cache.\n\n```php\n// Generic_Plugin.php, 2.9.1\nprivate function strip_dynamic_fragment_tags_from_string( $value ) {\n if ( ! is_string( $value ) || ! defined( 'W3TC_DYNAMIC_SECURITY' ) || empty( W3TC_DYNAMIC_SECURITY ) ) {\n return $value;\n }\n\n $pattern = array(\n '~(.*?)~Uis',\n '~(.*?)~Uis',\n );\n // preg_replace_callback over $pattern follows.\n}\n```\n\nThe strip function does not know what the security token is. It cannot. The same code runs against every comment and every feed item, indifferent to which token the administrator configured. So its regex slots the token as `[^\\s]+`, one or more non-whitespace characters. Any non-whitespace placeholder in the token position counts. The strip is meant to be defense in overcorrection: strip anything that looks like an mfunc tag, regardless of which token sits in the slot.\n\n`_parse_dynamic()` in `PgCache_ContentGrabber.php` is the executor. It runs on the cache-serve path. Its regex is built differently:\n\n```php\n// PgCache_ContentGrabber.php, 2.9.1\n$buffer = preg_replace_callback(\n '~(.*)~Uis',\n array( $this, '_parse_dynamic_mfunc' ),\n $buffer\n);\n```\n\nThe executor interpolates the actual token value straight into the regex pattern. No `preg_quote()`. Whatever string the administrator wrote as `W3TC_DYNAMIC_SECURITY` becomes part of the regex. The token slot is no longer \"any non-whitespace\"; it is the literal token value, parsed as regex syntax.\n\nRead both patterns at the level of the whitespace between `mfunc` and the token:\n\n- Strip: `mfunc\\s+[^\\s]+`, one or more whitespace, then one or more non-whitespace\n- Executor: `mfunc\\s*` then the token, zero or more whitespace, then the token\n\nA comment shaped `` carries zero whitespace between `mfunc` and the `A`. The strip's `\\s+` does not match. The strip passes the comment through unchanged. The executor's `\\s*` matches zero whitespace. If the configured token happens to be a regex metacharacter that matches `A`, the executor runs the embedded PHP.\n\nThe strip wants to delete every tag the executor would run. The executor runs the tags the strip did not see. This is `Gate Narrower Than Sink`: a security filter and a downstream sink each parse the same input through their own matcher, the filter's grammar is strictly contained within the sink's, inputs in the difference flow through unfiltered to the sink. The two matchers were written to describe the same syntactic object. They did not agree.\n\n## The token doubles as a regex pattern\n\nThe second half of the chain is the missing `preg_quote()`. The executor takes whatever the administrator wrote as `W3TC_DYNAMIC_SECURITY` and pastes it into the regex pattern as-is. Administrators choosing a token are choosing a regex pattern, even when they do not know it.\n\nTokens that look like placeholders to a human read differently to PCRE:\n\n```php\ndefine( 'W3TC_DYNAMIC_SECURITY', '.' );\ndefine( 'W3TC_DYNAMIC_SECURITY', '.*' );\n```\n\nIn regex syntax, `.` matches any single character. `.*` matches any string. An administrator who reads \"Dynamic Security\" and types a placeholder dot has built `mfunc.` into the executor: the literal `mfunc` followed by any character. The bypass character `A` matches `.`. Comments shaped `` reach the executor regardless of what the token was supposed to be.\n\nThis is the precondition the PoC's README admits up front: `W3TC_DYNAMIC_SECURITY` must contain a regex metacharacter. Without one, the attacker still needs to know the actual token. With one, knowing it is no longer required. The metacharacter becomes the universal token.\n\n## The complete chain\n\nThe attacker posts a WordPress comment whose body is the bypass payload:\n\n```http\nPOST /wp-comments-post.php HTTP/1.1\nHost: target.tld\nContent-Type: application/x-www-form-urlencoded\n\ncomment=&author=Visitor&email=v@example.com&comment_post_ID=1\n```\n\nWordPress fires the `preprocess_comment` filter. W3TC's `strip_dynamic_fragment_tags_from_string` runs. Its regex requires `\\s+` between `mfunc` and the token slot. The payload has zero whitespace there. No match. The comment is saved to the database verbatim.\n\nThe comment enters moderation or auto-approval depending on the site's WordPress settings. On a site where comments from previously-approved authors are auto-approved, an attacker who has any approved comment under the same name and email gets immediate publication. On a site where comments require manual approval, the payload sits until an administrator clicks Approve. Either path lands the payload in the rendered post page.\n\n```http\nGET /?p=1 HTTP/1.1\nHost: target.tld\n```\n\nW3TC caches the rendered page. The cached HTML includes the comment's content inside the comments section. The cache is now poisoned.\n\n```http\nGET /?p=1 HTTP/1.1\nHost: target.tld\n```\n\nThe second request hits the cache. W3TC reads the cached buffer and calls `_has_dynamic($buffer)`. With `W3TC_DYNAMIC_SECURITY` set to `.`, that function's regex resolves to `~~Uis`. The `.` matches `A`. `_has_dynamic` returns true. Control falls through to `_parse_dynamic`, which calls `_parse_dynamic_mfunc` on the matched tag. The handler extracts the PHP between the opening `-->` and closing `(.*)~Uis',\n+ '~(.*)~Uis',\n```\n\n`$security` is `preg_quote( W3TC_DYNAMIC_SECURITY, '~' )`. The first change makes the executor's whitespace requirement match the stripper's: `\\s+` now on both sides of the trust boundary. The second change neutralizes regex metacharacters in the token. `_has_dynamic` gets the same treatment and adds `empty()` and `1 === (int)` guards against tokens whose string form is empty or `1`.\n\nWhat the patch does not change: the mfunc feature still runs `eval()` on the content of HTML comments that survive the strip. The strip coverage is still defined by a deny-list regex applied at four WordPress content-filter hooks. The defense in depth remains a strip function before the cache and an executor with a tighter regex on the cache-serve path. The two regexes are now textually identical at the token boundary, which is the part that broke this time.\n\nThe next divergence is one development cycle away. The cache-serve path's greedy `(.*)` match between the opening and closing tags is unchanged. The stripper's lazy `.*?` match between them is unchanged. The two functions still parse the body of the tag through different greediness semantics. The same shape of `Gate Narrower Than Sink` is one code edit away from a new instance, on the next code path where one of the regexes is updated without the other. The substrate this CVE leaves in place is `Unpatchable Primitive`-shaped: `eval()` on the content of cached HTML comments is what the feature does. The patch closes one bypass of one gate that guards it. The substrate stays.\n\nPoC: [xxconi/CVE-2026-27384](https://github.com/xxconi/CVE-2026-27384)","closing_line":"The patch makes both regexes agree on whitespace. The eval() on the content of HTML comments is unchanged.","hook_md":"W3 Total Cache's Dynamic Fragment Caching feature runs `eval()` on PHP code wrapped in HTML comments. Two functions touch those comments. `strip_dynamic_fragment_tags_from_string()` removes them from user-supplied content before they reach the cache. `_parse_dynamic()` runs them when the cache serves the page. The strip function's regex requires at least one whitespace between `mfunc` and the security token; the executor's regex requires zero or more. A comment shaped `` passes the strip and reaches the executor. The function that deletes the dangerous tag is stricter than the function that runs it.\nThe function that deletes the dangerous tag is stricter than the function that runs it.","post_id":495,"slug":"w3-total-cache-cve-2026-27384-strip-stricter-than-executor","title":"CVE-2026-27384: W3 Total Cache's Strip Filter Was Stricter Than Its Executor","type":"initial","unreadable_sentence":"The function that deletes the dangerous tag is stricter than the function that runs it."} -----BEGIN PGP SIGNATURE----- iHUEARYIAB0WIQRf0htP5+SjynlxywneZjl4jgkQJgUCantcYwAKCRDeZjl4jgkQ JtSFAP0SES3aMx107DeAUzIimGFmWrDW+hK3ce8EGxmDOnOYcwEA49rsKMVA5wEw 2TeyQc5/h6PAnJ20dXE2jYedWvU9jQU= =ctjt -----END PGP SIGNATURE-----