Skip to content
XSS Write-up Beginner

How I Found a DOM XSS on a Major Brand’s Community Site (and Got Swag for It)

A product filter script on a community site read a URL parameter and inserted it into the page as HTML without encoding, and also passed URL-derived data to eval. An attacker could craft a link that runs their JavaScript in a victim's session on the trusted domain.

Subadevan C Follow

Published on medium.com

Cybersecurity

Subadevan C, on medium.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.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 4 min read.

Context

The target was a public bug bounty program run by a large electronics brand. The scope was broad, but rather than the main shopping site the researcher chose one of the brand's community sites, a place for camera enthusiasts, referred to throughout as community.example.com. The feature of interest was the product filter, which lets visitors filter lenses and gear. Filter values take the shape label:value, and the frontend turns them into tags displayed in the page.

These secondary sites tend to receive less attention than the main domain while still sitting on the same brand and carrying the same user trust, which is what made this one worth digging into.

Setup

The community site was public, and the researcher browsed it and read the JavaScript it loads. The researcher ran katana with -jc so that it also extracts JavaScript files while crawling, with depth 5 and silent output. The researcher's stated approach is to avoid running large numbers of scanners and instead read the frontend code directly, because the JavaScript describes how the site works.

Finding it

The first step was to collect every endpoint and script the site loads:

Bash
katana -u <https://community.example.com> -jc -d 5 -silent \  | grep -iE '\.js(\?|$)' \  | sort -u > jsfiles.txt

Katana crawls the site, -jc pulls out the JS files, the grep keeps only JavaScript URLs (with or without a query string), and sort -u produces a deduplicated list in jsfiles.txt.

Going through the files one by one, one stood out:

Text
/static/custom_js/products_filter.js

This is the script behind the product filter. Reading it revealed two problems. First, the script took a URL parameter called f, parsed it, built HTML from it, and inserted that HTML straight into the page:

JavaScript
tagsArrey.push(html)       $('#tagValues').append(tagsHtml)

There was no encoding and no sanitisation, so whatever was placed in the f parameter became real HTML in the DOM. Second, further down, around line 315, the script called eval() on data derived from the URL:

JavaScript
modifyTagsId = eval(tagsId)   // eval on data from the URL

That gave both ingredients of DOM XSS: attacker-controlled input from the URL, and dangerous sinks that turn it into HTML or execute it as code. The remaining question was whether the path could actually be reached.

Exploitation

Step 1: Keep the expected shape and inject into the value

Because filter values looked like label:value, the researcher kept that shape and put an HTML tag in the value part, using the classic image onerror payload that fires as soon as the broken image fails to load:

HTML
Test:<img src=x onerror=alert(1)>

Step 2: URL-encode and build the link

The payload was URL-encoded so it survives the address bar, giving the final proof-of-concept URL:

Text
https://community.example.com/photography-gear/lenses/?f=Test:%3Cimg%20src%3Dx%20onerror%3Dalert(1)%3E

Step 3: Open the link

Opening the URL loaded the brand's lens page normally, with everything looking legitimate. The payload landed in the filter label area, the image failed to load, onerror fired, and the alert popped. No clicking and no extra steps were needed: the script ran the moment the page loaded, on the real branded domain, with the user's session present.

Root cause

The filter script takes the f URL parameter and builds HTML from it, then appends that HTML to the #tagValues element without encoding or sanitisation. The same script also passes URL-derived data to eval(). Both are dangerous sinks fed by attacker-controlled input, which is the definition of DOM XSS. The script inserted the built HTML without encoding or sanitisation, which is the direct cause.

Impact

As argued in the report, DOM XSS on a trusted brand domain is serious. Anyone could send the crafted link to any user of the community, and the moment that user opens it, the attacker's JavaScript runs in their session on the real domain. That allows stealing the session cookie and taking over the account, dropping a fake login box on the trusted page to capture passwords, or silently acting as the user, for example posting or changing their profile. Because everything happens on the real trusted domain, users have no reason to be suspicious.

The report does not state which of these outcomes was demonstrated beyond the alert(1) proof of concept.

Fix

The report does not say what the vendor changed. The fix implied by the finding is to stop treating the f parameter as HTML: encode or sanitise the value before it reaches the #tagValues sink, and remove the eval() call on URL-derived data in favour of parsing the value safely.

Variants to test

  1. Crawl a target's JavaScript with katana (-jc) and grep for .js files, then read each one looking for URL parameters that are concatenated into HTML or passed to eval(), innerHTML, document.write or similar sinks. A positive result is a parameter whose value reaches the sink without encoding.
  2. On filter or tag interfaces that use a label:value format, keep the label and inject an HTML payload into the value, for example Test:<img src=x onerror=alert(1)>, then URL-encode it. A positive result is the alert firing on page load with no further interaction.
  3. Look for eval() calls on values read from the URL. A positive result is code execution from a crafted parameter, which is a stronger primitive than HTML injection alone.
  4. Test secondary and community subdomains of large brands, which the report notes receive less attention than the main domain while sharing its trust. A positive result is the same class of sink reachable on a branded domain where users are logged in.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 15 min read.

What happened, in plain words

A security researcher found a bug on a website belonging to a very large electronics brand. The bug let anyone who sent a specially crafted web link run their own small program inside another person's browser, on the brand's real website, while that person was logged in. This kind of bug is called DOM XSS, and it is dangerous because the victim has no reason to suspect anything: the address bar shows the brand's own domain.

The researcher did not get paid money for it. The company gave them swag instead, meaning branded merchandise. The bug was triaged within a few hours, which the researcher considered a big deal.

What makes this write-up useful for a beginner is that the whole discovery came from reading the website's own code, not from running a large pile of automated tools. The researcher's habit is to open the JavaScript files a site loads and read them, because the frontend code describes how the site works.

Before going further, a few words on the pieces involved.

  • A bug bounty program is an arrangement where a company invites outside people to look for security problems in its systems and report them, usually in exchange for a reward. Some programs pay money, some give other rewards, and some only give recognition.
  • Scope means the list of systems a program allows you to test. A broad scope means many websites and subdomains are fair game.
  • A subdomain is a site that sits under a company's main domain name. If the main site is example.com, then community.example.com is a subdomain, often run for a specific purpose such as a forum or a community area.
  • JavaScript is the programming language that runs inside your browser. It is what makes pages interactive: it reacts to clicks, loads new content, and changes what you see without reloading the page.
  • DOM stands for Document Object Model. It is the browser's live, in-memory model of the page: every heading, image, button and text block is an object in that model, and JavaScript can read and change it. When people say a script "puts something in the DOM", they mean it inserts content into the page you are looking at.
  • XSS stands for Cross-Site Scripting. It means getting someone else's JavaScript to run in a victim's browser as if the website itself had written it. DOM XSS is the variety where the malicious content never needs to reach the company's servers: the page's own JavaScript reads something from the URL and inserts it into the DOM, so the attack happens entirely inside the browser.
  • A sink is the place in code where data finally gets used in a way that matters, for example where a string is turned into HTML and shown on the page, or where it is executed as code. A source is where the data comes from, such as the URL. DOM XSS happens when a source that an attacker can control flows into a dangerous sink without being cleaned up first.

The target

The researcher picked a public program run by a big electronics company. The scope was massive, the sort of brand where you assume everything is already locked down and there is nothing left for a beginner to find. The researcher notes the opposite keeps being true: big names are never as clean as you imagine.

Instead of the main shopping site, the researcher went for one of the brand's community sites, a place for camera fans. In the write-up it is referred to as community.example.com. The reasoning is worth remembering: these side sites get far less attention than the main domain, yet they still run under the same brand and carry the same trust from users. That combination, less scrutiny plus the same trust, is a good place to dig.

The feature of interest was the product filter, the part of the site that lets visitors narrow down lenses and gear. Filter values take the shape label:value, and the frontend turns them into tags displayed on the page. Think of it like a shopping site where you pick "Brand: Canon" and the page shows a little removable chip reading "Brand: Canon". The label is the part before the colon, the value is the part after it.

The community site was public, so the researcher browsed it and read the JavaScript it loads.

Reading the JS

The approach here is the same one the researcher says keeps working: do not run a hundred scanners, read the JavaScript the site loads, because the frontend basically tells you how it works if you look.

To get a list of everything worth reading, the researcher ran a tool called katana. Katana is a crawler: you give it a starting address, and it follows links around the site the way a visitor would, collecting the pages and resources it finds. The -jc option tells it to also pull out JavaScript files while crawling. The command was:

Bash
katana -u <https://community.example.com> -jc -d 5 -silent \  | grep -iE '\.js(\?|$)' \  | sort -u > jsfiles.txt

Line by line, in plain words:

  • katana is the name of the crawler program being run.
  • -u <https://community.example.com> gives it the starting address, the community site.
  • -jc tells katana to extract JavaScript files as well as pages.
  • -d 5 sets the crawl depth to 5, meaning it will follow links up to five steps away from the start.
  • -silent keeps the output quiet, showing only the results rather than progress chatter.
  • The backslash at the end of the line is a line continuation: it tells the shell that the command carries on to the next line, so the whole thing is really one long command.
  • | is a pipe. It takes whatever the program on the left printed and hands it to the program on the right as input. It is like passing a list down an assembly line.
  • grep -iE '\.js(\?|$)' filters that list. grep searches text for a pattern. -i makes it ignore upper and lower case. -E lets the pattern use extended regular expressions. The pattern \.js(\?|$) means: the characters .js, followed either by a question mark or by the end of the line. In other words, keep only addresses that point at JavaScript files, with or without extra parameters after a ?.
  • sort -u sorts the remaining lines alphabetically and -u removes duplicates, so each file appears once.
  • > jsfiles.txt writes the result into a file called jsfiles.txt instead of printing it on screen.

The point of this step is purely practical: a modern site loads many scripts, and you want a tidy, deduplicated list so you can go through them one by one without missing any or reading the same one twice.

Going through that list, one file caught the researcher's eye:

Text
/static/custom_js/products_filter.js

This is the script behind the product filter, the thing that lets you filter lenses and gear. The name alone says what it does, which is why reading file names is a useful first pass. When the researcher read it, a few things made them stop.

First, the script was taking a URL parameter called f, parsing it, and building HTML out of it. A URL parameter is the part of a web address after a question mark, made of name and value pairs. In https://site/page?colour=blue, colour is the parameter name and blue is its value. Anything in the address bar is under the visitor's control, so a parameter is a classic source of attacker-controlled input.

Second, the script was dropping the HTML it built straight into the page:

JavaScript
tagsArrey.push(html)       $('#tagValues').append(tagsHtml)

Line by line:

  • tagsArrey.push(html) takes the variable html, which holds the HTML the script built from the f parameter, and adds it to the end of a list called tagsArrey. (The spelling Arrey is as it appears in the code.) A list like this is just an ordered collection of items, the way a shopping list holds several entries.
  • $('#tagValues').append(tagsHtml) finds the element on the page whose id is tagValues and appends tagsHtml to it. The $ is a common shorthand from the jQuery library for "find this element". append means "add this content at the end of that element".

The important part is what append does with a string that contains HTML: it does not show it as text, it interprets it as markup and creates real elements. If the string contains an image tag, the browser creates an actual image. There was no encoding and no sanitisation, meaning nothing checked or neutralised the content before it was inserted. Whatever you put in the f parameter, the page turned it into real HTML and put it in the DOM.

Encoding here means converting special characters into a harmless form so the browser displays them as text rather than acting on them. Sanitisation means cleaning input by removing or neutralising anything dangerous. Neither was happening.

And it got worse. Further down, around line 315, the script did this:

JavaScript
modifyTagsId = eval(tagsId)   // eval on data from the URL

Line by line:

  • eval(tagsId) calls eval, a JavaScript function that takes a piece of text and runs it as code. If the text is 2 + 2, eval returns 4. If the text is a program, eval runs that program. It is the programming equivalent of handing a stranger a note and doing whatever it says without reading it first.
  • tagsId is the value being evaluated, and the comment in the code itself says it comes from the URL.
  • modifyTagsId = ... stores the result in a variable called modifyTagsId.

eval() on something that comes from the URL is, on the frontend, basically the worst thing you can do. A visitor controls the URL, so a visitor controls the code that gets run.

At this point the researcher had both ingredients needed for DOM XSS: input controlled from the URL, and a dangerous sink that turns it into HTML or runs it as code. The only question left was whether the path could actually be reached, meaning whether a normal visitor could trigger this code by loading a crafted link.

The payload

A payload is the actual malicious input you send to prove a bug exists. Here it had to fit the format the filter expected. Filter values looked like label:value, so the researcher kept that same shape and put an HTML tag in the value part. The tag used was the classic image onerror payload:

HTML
Test:<img src=x onerror=alert(1)>

Line by line:

  • Test: is the label part, kept so the input looks like a normal filter value and passes whatever parsing expects a colon.
  • <img ...> is an HTML image tag. It tells the browser to display a picture.
  • src=x says the image is located at x. There is no such address, so the image will fail to load.
  • onerror=alert(1) is an event handler. It tells the browser: when this image fails to load, run the JavaScript alert(1). alert(1) is a built-in browser function that pops up a small dialog box showing the number 1. It is the standard harmless proof that JavaScript ran.

So the payload is a deliberately broken image whose failure triggers a popup. It fires the moment the broken image fails to load, with no click required.

The payload then had to be URL-encoded, meaning special characters are replaced by percent codes so they survive the address bar intact. A space becomes %20, < becomes %3C, > becomes %3E, and so on. Browsers and servers treat certain characters in a URL specially, so encoding keeps the payload from being mangled or cut off. The final proof-of-concept link was:

Text
https://community.example.com/photography-gear/lenses/?f=Test:%3Cimg%20src%3Dx%20onerror%3Dalert(1)%3E

Reading it in plain words: the address is the brand's lens page under community.example.com. The ?f= starts the parameter named f, and everything after the equals sign is the encoded payload. Decoded, %3Cimg%20src%3Dx%20onerror%3Dalert(1)%3E is exactly <img src=x onerror=alert(1)>.

Opening the link

The researcher opened the URL. The page loaded normally: the brand's lens page, everything looking legitimate. The payload landed in the filter label area, the image failed to load, onerror fired, and the alert popped.

No clicking and no extra steps were needed. The script ran the moment the page loaded, on the real branded domain, with the user's session sitting right there. A session is how a website remembers that you are logged in. When you sign in, the site gives your browser a small piece of data, often called a session cookie, which the browser sends back with every request so the site knows it is still you. Think of it as a wristband you get at an event: show it and you get in without proving who you are again.

That is why the timing matters. The script runs while the victim's wristband is on, on the brand's own site.

Why this is bad

DOM XSS on a trusted brand domain is nasty, and the researcher said so in the report. Anyone could send this link to any user of the community. The second that user opens it, the attacker's JavaScript runs in their session on the real domain. That enables several concrete outcomes:

  1. Stealing the session cookie and taking over the account. If the script can read the session cookie, it can send it to the attacker, who then uses it to act as the victim without knowing their password.
  2. Dropping a fake login box on the trusted page to grab passwords. The script can draw a convincing login form on the real site. A user who types their password into it hands it straight to the attacker.
  3. Silently acting as the user, for example posting or changing their profile. The site sees a logged-in session making requests, so it cannot tell the difference.

And because it all happens on the real trusted domain, nobody has a reason to be suspicious. The address bar shows the real trusted domain. The only fake part is the script the attacker slipped in through the filter parameter.

One limit worth stating plainly: the proof of concept demonstrated was the alert(1) popup. The report does not describe carrying out any of the three outcomes above; they are the consequences the researcher argued the bug makes possible.

Root cause

The filter script takes the f URL parameter and builds HTML from it, then appends that HTML to the #tagValues element without encoding or sanitisation. The same script also passes URL-derived data to eval(). Both are dangerous sinks fed by attacker-controlled input, which is the definition of DOM XSS. The script inserted the built HTML without encoding or sanitisation, which is the direct cause.

In everyday terms: the site took a note from a stranger, did not read it, and followed its instructions. The fix is to read the note as plain text and never treat it as instructions.

Fix

The fix implied by the finding is to stop treating the f parameter as HTML: encode or sanitise the value before it reaches the #tagValues sink, and remove the eval() call on URL-derived data in favour of parsing the value safely. Parsing safely means reading the value according to a strict expected format, such as splitting on the colon and accepting only plain text, rather than handing it to a function that executes whatever it is given.

Variants to test

If you want to try the same approach on a target you are authorised to test, these are the directions the write-up points to:

  1. Crawl a target's JavaScript with katana (-jc) and grep for .js files, then read each one looking for URL parameters that are concatenated into HTML or passed to eval(), innerHTML, document.write or similar sinks. A positive result is a parameter whose value reaches the sink without encoding.
  2. On filter or tag interfaces that use a label:value format, keep the label and inject an HTML payload into the value, for example Test:<img src=x onerror=alert(1)>, then URL-encode it. A positive result is the alert firing on page load with no further interaction.
  3. Look for eval() calls on values read from the URL. A positive result is code execution from a crafted parameter, which is a stronger primitive than HTML injection alone.
  4. Test secondary and community subdomains of large brands, which the report notes receive less attention than the main domain while sharing its trust. A positive result is the same class of sink reachable on a branded domain where users are logged in.

Glossary

  • Bug bounty program: an arrangement where a company invites outside researchers to find and report security problems, usually for a reward.
  • Scope: the list of systems a bug bounty program allows you to test.
  • Subdomain: a site under a company's main domain name, such as community.example.com under example.com.
  • JavaScript: the programming language that runs in the browser and makes pages interactive.
  • DOM (Document Object Model): the browser's live model of the page, which JavaScript can read and change.
  • XSS (Cross-Site Scripting): getting an attacker's JavaScript to run in a victim's browser as if the website had written it.
  • DOM XSS: XSS where the page's own JavaScript reads attacker-controlled input, such as a URL parameter, and inserts it into the DOM without cleaning it.
  • Source: where attacker-controlled data enters the code, for example a URL parameter.
  • Sink: the place in code where data is used dangerously, such as being turned into HTML or executed as code.
  • Product filter: the site feature that lets visitors narrow down lenses and gear, producing tags in a label:value shape.
  • URL parameter: a name and value pair after the ? in a web address, such as f in ?f=....
  • Katana: a crawler tool that follows links on a site and can extract JavaScript files with -jc.
  • Crawler: a program that follows links around a website automatically, like a visitor clicking through pages.
  • Pipe (|): a shell symbol that passes the output of one command as input to the next.
  • grep: a command that searches text for a pattern.
  • Regular expression: a pattern language for matching text, used here to keep only JavaScript file addresses.
  • Encoding (output encoding): converting special characters into a harmless form so they are displayed as text rather than acted on.
  • Sanitisation: cleaning input by removing or neutralising anything dangerous before it is used.
  • eval(): a JavaScript function that runs a piece of text as code.
  • Payload: the malicious input used to prove a vulnerability exists.
  • Event handler: code attached to an element that runs when something happens, such as onerror when an image fails to load.
  • alert(1): a built-in browser function that shows a small dialog, used as harmless proof that JavaScript ran.
  • URL encoding: replacing special characters with percent codes, such as %3C for <, so they survive the address bar intact.
  • Proof of concept (PoC): a concrete demonstration, here a link, that proves the bug is real.
  • Session: how a website remembers that you are logged in.
  • Session cookie: the small piece of data your browser sends to prove your session, which an attacker could steal to take over an account.
  • Root cause: the underlying reason the bug exists, here missing encoding at the sink and eval() on URL data.
  • Vendor: the company that owns the affected website.

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.