Progress Report: wp_kses()

The Quiet Gatekeeper Behind Every WordPress Post

Progress Report - SiteHale

If you’ve run a WordPress site for any length of time, you’ve relied on wp_kses() thousands of times without knowing it. This function is WordPress’s built-in HTML filter. Whenever content comes from somewhere WordPress doesn’t fully trust, such as a comment, a contributor’s post, a form submission, or certain plugin output, wp_kses() decides which tags and attributes stay and which get stripped.

The name comes from an old recursive joke: KSES Strips Evil Scripts. That joke points at the real job. The function blocks injected JavaScript, malicious links, and other markup an attacker might use to hijack a visitor’s browser or a logged-in administrator’s session. Cross-site scripting (XSS) is still one of the most common vulnerability classes reported in WordPress plugins, so this filter matters a lot.

WordPress core contributors have now published a progress report on a significant overhaul of this subsystem. It’s tracked in Trac ticket #66208, and an early pull request (PR #13271) has already replaced part of the underlying implementation. This isn’t a cosmetic refactor. The goal is to rethink how WordPress sanitizes HTML so the approach fits the way the web works today.

Why should a site owner care about a low-level function most people never call directly? Because wp_kses() sits underneath a huge share of what your site shows visitors. Its relatives include wp_kses_post() for post content, wp_kses_data() for comments, and helpers used across thousands of themes and plugins. Any change to how it reads HTML eventually reaches nearly every WordPress installation on the internet.

The good news is that this work aims to make sites more secure and predictable. Still, changes this deep tend to surface edge cases, so it helps to understand what’s happening before it lands in a release you update to.

Why a 2000s-Era Approach Needed Rethinking

The original kses library was written in a very different web era. People commonly typed HTML by hand into a textarea. Browsers each handled broken markup in their own way, and no single, authoritative standard said how a parser should treat sloppy code. So kses took on two jobs at once. It cleaned up typos and pasting mistakes, such as unclosed tags and stray brackets, and it removed anything dangerous.

Two big things have changed since then.

  1. HTML5 standardized parsing. The HTML5 specification defines exactly how a browser must interpret any string of characters, including messy ones. As a result, there’s really no such thing as ‘seriously malformed’ HTML anymore. Every input has one correct interpretation that modern browsers agree on.
  2. Most content no longer comes from hand-typed code. The Block Editor, page builders, and other rich editors generate structured markup for you. The typo-correction role kses once played matters much less than it used to.

This creates a security problem. A sanitizer that reads HTML differently from how browsers read it leaves a gap. If the filter believes a string is harmless text, but a browser parses the same string as a working script tag or event handler, an attacker can slip through that mismatch. Security researchers call these parser differential attacks, and older regex-style and hand-rolled HTML filters are especially exposed to them.

The core team’s conclusion is that wp_kses() should focus on its main job today, which is pruning risk from untrusted input. It should do that by understanding HTML the same way a browser does. Recent WordPress releases have already introduced a spec-aware HTML API, and moving sanitization toward standards-compliant parsing follows naturally from that work. The direction is to stop guessing at markup and start reading it accurately.

What This Means for Your Site's Security and Content

For most WordPress site owners, the most important takeaway is reassuring. A sanitizer that parses HTML like a browser closes off whole categories of bypass tricks. If someone tries to sneak a script past your comment form or a compromised contributor account using odd encodings, nested quotes, or deliberately broken tags, a standards-aware filter should see exactly what the browser would see and handle it correctly.

This matters across several common setups:

  • Multi-author blogs and news sites, where contributors and authors don’t have the unfiltered_html capability and their content always passes through kses.
  • Membership and ecommerce sites that accept user-submitted reviews, profile bios, or forum posts.
  • Multisite networks, where even site administrators are usually filtered and only super admins can post raw HTML.
  • Sites running many plugins, since plugin developers often lean on kses functions to escape output safely.

There’s a second, subtler benefit: consistency. The older approach tried to repair broken markup, so it sometimes changed content in surprising ways. It might strip an attribute you expected to keep or adjust something that looked fine in the editor. A more modern implementation should give more predictable results, with fewer moments where a post looks different on the front end than it did while you were writing it.

From an SEO and site-health view, cleaner and more predictable output supports reliable rendering, structured data, and accessibility attributes. Security also has a direct link to search visibility. A site hit by injected spam links or malicious redirects can be flagged by search engines and browsers, and recovering rankings after that kind of incident often takes a long time.

In short, this work strengthens a foundation your site depends on every day, even if you never notice it doing its job.

Who Should Watch This Change Most Closely

Typical site owners should benefit without lifting a finger. Some groups, though, should follow this overhaul more closely as it moves toward a release.

Plugin and theme developers. If your code calls wp_kses() with custom allowed-tag arrays, hooks into the wp_kses_allowed_html filter, or extends allowed CSS properties through safe_style_css, test your output against development builds. Code that quietly relied on the old function’s quirks may behave differently. For example, it might have counted on a specific way malformed input got repaired, or on attribute handling that happened to work.

Agencies and developers maintaining custom builds. Custom shortcodes, legacy widgets, and older custom fields often output HTML that passes through kses. Sites built years ago, before the Block Editor, are the most likely to contain handcrafted markup that an updated parser could interpret differently.

Sites with heavy embedded content. If contributors regularly paste iframes, SVG code, data attributes, or inline styles, check whether that content still renders as expected after updating. Advanced or unusual markup is where a parsing change is most likely to show up.

Security-conscious organizations. Teams with compliance requirements or formal security reviews may want to read the Trac ticket and pull request discussion directly. Understanding the threat model WordPress core is designing for helps you judge whether your own content policies and user roles still make sense.

One caution: work tracked in a Trac ticket and an open pull request is still in progress. Implementation details can shift before anything ships in a stable release. Treat this as early notice, not a finished change, and expect more discussion, testing, and refinement along the way.

Practical Steps to Prepare Your WordPress Site

You don’t need to panic or rewrite anything today. A few sensible steps now will make sure this improvement arrives smoothly when it reaches a stable WordPress release.

  1. Audit who can post unfiltered HTML. Review your user roles. Only people you fully trust should hold the unfiltered_html capability, which by default means administrators and editors on single-site installs. Many sites hand out elevated roles more generously than they need to.
  2. Use a staging environment. Before major WordPress updates, test on a staging copy of your site. Look closely at posts with embedded media, custom HTML blocks, shortcodes, and user-generated content such as comments and reviews.
  3. Keep plugins and themes current. Responsible developers will test against these core changes and ship compatibility updates. Running outdated extensions is how small core changes turn into broken layouts.
  4. Identify legacy content. If your site has years of archives written in the Classic Editor or pasted from word processors, spot-check older posts after upgrading. Those are the most likely to contain unusual markup.
  5. Follow release notes and developer notes. WordPress publishes dev notes on Make WordPress Core before each major release. If the kses overhaul ships, expect guidance there about behavioral changes and any new APIs.
  6. Maintain reliable backups. A full, restorable backup taken before each update is the simplest protection against surprises of any kind.

The bigger picture is encouraging. WordPress is modernizing one of its oldest and most security-critical components so it matches how browsers actually read the web. That means fewer clever bypasses, more predictable content, and a stronger default posture for the hundreds of millions of sites built on the platform. Stay informed, test before you update, and let this improvement do its quiet work.

Source

Based on reporting from Make WordPress Core.

Does Your Site Have This Problem?

Every check in this article runs automatically on the sites we look after. You can run the same health checks on your own site in seconds with the free SiteHale plugin — no account, nothing transmitted anywhere. Or have us do it: we’ll crawl your site and send you a written report, free.

Leave a Comment