Scenario
A WordPress plugin stored an image URL in a database and later rendered it inside an img src attribute without proper context-aware escaping. An attacker could inject a double quote to break out of the attribute and add an onerror handler, leading to stored cross-site scripting when the image list was viewed.
shreyapohekar.com
Published on shreyapohekar.com
Hey infosec fam!! Recently I was testing out an image upload functionality on a wordpress plugin that led me to stored XSS.
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
Likely the developer used sanitize_text_field, which escapes quotes with backslashes, instead of an HTML-attribute-aware escaping function, so the quote still terminated the src attribute.
Impact
An attacker could execute arbitrary JavaScript in the context of an authenticated user viewing the image list, potentially leading to actions on behalf of the victim.
What the attacker needed
Ability to upload or add an image entry; victim views the image list
The fix
The plugin should use context-appropriate escaping such as esc_url or esc_attr for the src attribute instead of sanitize_text_field.
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 saved an image link and later put it directly into a web page inside an image tag. The developer used a filter that adds backslashes before quotes, but that filter is not meant for HTML attributes. Because the backslash became part of the URL, the quote still closed the attribute, letting the attacker add JavaScript that runs when the page loads.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.