Lazy Load stored XSS
The Lazy Load WordPress plugin used a regular expression to rewrite image tags that failed when the tag contained spaces or mixed quotes, allowing a lower-privileged user to inject arbitrary HTML attributes such as an event handler. When an administrator viewed the post, the injected JavaScript executed with the administrator's privileges, enabling actions like changing passwords or editing plugin PHP.
- Fixed in 3 days
- Paid in 3 days
- Disclosed after 16 months
I noticed a problem with the Lazy Load WordPress plugin. It could be exploited by a lower-level user to gain administrator-level access or server compromise.
I've discussed this by email with Mohammad Jangda who confirmed the issue.
According to my tests, this kind of post content leads to JavaScript execution:
{{media:0}}
The problem seems to be this regular expression:
// This is a pretty simple regex, but it works
$content = preg_replace( '#<img([^>]+?)src=[\'"]?([^\'"\s>]+)[\'"]?([^>]*)>#', sprintf( '{{media:1}}<noscript>{{media:2}}</noscript>', $placeholder_image ), $content );
It doesn't work as intended if there are spaces or mixed single and double quotes inside the image tag. A maliciously formed src attribute can be used to inject any other HTML attributes, like onerror.
Why this is a problem: normally users without the administrator privilege can't embed JavaScript in posts/pages. A malicious user can inject JS which, when the post is viewed by an administrator, executes administrative functions such as changing passwords, adding users, or editing plugin PHP.
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
Likely the plugin's regular expression for matching image tags did not correctly handle spaces or mixed single and double quotes inside the tag, so a crafted src attribute could break out and inject extra HTML attributes.
Impact
A lower-level user could inject JavaScript that, when an administrator viewed the post, could perform administrative actions such as changing passwords, adding users, or editing plugin PHP, potentially leading to server compromise.
What the attacker needed
A low-privileged account able to create posts; an administrator views the post
How it was found
- Create a post whose content contains a specially formed image tag.
- The plugin's regular expression rewrites the image tag but is fooled by spaces or mixed quotes.
- The crafted src attribute injects an extra HTML attribute such as an event handler.
- An administrator views the post, and the injected JavaScript runs with administrator privileges.
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.
WordPress lets people with lower roles write posts but normally strips out JavaScript so they cannot run code in other people's browsers. This plugin tried to find image tags in a post and rewrite them, but its pattern-matching was too simple and could be fooled. A user could then slip in an attribute that runs JavaScript when an administrator opens the post, and because the code runs as the administrator it can do administrative things.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.