CSRF attack can lead to stored XSS
A subdomain accepted template-creation requests without any CSRF protection, and the description field allowed HTML. An attacker could make a logged-in victim's browser create a template containing a stored cross-site scripting payload, which would run when the victim opened it.
Published on medium.com
{{media:0}}
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.
Context
The target is a website the researcher refers to as example.com. On one of its subdomains there is a feature built around templates: a user can create a template, and each template has fields such as a title and a description. The description field accepts HTML tags, and the template list shows the user's templates, from which a template can be opened and edited.
The write-up chains two issues against that feature: a cross-site request forgery (CSRF) that lets an attacker create a template on a victim's behalf, and a self-stored cross-site scripting (XSS) in the description field that fires when the template is opened. The researcher's own framing is that the CSRF leads to stored XSS.
Setup
The researcher tested the subdomain manually with Burp Suite, using the proxy to capture requests and Repeater to resend them. No account details, roles, software versions or other preconditions are given beyond the existence of a logged-in user with a template list. The proof of concept is a local HTML file containing a form with a submit button, which the victim would have to load while authenticated to the target.
Finding it
On an earlier test the researcher found a self-stored XSS in a description field that allows HTML tags. They also found what looked like a CSRF that could add the XSS payload, but exploiting it required knowing the template ID to edit, and brute forcing that ID was not feasible at the time, so the issue was left alone.
On returning to the target, the researcher captured requests in Burp and found an interesting request. Sending it to Repeater and resending it produced a new template in the template list. Scanning the request showed no CSRF protection. The request also includes the template ID, which can be used to write content into the template fields. That is what made the earlier self-stored XSS reachable: the two bugs could be combined.
Exploitation
The researcher wrote an HTML file as the proof of concept:
<form action="https://subdomain.example.com/endpoint" method="POST"> <input type="text" name="svcid" value="WRKSPC_LAYER_SERVICE"><br> <input type="text" name="stok" value=""><br> <input type="text" name="v" value="0"><br> <input type="text" name="clientType" value=""><br> <input type="text" name="request" value='{"basePage":{"draftIds":["1514844016810"],"wsId":"-1","wsType":"-1"},"fields":{"title":"CSRF_1","bold":"false"},"fields":{"description":"<font rwr=\"1\" style=\"font-family:Arial\" size=\"4\"><br>\"><svg onload=\"alert(cookie)\">\n</svg></font>","rteMode":"0"},"mode":"INDIVIDUAL","action":"SAVE","layerName":"EDITPANE","variation":null,"currencyInfo":{"currencySymbolLeft":true,"singularName":"U.S. dollars","moneySymbol":"$","decimalSymbol":".","groupingSymbol":",","gS":",","decimalPlaces":"2","currencyCode":"USD","pluralName":"U.S. dollar"},"singleList":true,"listingMode":"AddItem","updateRequired":true,"customFields":{},"byPassUpdate":false,"sellerType":"C2C","saveUlsi":true,"edpCrNew":false,"deletedFields":[],"customAttributes":{"PL_SELLER_ELIGIBLE":"1","PL_FORMAT_ELIGIBLE":"1","PL_CATEGORY_ELIGIBLE":"1","PL_ALREADY_OPTED":"0"},"draftMode":"Listing","restricted":false,"customPreference":{"preferences":{"scheduleStartTime":true,"reservePrice":true,"sellAsLot":true,"privateListing":true,"salesTax":true},"sellerDetails":["BUSINESS_POLICY","NO_STORE_SUBSCRIPTION","NO_SHIPPING_DISCOUNTS","NON_SM_SELLER"]},"payments20":false,"templateId":5553489011,"isvShown":false}'><br> <input type="submit" value="send"></form>
Step 1: deliver the forged request
The form posts to https://subdomain.example.com/endpoint with method="POST". The visible fields are svcid set to WRKSPC_LAYER_SERVICE, stok left empty, v set to 0, and clientType left empty. The substantive content is the request field, a JSON document carried as a form value.
Step 2: understand the JSON body
Inside request, basePage.draftIds contains 1514844016810, and templateId is 5553489011. The fields object carries title set to CSRF_1 and bold set to false; a second fields key carries description and rteMode set to 0. The description value is the XSS payload wrapped in a font tag:
<font rwr="1" style="font-family:Arial" size="4"><br>"><svg onload="alert(cookie)">
</svg></font>
The remaining keys describe the save operation: mode is INDIVIDUAL, action is SAVE, layerName is EDITPANE, listingMode is AddItem, updateRequired is true, byPassUpdate is false, saveUlsi is true, edpCrNew is false, draftMode is Listing, restricted is false, payments20 is false and isvShown is false. There are also currency settings, an empty customFields object, an empty deletedFields array, a customAttributes object with four PL_* flags, and a customPreference object listing preferences and seller details. The researcher does not explain what each of these keys does; they are part of the captured request as sent.
Step 3: create the template through the missing ID
The request is meant to edit a template with ID 1514844016810. Because the server does not find a template with that ID, it creates one instead, with the supplied values, including the XSS payload in the description. This is the behaviour the researcher observed in Repeater: resending the request added a new template to the template list.
Step 4: trigger the payload
When the victim visits their template list, the newly created template appears there. Opening it executes the payload in the description, which calls alert(cookie).
Root cause
The save endpoint accepts a state-changing POST without any CSRF protection, so a page on another origin can submit it on behalf of an authenticated user. The description field stores the HTML payload, and the <svg onload=...> handler runs when the template is opened. The combination is what turns a self-stored XSS, which normally only affects the person who enters it, into an attack delivered to another user. The report does not describe the server-side validation or output encoding in any more detail, so the exact sanitisation gap is not stated.
Impact
An attacker who gets a logged-in victim to load the proof-of-concept page can create a template in the victim's account containing script. The script runs in the victim's session when they open the template, and the payload calls alert(cookie). The attack requires the victim to be authenticated and to visit the attacker's page, and then to open the new template from their list.
Fix
The two fixes implied by the findings are CSRF protection on the save endpoint, such as a token tied to the user's session, and sanitisation or encoding of the description field so that HTML such as <svg onload=...> cannot be stored and executed.
Variants to test
- Resend any template or content save request in
Repeaterwithout a CSRF token and see whether a new object appears in the account. A positive result is a new entry in the list after a request sent from a different origin. - Submit a description containing an event-handler payload such as
<svg onload=alert(1)>and open the saved item. A positive result is script execution when the item is rendered. - Try a non-existent ID in a save request that is meant to edit an existing object. A positive result is the server creating a new object with the supplied values instead of rejecting the request.
- Check whether the same save endpoint accepts a request with no
OriginorRefererheader, which would confirm that no origin check is in place.
What happened, in plain words
A security researcher was testing a website, which the write-up calls example.com. On one of its subdomains there was a feature built around templates. A template is a saved starting point for something a user creates: it has a title and a description, and the user can open it later and edit it. The description field accepted HTML, the language web pages are written in, so whatever a user typed there was stored and later shown as part of a page.
The researcher found two separate weaknesses in that feature and joined them together. The first was a cross-site request forgery (CSRF): a way to make a logged-in user's browser send a request to the site that the user did not intend to send. The second was a self-stored cross-site scripting (XSS) in the description field: HTML containing a small script could be saved and would run when the template was opened. On its own, a self-stored XSS only affects the person who typed it in. Chained with the CSRF, the attacker can plant the script in someone else's account, and it runs when that person opens the new template.

The feature being attacked
On the subdomain there is a template feature. A user can create a template, and each template has fields such as a title and a description. The description field accepts HTML tags. The user's template list shows all their templates, and from that list a template can be opened and edited.
Two ideas are worth explaining before the rest makes sense.
- HTML: the markup language browsers use to draw pages. Tags such as
<font>or<svg>tell the browser how to display something. Some tags can carry a small piece of code that the browser runs, and that is what makes HTML interesting to an attacker. - A request: when you click a button on a page, your browser sends a message to the server asking it to do something, and the server sends back a reply. A form on a page is just a tidy way of building such a request.
The tool used to look at requests
The researcher tested the subdomain by hand with Burp Suite. Burp Suite is a program that sits between your browser and the website and lets you read every request and reply. Two parts of it are named in the write-up:
- The proxy, which captures the requests as they pass through.
- Repeater, a panel where you can take a captured request and send it again, as many times as you like, changing it in between.
No account details, roles or software versions are given. The only precondition stated is that there is a logged-in user with a template list. The proof of concept is a local HTML file containing a form.
Finding it
On an earlier test the researcher found a self-stored XSS in a description field that allows HTML tags. They also found what looked like a CSRF that could add the XSS payload, but exploiting it required knowing the template ID to edit, and brute forcing that ID was not feasible at the time, so the issue was left alone.
Two terms from that paragraph:
- Self-stored XSS: script that a user saves into a field and that runs when that same user views the saved content. It is stored on the server, but normally only harms the person who entered it.
- Template ID: a number the site uses to tell one template from another, the way a customer number identifies a customer. If you want to edit a particular template, you have to name its ID.
- Brute forcing: trying every possible value in turn until one works. With a long number that takes far too long, which is why the researcher dropped the idea at first.
On returning to the target, the researcher captured requests in Burp and found an interesting request. Sending it to Repeater and resending it produced a new template in the template list. Scanning the request showed no CSRF protection. The request also includes the template ID, which can be used to write content into the template fields. That is what made the earlier self-stored XSS reachable: the two bugs could be combined.
What "no CSRF protection" means: a well-defended site attaches a secret value to each state-changing request, a CSRF token, so that a request forged by another site cannot carry it. Here there was no such value to check, so a request coming from anywhere would be accepted as long as the victim's browser sent it with the victim's login.

Exploitation
The researcher wrote an HTML file as the proof of concept:
<form action="https://subdomain.example.com/endpoint" method="POST"> <input type="text" name="svcid" value="WRKSPC_LAYER_SERVICE"><br> <input type="text" name="stok" value=""><br> <input type="text" name="v" value="0"><br> <input type="text" name="clientType" value=""><br> <input type="text" name="request" value='{"basePage":{"draftIds":["1514844016810"],"wsId":"-1","wsType":"-1"},"fields":{"title":"CSRF_1","bold":"false"},"fields":{"description":"<font rwr=\"1\" style=\"font-family:Arial\" size=\"4\"><br>\"><svg onload=\"alert(cookie)\">\n</svg></font>","rteMode":"0"},"mode":"INDIVIDUAL","action":"SAVE","layerName":"EDITPANE","variation":null,"currencyInfo":{"currencySymbolLeft":true,"singularName":"U.S. dollars","moneySymbol":"$","decimalSymbol":".","groupingSymbol":",","gS":",","decimalPlaces":"2","currencyCode":"USD","pluralName":"U.S. dollar"},"singleList":true,"listingMode":"AddItem","updateRequired":true,"customFields":{},"byPassUpdate":false,"sellerType":"C2C","saveUlsi":true,"edpCrNew":false,"deletedFields":[],"customAttributes":{"PL_SELLER_ELIGIBLE":"1","PL_FORMAT_ELIGIBLE":"1","PL_CATEGORY_ELIGIBLE":"1","PL_ALREADY_OPTED":"0"},"draftMode":"Listing","restricted":false,"customPreference":{"preferences":{"scheduleStartTime":true,"reservePrice":true,"sellAsLot":true,"privateListing":true,"salesTax":true},"sellerDetails":["BUSINESS_POLICY","NO_STORE_SUBSCRIPTION","NO_SHIPPING_DISCOUNTS","NON_SM_SELLER"]},"payments20":false,"templateId":5553489011,"isvShown":false}'><br> <input type="submit" value="send"></form>
Step 1: deliver the forged request
The form posts to https://subdomain.example.com/endpoint with method="POST". The visible fields are svcid set to WRKSPC_LAYER_SERVICE, stok left empty, v set to 0, and clientType left empty. The substantive content is the request field, a JSON document carried as a form value.
Line by line, in plain words:
<form action="https://subdomain.example.com/endpoint" method="POST">opens a form.actionis the address the browser will send the form to, andmethod="POST"says the data travels in the body of the request rather than in the address bar. A POST is the method sites use when something is being created or changed, as opposed to simply read.- The first four
<input>lines are ordinary form fields. Each has aname(the label the server sees) and avalue(what is sent).stokandclientTypeare sent empty. - The
requestinput is the important one. Its value is a long piece of JSON, a text format for structured data: curly braces group things, and each entry is a name followed by a value. It is wrapped in single quotes so the double quotes inside it do not end the attribute early. <input type="submit" value="send">is the button that submits the form.
Why a form on another site works at all: when your browser sends a request to a site, it also attaches the cookies that site gave you. A cookie is a small piece of data a site stores in your browser so it can recognise you on the next request, which is how you stay logged in. The browser does not ask whether the page that made the request was written by the site itself. That is the gap CSRF lives in.
Step 2: understand the JSON body
Inside request, basePage.draftIds contains 1514844016810, and templateId is 5553489011. The fields object carries title set to CSRF_1 and bold set to false; a second fields key carries description and rteMode set to 0. The description value is the XSS payload wrapped in a font tag:
<font rwr="1" style="font-family:Arial" size="4"><br>"><svg onload="alert(cookie)">
</svg></font>
What each part of that payload does:
<font ...>is a tag that sets how the text looks. It is only there to make the value look like ordinary formatted text.<br>is a line break.">is an escaped greater-than sign. Escaping is how HTML writes a character that would otherwise be read as part of the markup.<svg onload="alert(cookie)">is the actual attack.svgis a tag for drawing graphics, andonloadis an event: the browser runs the code in it as soon as the element has loaded.alert(cookie)makes the browser pop up a box showing the value ofcookie.
The remaining keys describe the save operation: mode is INDIVIDUAL, action is SAVE, layerName is EDITPANE, listingMode is AddItem, updateRequired is true, byPassUpdate is false, saveUlsi is true, edpCrNew is false, draftMode is Listing, restricted is false, payments20 is false and isvShown is false. There are also currency settings, an empty customFields object, an empty deletedFields array, a customAttributes object with four PL_* flags, and a customPreference object listing preferences and seller details. The researcher does not explain what each of these keys does; they are part of the captured request as sent.
Two more words from that list:
- API: the set of addresses and data formats a site offers so that a program, rather than a person clicking, can ask it to do things. The
requestJSON is the shape this site's API expects. - Endpoint: one specific address on a server that accepts requests, here
https://subdomain.example.com/endpoint.
Step 3: create the template through the missing ID
The request is meant to edit a template with ID 1514844016810. Because the server does not find a template with that ID, it creates one instead, with the supplied values, including the XSS payload in the description. This is the behaviour the researcher observed in Repeater: resending the request added a new template to the template list.
Think of it like a form at a hotel reception that says "change the booking with number X". If no booking with that number exists, a sensible system refuses. This one treated the unknown number as a request to make a new booking with the details on the form. That is what let the attacker choose a number that certainly does not exist and still get a template created.
Step 4: trigger the payload
When the victim visits their template list, the newly created template appears there. Opening it executes the payload in the description, which calls alert(cookie).
The victim does nothing suspicious: they log in as usual, load the attacker's page at some point, and later open what looks like an ordinary new template. The script runs inside their logged-in session.
Root cause
The save endpoint accepts a state-changing POST without any CSRF protection, so a page on another origin can submit it on behalf of an authenticated user. The description field stores the HTML payload, and the <svg onload=...> handler runs when the template is opened. The combination is what turns a self-stored XSS, which normally only affects the person who enters it, into an attack delivered to another user. The report does not describe the server-side validation or output encoding in any more detail, so the exact sanitisation gap is not stated.
Two terms from that paragraph:
- Origin: the combination of scheme, host and port that a page comes from, roughly "which site this page belongs to". A page from one origin is not supposed to be able to act on another origin using your login.
- Sanitisation: cleaning input so that anything dangerous in it is removed or neutralised before it is stored or shown. Without it, HTML typed into a field is stored as-is and later treated as real markup by the browser.
Impact
An attacker who gets a logged-in victim to load the proof-of-concept page can create a template in the victim's account containing script. The script runs in the victim's session when they open the template, and the payload calls alert(cookie). The attack requires the victim to be authenticated and to visit the attacker's page, and then to open the new template from their list.
Fix
The two fixes implied by the findings are CSRF protection on the save endpoint, such as a token tied to the user's session, and sanitisation or encoding of the description field so that HTML such as <svg onload=...> cannot be stored and executed.
Variants to test
- Resend any template or content save request in
Repeaterwithout a CSRF token and see whether a new object appears in the account. A positive result is a new entry in the list after a request sent from a different origin. - Submit a description containing an event-handler payload such as
<svg onload=alert(1)>and open the saved item. A positive result is script execution when the item is rendered. - Try a non-existent ID in a save request that is meant to edit an existing object. A positive result is the server creating a new object with the supplied values instead of rejecting the request.
- Check whether the same save endpoint accepts a request with no
OriginorRefererheader, which would confirm that no origin check is in place.
Glossary
- API: the set of addresses and data formats a site offers so that a program can ask it to do things, instead of a person clicking.
- Burp Suite: a program that sits between your browser and a website so you can read, change and resend requests.
- Cookie: a small piece of data a site stores in your browser so it can recognise you on later requests, which is how you stay logged in.
- CSRF (cross-site request forgery): making a logged-in user's browser send a request to a site that the user did not intend to send.
- CSRF token: a secret value attached to a request and checked by the server, so a request forged by another site cannot succeed.
- Endpoint: one specific address on a server that accepts requests.
- Escaping: writing a character in a form that will not be mistaken for part of the markup, such as
>for>. - JSON: a text format for structured data, using curly braces and name/value pairs.
- Origin: the scheme, host and port a page comes from, roughly which site it belongs to.
- POST: the request method used when something is being created or changed, with the data in the request body.
- Proxy: a program that sits in the middle of a connection and passes traffic through, so it can be inspected.
- Repeater: the Burp Suite panel where a captured request can be resent, with changes, as many times as you like.
- Request: the message a browser sends to a server asking it to do something.
- Sanitisation: cleaning input so anything dangerous is removed or neutralised before it is stored or shown.
- Self-stored XSS: script a user saves into a field that runs when that same user views the saved content.
- Template: a saved starting point with fields such as a title and a description that a user can open and edit later.
- Template ID: the number a site uses to tell one template from another.
- XSS (cross-site scripting): getting a site to store or show script that then runs in another user's browser.