wp72-html-kses
Reviews HTML sanitization against WordPress 7.2's transitional KSES implementation. Use for wp_kses, wp_kses_post, pre_kses, custom allowlists, wp_kses_force_legacy_parser, or HTML API parser migratio
Files1
View on GitHubSKILL.mdwordpress-72/wp72-html-kses/SKILL.md
GitHubWordPress 7.2 HTML and KSES
Keep wp_kses() and wp_kses_post() as the public sanitization entry points.
They have not been removed. In build 7.2-RC2-65695, the new HTML API implementation
is active after normal bootstrap: default-filters.php registers
__return_false on wp_kses_force_legacy_parser. The true fallback visible
inside wp_kses() alone does not describe the effective default.
Workflow
- Inspect
wp-includes/kses.php,wp-includes/default-filters.phpand the runtime filter stack in the actual candidate. Record the effective parser; do not infer it from one function, a since tag or an October progress report. - Inventory content entry points, allowed tags/attributes/protocols,
pre_kses,wp_kses_allowed_htmland lower-level parser callbacks. - Save representative fragments: editor block comments, malformed markup, entity-encoded URLs, styles, non-ASCII text, custom attributes and large attribute values.
- Run the same policy through default and forced-legacy modes in an isolated process. Compare allowed content and browser-visible semantics as well as bytes.
- Check disallowed elements/attributes and URL protocols with a structured parser. An output-string difference alone is not a vulnerability.
- Test the project's hooks with nested sanitization. Avoid reading or changing
$wp_kses_operating_modeas a plugin API.
For a scoped experiment, use the existing entry point and restore the filter:
$legacy_override = static function () { return true; };
add_filter( 'wp_kses_force_legacy_parser', $legacy_override, PHP_INT_MAX );
try {
$clean = wp_kses( $input, $allowed_html, $allowed_protocols );
} finally {
remove_filter( 'wp_kses_force_legacy_parser', $legacy_override, PHP_INT_MAX );
}
Use a distinct callback so cleanup does not remove core's filter. Prefer a disposable request/process for comparisons with an existing filter stack.
Boundaries
- Do not call
wp_sanitize_html_kses()directly. The candidate labels it private and transitional even though PHP exposes the function. - Do not replace sanitization with
WP_HTML_Tag_ProcessororWP_HTML_Processor; parsers alone retain unsafe HTML. - Do not promise byte-identical serialization, unchanged entity spelling or unchanged malformed-tag repair.
- Keep the allowlist appropriate to the output context. Broadening it to make a snapshot pass can introduce XSS.
- Treat forcing the legacy parser as a temporary diagnostic or a documented, scoped compatibility measure, not a substitute for fixing the integration.
Verification
Exercise a custom allowlist and verify removal of scripts, event attributes and JavaScript URLs in both modes. Include the target plugin's content corpus and filters. Keep regression checks distinct from a full sanitizer security review.
References
- KSES implementation ticket
- Original progress report; its forecast is not a release guarantee
- Verified source:
wp-includes/kses.php,wp-includes/default-filters.php,wp-includes/html-api/class-wp-html-tag-processor.php. - Related stable skill:
wp-html-api.