Reflected XSS Filter Bypass in Search Functionality
The search functionality reflected user input without proper encoding, and the filter only removed HTML tags when both opening and closing angle brackets were present. An attacker could craft a URL that bypassed the filter and executed arbitrary JavaScript in a victim's browser.
Published on kashsecurity.medium.com
Two years ago, while testing a web application, I discovered an interesting Reflected Cross-Site Scripting (XSS) vulnerability.
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 input filter only removed HTML tags when both the opening '<' and closing '>' were present, allowing incomplete tags to bypass sanitisation and be interpreted by the browser.
Impact
An attacker could steal session cookies, redirect users to malicious sites, perform actions as the victim, or load external scripts; for authenticated sessions this could have meant full account takeover, though the need for a user to click a link reduced severity.
What the attacker needed
Victim clicks a crafted link
The fix
The vulnerability was fixed by properly sanitising and encoding all user input, rejecting incomplete HTML tags, using auto-escaping libraries, and implementing a strong Content Security Policy.
How it was found
- Visit the search URL with a crafted parameter containing an input element with an onfocus handler and autofocus attribute, ending with '/<' to avoid the filter.
- The page loads and the injected input field automatically gains focus.
- The onfocus event triggers, executing the JavaScript (alert(1) in the proof of concept).
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.
Reflected cross-site scripting (XSS) happens when a website takes something you type, like a search term, and puts it directly into the page without cleaning it first. An attacker can send a link that contains malicious code, and when you click it, that code runs in your browser as if it came from the website. Here, the site tried to block code by removing HTML tags, but it missed a trick: it only removed tags that had both a start and an end symbol, so a tag without the end symbol slipped through.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.