Skip to content
XSS Disclosed report Intermediate

Stored XSS in Post Preview as Contributor

A stored cross-site scripting vulnerability existed in WordPress post previews because a URL-decoding step ran after sanitisation, allowing a contributor to inject a link with a JavaScript URL that bypassed esc_url(). An attacker could trick an admin into previewing the post and clicking the link, executing arbitrary JavaScript in the admin's browser.

simonscannell Follow

Originally disclosed on HackerOne

  • Triaged in 20 hours
  • Fixed in 7 months
  • Paid in 7 months
  • Disclosed after 18 months

Root cause

I noticed that the get_the_content() makes a preg_replace_callback after all other validation and sanitization has been performed.

function get_the_content( $more_link_text = null, $strip_teaser = false ) {
	global $page, $more, $preview, $pages, $multipage;

	$post = get_post();

	...
	if ( $preview ) // Preview fix for JavaScript bug with foreign languages.
		$output =	preg_replace_callback( '/\%u([0-9A-F]{4})/', '_convert_urlencoded_to_entities', $output );

	return $output;
}

Any JavaScript URL encoded characters will get replaced by the result of the _convert_urlencoded_to_entities() function.

function _convert_urlencoded_to_entities( $match ) {
	return '&#' . base_convert( $match[1], 16, 10 ) . ';';
}

This function replaces the URL encoded characters with a corresponding HTML entity.

This in fact leads to a bypass of esc_url().

esc_url() usually prevents payloads such as javascript:alert(1) etc. It even understands javascript&#3A;alert(1);. However, the payload <a href="javascript%u003Aalert(/XSS/)">text</a> would not get sanitized by esc_url(). Due to the characters being converted back to HTML entities after the sanitization, the payload works again.

Steps for replication

  1. Create a new blog post
  2. Paste the following HTML: <a href="javascript%u003Aalert(/XSS/)">text</a>
  3. Preview the post and click the link

I have tested this with Firefox.

Impact

If an attacker can trick an admin into previewing a post and get him to click the link, he can execute arbitrary JavaScript code in the context of the admin user.

I have demonstrated in #428019 how using already existing CSS classes the link can be turned into an invisible overlay over the entire page, which makes exploitation way more likely.

The original report as published on HackerOne, by simonscannell. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

The preview-specific preg_replace_callback that converts %u-encoded characters to HTML entities runs after esc_url() sanitisation, so a javascript: URL hidden as %u003A becomes active again.

Impact

If an attacker can trick an admin into previewing a post and clicking the link, they can execute arbitrary JavaScript in the admin's browser; the report notes that CSS can make the link an invisible overlay, increasing the chance of exploitation.

What the attacker needed

An account able to create and preview a post; Victim (admin) previews the post; Victim clicks the crafted link

How it was found

  1. Create a new blog post
  2. Paste HTML containing a link with a javascript%u003A URL
  3. Preview the post and click the link

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

When you write a blog post, WordPress cleans up dangerous HTML before showing it. But in preview mode, it later converted some encoded characters back into HTML, undoing the cleaning. This let a low-privilege author sneak in a link that runs JavaScript when an admin clicks it.

What is XSS?

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.

More by simonscannell

View all

13 more disclosed reports, best first.

More from WordPress

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Cross-site scripting (XSS)

The lesson behind this report.

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.