Writing my Medium blog to complete account takeover
Medium's story editor allowed links with a javascript: scheme, leading to stored XSS. An attacker could use this to change a victim's email address and take over their account.
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
Medium is a publishing platform where writers compose stories in a browser-based editor. A story is built from paragraphs, and paragraphs can carry markups: links with an href, a title, a rel and an anchor type. When a reader opens a published story, those markups become clickable links.
The feature under test was the story editing page and, in particular, the ability to add links to a story. The second feature involved was the Unsplash image component: when a writer inserts an Unsplash photo into a story, Medium stores the photo's credit text ("Photo by Some Author on Unsplash") together with two links, one for the photo creator and one for the photo source.
Setup
The researcher was working on his own Medium account while writing a blog post, and used Burp Suite to intercept the request that adds an Unsplash image to a story. No other tooling, versions or preconditions are described in the report. The session cookie on Medium is set to HTTP Only, which matters later because it rules out simply reading the cookie from script.
Finding it
While taking a break from writing, the researcher started poking at the story editing page. He noticed that he could add links with a special scheme such as mailto:, and asked himself the obvious follow-up question: if mailto: is accepted, what about javascript:?
His first attempt did not work:
javascript:
He was about to move on, but tried again with mixed case:
jAvAsCrIpT:confirm()
That worked. The link was stored in the story, and when he opened the story as a reader and clicked the link, a confirm dialog popped up. In other words, a stored XSS in stories, the core object of the platform.
The reader clicks on the link and a confirm dialog pops up.
He reported the issue and went to bed.
Exploitation
Step 1: stored XSS through a story link
The first finding needs no request capture in the report: a link whose href is jAvAsCrIpT:confirm() is accepted by the editor, persisted with the story, and executed when a reader clicks it. The all-lowercase javascript: did not work; the mixed-case spelling did.
Step 2: stored XSS through the Unsplash image component
The next morning the researcher went looking for a second instance. He added an Unsplash image to a story and intercepted the request with Burp Suite. The request looked like this:
The request is a delta update against the story identified as 8f2xxxxxxx, sent to /p/8f2xxxxxxx/deltas with a logLockId query parameter. It carries the usual JSON headers plus X-Obvious-CID, X-XSRF-Token, X-Client-Date and the session cookie. The body describes a single delta of type 3 at index 1: a paragraph of type 4 whose text is the Unsplash credit line, with two markups of type 3. The first markup spans characters 9 to 17 and has rel set to photo-creator; the second spans 21 to 29 and has rel set to photo-source. Both href values point at https://medium.com/r/?url= wrapping the URL-encoded Unsplash profile URL. The paragraph metadata carries the photo id, dimensions and an unsplashPhotoId.
He replaced both href values with the same payload he had used on the first XSS. The tampered body looked like this:
{"id":"8f2xxxxxxx","deltas":[{"type":3,"index":1,"paragraph":{"name":"exxx","type":4,"text":"Photo by Some Author on Unsplash","markups":[{"type":3,"start":9,"end":17,"href":"jAvAsCrIpT:confirm()","title":"","rel":"photo-creator","anchorType":0},{"type":3,"start":21,"end":29,"href":"jAvAsCrIpT:confirm()","title":"","rel":"photo-source","anchorType":0}],"layout":1,"metadata":{"id":"0*xxxxxx","originalWidth":"\"alt='test'","originalHeight":5219,"alt":"","unsplashPhotoId":"xxxxx"}},"verifySameName":true}],"baseRev":28}
It worked: a second stored XSS, this time in the Unsplash image component.

Another stored XSS in the Unsplash image component.
Step 3: from XSS to full account takeover
Medium's bug bounty page pays $100 for XSS, but the researcher wanted the higher tier:
Bugs leaking or bypassing significant security controls: $1000
To reach it he set out to demonstrate a complete account takeover. Because the session cookie is HTTP Only, stealing the cookie is not an option, so the attack has to act inside the victim's authenticated session instead.
He went to his own user profile and checked whether he could change his email address to another one without entering his password. He could. He then manually changed his email, used the "magic link" feature that sends a temporary login link to the new address, and was logged in to the account under the new email address.
That gives the two steps the automated attack needs:
- Get the user's XSRF token (no cookies for the attacker, as noted above).
- Send a PUT request to the
/me/emailendpoint with the new email.
The final payload he used:
JaVaScRiPt:var x=window.__PRELOADED_STATE__.session.xsrf;var h = new XMLHttpRequest();h.open(‘PUT’, ‘/me/email’, true);h.setRequestHeader(‘Content-Type’, ‘application/json’);h.setRequestHeader(‘X-XSRF-Token’, x);h.send(‘{“email”:”[redacted]”}’);
The payload reads the XSRF token out of window.__PRELOADED_STATE__.session.xsrf, opens an XMLHttpRequest with the PUT method against /me/email, sets Content-Type: application/json and the X-XSRF-Token header to the value it just read, and sends a JSON body containing the new email address. The request runs in the victim's browser, so it carries the victim's session cookie automatically; the XSRF token is supplied from the page state rather than from a cookie the attacker cannot read.
Root cause
The report does not describe the server-side validation code. What it shows is that the editor and the delta endpoint accepted a javascript: scheme in link href values, and that the check in place was defeated by changing the case of the scheme: javascript: was rejected, jAvAsCrIpT: was not. The same payload worked in the Unsplash image component, where the two credit links are written from the request body.
The account takeover itself does not depend on a flaw in the email change flow: changing the email without a password and logging in through the magic link are the product's intended behaviour. The XSS is what turns that behaviour into a takeover, because it lets the attacker drive the change from the victim's authenticated session. The HTTP Only cookie flag did its job of protecting the cookie, but it does not stop script running in the page from issuing authenticated requests.
Impact
An attacker who can get a victim to open a story containing the malicious link and click it can run script in the victim's session on medium.com. With the payload above, that script changes the victim's account email to an address the attacker controls, after which the attacker uses the magic link sent to that address to log in as the victim. The result is a complete account takeover without ever reading the session cookie.
The report does not state which users or stories were affected beyond the researcher's own account, nor how a victim would be lured into clicking. The bounty page quoted in the report lists $100 for XSS and $1000 for bugs leaking or bypassing significant security controls.
Fix
The timeline records that the issue was fixed on August 3, 2019, and the researcher was given approval to disclose. What the fix needs to do, based on the finding, is validate link schemes on the server side for every place a link is stored, including story markups and the Unsplash credit links, by parsing the URL and allowing only an explicit list of safe schemes rather than comparing against a blocklist in a case-sensitive way.
Variants to test
- Case and encoding tricks on scheme filters. Submit
jAvAsCrIpT:, mixed case variants, and schemes with embedded whitespace or control characters where the application accepts a URL. A positive result is a stored link that executes script when clicked. - Every field that becomes an
href. Look beyond the main link editor: image credits, embeds, captions, profile fields, and any markup object with arelsuch asphoto-creatororphoto-source. A positive result is a storedjavascript:value in any of them that survives a reload. - Direct delta or update endpoints. Capture the request that saves content and replay it with a modified body, bypassing the editor UI entirely. A positive result is the server accepting a payload the UI would have blocked.
- Token exposure in page state. Check whether the XSRF token is readable from a global such as
window.__PRELOADED_STATE__. A positive result is a token you can read and reuse in a cross-site request from injected script. - Sensitive state-changing endpoints without re-authentication. Test whether email change, password change or similar actions require the current password. A positive result is a change that succeeds with only the session and the XSRF token, which is what makes an XSS escalate to takeover.
What happened, in plain words
A security researcher was writing a blog post on Medium, a website where people publish articles. While taking a break, he started clicking around the page where you edit a story. He discovered that he could put a special kind of link into his story that, when a reader clicked it, would run a small piece of computer code inside the reader's browser. That kind of bug is called a cross-site scripting bug, or XSS for short.
He reported it, then went looking for more. The next day he found a second place with the same weakness: the part of the editor that lets you add a photo from Unsplash, a free photo website. Then he went further. He worked out how to use that code to change a victim's email address and then log in as that victim. That is called a full account takeover.
This article walks through the whole thing from the beginning, assuming you have never done any security work before. Every technical word is explained the first time it appears, and there is a glossary at the end.
Some background first
What Medium is
Medium is a publishing platform. Writers write articles, called stories, in an editor that runs inside a web browser. A story is made of paragraphs. A paragraph can carry things called markups, which are basically links. Each link has a few pieces of information attached to it:
- an
href, which is the address the link points to (the thing that happens when you click it); - a
title, which is a tooltip shown when you hover over it; - a
rel, which is a label describing what the link is for; - an anchor type, which is a number telling the platform what kind of link it is.
When a reader opens a published story, those markups are turned into clickable links.
What an API is
When you use a website, your browser is constantly talking to the website's servers behind the scenes. Every time you type something, add a photo, or save a draft, your browser sends a message to a server asking it to do something. Those messages are called requests, and the set of addresses a website accepts requests at is often called its API (application programming interface).
A useful comparison: think of a restaurant. You (the browser) do not walk into the kitchen. You tell the waiter (the request) what you want, the waiter takes it to the kitchen (the server), and the kitchen sends back a plate (the response). The menu of things you are allowed to order is the API.
What a cookie is
When you log in to a website, the server needs a way to remember that you are logged in on the next page you visit. It does this by giving your browser a small piece of data called a cookie. Your browser stores it and sends it back with every request to that website. The cookie is effectively your proof of identity: anyone who has it can act as you.
A cookie can be marked HTTP Only. That is a setting that tells the browser: this cookie may only be sent to the server, and JavaScript code running on the page is not allowed to read it. It is a protection against exactly the kind of attack described here, where malicious code runs in a victim's browser and tries to steal the cookie.
What a token is
A token is a short string of characters that acts like a temporary pass. Websites often use a specific kind called an XSRF token (also written CSRF token). Its job is to prove that a request genuinely came from the website's own pages and not from some other site trying to trick your browser into doing something. The token is generated by the server, embedded in the page, and must be sent back with certain requests.
What stored XSS means
XSS stands for cross-site scripting. It means getting your own code to run inside someone else's browser, in the context of a website they trust. The code then behaves as if the website itself had written it: it can read what the page can read and do what the page can do.
Stored XSS is a specific flavour. The malicious content is saved on the server (stored), for example inside a story, and then served to every reader who opens that story. The attacker does not need to be present when the victim is attacked; the trap sits there waiting.
A comparison: imagine a noticeboard in an office where anyone can pin a note. If someone pins a note that says "whoever reads this, go and unlock the back door", and the building's staff follow instructions written on the noticeboard without question, that is stored XSS. The note was stored once and affects everyone who reads it.
What Burp Suite is
Burp Suite is a tool used by security testers. It sits between your browser and the website and lets you look at, pause, and change the requests your browser sends before they reach the server. It is like a postal worker who lets you open a letter, rewrite it, and then seal it back up before delivery.
Setting up
The researcher was working on his own Medium account while writing a blog post. He used Burp Suite to intercept the request that adds an Unsplash image to a story. That is the whole setup described: no special versions, no other tools, no preconditions. One detail matters later: Medium's session cookie is set to HTTP Only, so simply reading the cookie from script is not possible.
Finding the first bug
While taking a break from writing, the researcher started poking at the story editing page. He noticed he could add links with a special scheme such as mailto:. A scheme is the first part of a link, before the colon: it tells the browser what kind of link it is. mailto: means "open an email program". https: means "go to a web page".
That raised an obvious question: if mailto: is accepted, what about javascript:? The javascript: scheme tells the browser that what follows the colon is code to run, not an address to visit. If a website lets you store a javascript: link, then clicking that link runs your code.
His first attempt did not work:
javascript:
He was about to move on, but tried again with the letters in mixed upper and lower case:
jAvAsCrIpT:confirm()
That worked. The link was saved in the story. When he opened the story as a reader and clicked the link, a confirm dialog popped up. confirm() is a built-in browser function that shows a small pop-up box with an OK and Cancel button; it is the simplest possible proof that code is running.
The reader clicks on the link and a confirm dialog pops up.
So this was a stored XSS in stories, the core object of the platform. He reported the issue and went to bed.
Why the mixed case mattered
The all-lowercase javascript: did not work, but the mixed-case spelling did. Browsers, on the other hand, do not care about the case of a scheme: jAvAsCrIpT: and javascript: mean exactly the same thing to them. So the check said "no" while the browser said "yes". This is a classic mismatch between how a filter reads text and how the thing it is protecting reads the same text.
Finding the second bug
The next morning the researcher went looking for a second instance of the same weakness. He added an Unsplash image to a story and intercepted the request with Burp Suite. Here is what the request looked like:
Let us go through this line by line, in plain words.
POST /p/8f2xxxxxxx/deltas?logLockId=970 HTTP/1.1is the first line of the request.POSTis the method, meaning "I am sending data for you to save"./p/8f2xxxxxxx/deltasis the address on the server being called;8f2xxxxxxxis the identifier of the story being edited, anddeltassuggests the endpoint accepts changes (deltas) to that story.?logLockId=970is a query parameter, a small extra value appended to the address.HTTP/1.1is the version of the protocol being spoken.Host: medium.comsays which website the request is for.User-Agent: [Redacted]identifies the browser or tool making the request. The value has been hidden here.Accept: application/jsonsays the browser expects a response in JSON, a text format for structured data.Accept-Language: en-US,en;q=0.5says the browser prefers English responses.Accept-Encoding: gzip, deflatesays the browser can accept compressed responses.Referer: https://medium.com/p/8f2xxxxxxx/editsays which page the request came from: the edit page for this story.X-Obvious-CID: webis a custom header. Headers are extra labelled pieces of information attached to a request. TheX-prefix is a convention for custom headers. This one appears to identify the client as the web app.X-XSRF-Token: [Redacted]is the XSRF token described earlier, hidden here.X-Client-Date: [Redacted]is another custom header, presumably carrying a date, hidden here.Content-Type: application/jsonsays the body of the request is JSON.Content-Length: 536says the body is 536 bytes long.Connection: closeasks the server to close the connection after responding.Cookie: [Redacted]is the session cookie, hidden here. This is the piece of data that proves who is logged in.- The long JSON line after the headers is the body, the actual content being saved. It describes a single change (a delta) to the story. The paragraph being added is of type 4 and its text is the Unsplash credit line, "Photo by Some Author on Unsplash". Inside it there are two markups, both of type 3. The first covers characters 9 to 17 of the text and is labelled
photo-creator; the second covers characters 21 to 29 and is labelledphoto-source. Bothhrefvalues point athttps://medium.com/r/?url=followed by the URL-encoded address of the photographer's Unsplash profile. URL encoding is how special characters are written safely inside a web address;%3Ais a colon,%2Fis a slash, and so on. The paragraph also carries metadata: a photo id, its dimensions, and anunsplashPhotoId.
In short: when you insert an Unsplash photo, Medium saves the credit line and two links, one to the photographer and one to the photo source. Those two links are written straight from the request body.
He replaced both href values with the same payload he had used on the first XSS. The tampered body looked like this:
{"id":"8f2xxxxxxx","deltas":[{"type":3,"index":1,"paragraph":{"name":"exxx","type":4,"text":"Photo by Some Author on Unsplash","markups":[{"type":3,"start":9,"end":17,"href":"jAvAsCrIpT:confirm()","title":"","rel":"photo-creator","anchorType":0},{"type":3,"start":21,"end":29,"href":"jAvAsCrIpT:confirm()","title":"","rel":"photo-source","anchorType":0}],"layout":1,"metadata":{"id":"0*xxxxxx","originalWidth":"\"alt='test'","originalHeight":5219,"alt":"","unsplashPhotoId":"xxxxx"}},"verifySameName":true}],"baseRev":28}
Line by line, the only thing that changed is the two href values. Where they used to hold the Unsplash profile address, they now hold jAvAsCrIpT:confirm(). Everything else, the story id, the paragraph text, the character positions, the metadata, is identical. The point of changing only the href values is to test whether the server accepts the payload when it saves an image credit. It did.
It worked: a second stored XSS, this time in the Unsplash image component.

Another stored XSS in the Unsplash image component.
Turning the bug into a full account takeover
Why the researcher wanted more
Medium's bug bounty page pays $100 for XSS. A bug bounty programme is a scheme where a company pays people for reporting security problems. But the same page lists a higher tier:
Bugs leaking or bypassing significant security controls: $1000
So the researcher set out to demonstrate a complete account takeover, which is a much more serious outcome than a pop-up box. Account takeover means logging in as someone else and controlling their account.
The obstacle
Because the session cookie is HTTP Only, stealing the cookie is not an option. The attack therefore has to act inside the victim's already-logged-in session: instead of taking the victim's key, the malicious code uses the victim's browser, which is already holding the key, to make requests on the victim's behalf.
Checking the email change flow
He went to his own user profile and checked whether he could change his email address to another one without entering his password. He could. He then manually changed his email, used the "magic link" feature that sends a temporary login link to the new address, and was logged in to the account under the new email address.
A magic link is a login method where, instead of typing a password, you receive a special link by email; clicking it logs you in. In the researcher's own test, changing the email address did not require the current password. That is a normal product decision, not a bug by itself, but it is what makes the XSS dangerous.
The two steps of the automated attack
That gives the two steps the automated attack needs:
- Get the user's XSRF token (no cookies for the attacker, as noted above).
- Send a PUT request to the
/me/emailendpoint with the new email.
A PUT request is a method, like POST, used to update something that already exists. /me/email is the address that handles changing the logged-in user's email. The XSRF token is needed because the server will reject a state-changing request that does not carry it, and the attacker cannot read the cookie, so the token has to be obtained another way: from the page itself.
The final payload
The final payload he used:
JaVaScRiPt:var x=window.__PRELOADED_STATE__.session.xsrf;var h = new XMLHttpRequest();h.open(‘PUT’, ‘/me/email’, true);h.setRequestHeader(‘Content-Type’, ‘application/json’);h.setRequestHeader(‘X-XSRF-Token’, x);h.send(‘{“email”:”[redacted]”}’);
Line by line, in plain words:
JaVaScRiPt:is the scheme again, in mixed case to slip past the filter. Everything after the colon is code the browser will run when the link is clicked.var x=window.__PRELOADED_STATE__.session.xsrf;creates a variable calledxand stores in it the XSRF token.window.__PRELOADED_STATE__is a global object that the page itself puts data into so its own scripts can read it; the token happens to be sitting there undersession.xsrf. This is how the attacker gets the token without reading the cookie.var h = new XMLHttpRequest();creates an XMLHttpRequest object. That is the browser's built-in way for JavaScript to send a request to a server without reloading the page.h.open(‘PUT’, ‘/me/email’, true);prepares the request: methodPUT, address/me/email, andtruemeaning do it asynchronously (do not freeze the page while waiting).h.setRequestHeader(‘Content-Type’, ‘application/json’);tells the server the body will be JSON.h.setRequestHeader(‘X-XSRF-Token’, x);attaches the token read a moment ago, so the server will accept the request as legitimate.h.send(‘{“email”:”[redacted]”}’);actually sends the request, with a JSON body asking to change the account's email to the attacker's address.
Because this code runs in the victim's browser, the request automatically carries the victim's session cookie. The XSRF token is supplied from the page state rather than from a cookie the attacker cannot read. The server sees a request that looks exactly like the victim changing their own email.
Why it worked
The report does not describe the server-side validation code. What it shows is that the editor and the delta endpoint accepted a javascript: scheme in link href values, and that the check in place was defeated by changing the case of the scheme: javascript: was rejected, jAvAsCrIpT: was not. The same payload worked in the Unsplash image component, where the two credit links are written from the request body.
An allow-list means "only these values are permitted"; a blocklist means "these values are forbidden". Allow-lists are safer because there are endless ways to spell a forbidden value, and a blocklist has to anticipate every one of them.
The account takeover itself does not depend on a flaw in the email change flow: changing the email without a password and logging in through the magic link are the product's intended behaviour. The XSS is what turns that behaviour into a takeover, because it lets the attacker drive the change from the victim's authenticated session. The HTTP Only cookie flag did its job of protecting the cookie, but it does not stop script running in the page from issuing authenticated requests.
What the impact was
An attacker who can get a victim to open a story containing the malicious link and click it can run script in the victim's session on medium.com. With the payload above, that script changes the victim's account email to an address the attacker controls, after which the attacker uses the magic link sent to that address to log in as the victim. The result is a complete account takeover without ever reading the session cookie.
The report does not state which users or stories were affected beyond the researcher's own account, nor how a victim would be lured into clicking. The bounty page quoted in the report lists $100 for XSS and $1000 for bugs leaking or bypassing significant security controls.
How it was fixed
The issue was fixed on August 3, 2019, and the researcher was given approval to disclose. What the fix needs to do, based on the finding, is validate link schemes on the server side for every place a link is stored, including story markups and the Unsplash credit links, by parsing the URL and allowing only an explicit list of safe schemes rather than comparing against a blocklist in a case-sensitive way.
Timeline
- July 10, 2019: initial report.
- July 10, 2019: report updated with the second stored XSS in the Unsplash image component.
- July 12, 2019: report updated with the complete account takeover demonstration.
- July 13, 2019: first response from Medium's security team.
- August 3, 2019: issue fixed, and approval given to disclose.
- August 6, 2019: researcher added to Medium's humans.txt file.
Things worth testing elsewhere
These are the general lessons from this report, phrased as things to try on other sites.
- Case and encoding tricks on scheme filters. Submit
jAvAsCrIpT:, mixed case variants, and schemes with embedded whitespace or control characters where the application accepts a URL. A positive result is a stored link that executes script when clicked. - Every field that becomes an
href. Look beyond the main link editor: image credits, embeds, captions, profile fields, and any markup object with arelsuch asphoto-creatororphoto-source. A positive result is a storedjavascript:value in any of them that survives a reload. - Direct delta or update endpoints. Capture the request that saves content and replay it with a modified body, bypassing the editor UI entirely. A positive result is the server accepting a payload the UI would have blocked.
- Token exposure in page state. Check whether the XSRF token is readable from a global such as
window.__PRELOADED_STATE__. A positive result is a token you can read and reuse in a cross-site request from injected script. - Sensitive state-changing endpoints without re-authentication. Test whether email change, password change or similar actions require the current password. A positive result is a change that succeeds with only the session and the XSRF token, which is what makes an XSS escalate to takeover.
Glossary
- Account takeover: gaining control of someone else's account, for example by changing their email and logging in as them.
- Allow-list: a rule that permits only an explicit set of values and rejects everything else.
- Anchor type: a number in a link's data describing what kind of link it is.
- API: the set of addresses and rules a website's servers accept requests at.
- Blocklist: a rule that forbids a list of known-bad values and allows everything else.
- Body: the main content of a request, as opposed to its headers.
- Bug bounty: a programme where a company pays people for reporting security problems.
- Burp Suite: a tool that sits between browser and server so requests can be inspected and modified.
- Cookie: a small piece of data a website stores in your browser to remember who you are.
- Cross-site scripting (XSS): getting your own code to run in someone else's browser in the context of a website they trust.
- CSRF / XSRF: cross-site request forgery; an attack where another site tricks your browser into making a request. The XSRF token is the defence against it.
- Delta: a change to a document, describing only what is added or modified.
- Endpoint: a specific address on a server that accepts requests.
- Header: a labelled piece of extra information attached to a request or response.
href: the address a link points to.- HTTP Only: a cookie setting that stops JavaScript on the page from reading the cookie.
- JSON: a text format for structured data, made of names and values.
- Magic link: a login method where clicking a link sent by email logs you in instead of typing a password.
- Markup: a link attached to a piece of text, with an
href,title,reland anchor type. - Method: the verb of a request, such as
GET(fetch),POST(send data) orPUT(update). - Paragraph: a block of a story; in this report, the unit that carries text and markups.
- Payload: the piece of code or data an attacker uses to carry out an attack.
- Query parameter: a small extra value appended to an address after a
?. rel: a label on a link describing its purpose, such asphoto-creatororphoto-source.- Request: a message a browser sends to a server asking it to do something.
- Response: the message a server sends back.
- Scheme: the part of a link before the colon, such as
https:,mailto:orjavascript:, telling the browser what kind of link it is. - Session: the period during which a website remembers you as logged in.
- Stored XSS: XSS where the malicious content is saved on the server and served to everyone who views it.
- Token: a short string acting as a temporary pass, used to prove a request is legitimate.
- URL encoding: writing special characters in a web address in a safe form, such as
%3Afor a colon. - XMLHttpRequest: the browser's built-in way for JavaScript to send requests to a server without reloading the page.