Skip to content
XSS Write-up Intermediate

REGEXSS: How .* Turned Into over $6k in Bounties

A WordPress plugin used a greedy regex to remove HTML attributes from user comments, but the regex could be tricked into removing part of an attribute value, allowing an attacker to inject a JavaScript event handler. An unauthenticated attacker could post a comment that executes JavaScript when a victim views it.

sec.stealthcopter.com

Published on sec.stealthcopter.com

When you think of sources of Cross-Site Scripting (XSS) vulnerabilities, regex probably wouldn’t be one of the more obvious things that springs to mind, but a couple of weeks ago I teased that I’d hit something fun:

The author, on sec.stealthcopter.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

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

How it worked

Root cause

The regex used a greedy quantifier that could match across attribute boundaries, so it removed more than intended and allowed attribute injection.

Impact

An unauthenticated attacker could execute arbitrary JavaScript in the context of the victim's browser when they view the comment, potentially leading to account compromise or other malicious actions.

What the attacker needed

WordPress plugin installed; Ability to post comments (no login required)

The fix

The fix was to replace the regex with a proper HTML tag processor that understands HTML context and can safely remove attributes.

How it was found

  1. Post a comment containing a crafted link with mixed quotes and an event handler.
  2. The plugin applies the regex replacement to the comment content.
  3. The regex removes part of the attribute value, causing the event handler to become a separate attribute.
  4. When the comment is viewed, the event handler executes the JavaScript.

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 write-up has not been written yet. The Original tab links to the source.

The plugin tried to clean up comments by using a pattern-matching tool (regex) to delete certain HTML attributes. But the pattern was too greedy and could be fooled into deleting the wrong part of the HTML, letting an attacker sneak in a script that runs when someone views the comment. This is called cross-site scripting (XSS).

What is XSS?

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

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.