Skip to content
XSS Write-up Intermediate

MonkeyType.com Stored Cross-Site Scripting

Tyle Butler Follow

Published on web.archive.org

Bounty$40 View original

In May 2021, independent security researcher Tyler Butler found several critical vulnerabilities in monkeytype.com, a popular open-source typing-test application with a booming community of over 100k daily unique visitors. The vulnerabilities included stored cross-site scripting and user impersonation in the tribe…

Tyler Butler, on web.archive.org

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

Context

Monkeytype is an open-source typing-test application that started in early 2020. By late May 2021 the lead developer was reporting 100k daily unique visitors, 228k registered accounts, 139 million started tests, 54 million completed tests and 2.22 billion seconds of typing, which the researcher notes is around 70 years. The site had over 40 million page views at the time.

The feature at the centre of this write-up is tribe, available on the beta site at dev.monkeytype.com. Tribe lets users join rooms, chat, and compete in typing challenges together. The chat runs over socket.io, and the leaderboard is backed by a cloud function at us-central1-monkey-type.cloudfunctions.net.

In May 2021 the researcher found three issues: stored cross-site scripting and user impersonation in tribe chat, and an authentication bypass that allowed arbitrary leaderboard entries. All were triaged, and the developer also accepted a pull request adding a security policy and a security.txt file.

Setup

The only tool named in the report is BurpSuite, configured to intercept browser traffic. The proof of concept for the XSS requires an account able to create or join a tribe room. The leaderboard request carries a bearer token, so it is made as an authenticated user. The researcher used the beta site https://dev.monkeytype.com/tribe for the chat issues and https://monkeytype.com as the origin for the leaderboard request.

Disclosure went through the project's bug report policy at the time: the researcher contacted the developer on Discord and opened GitHub issues. The leaderboard issue was the first one submitted through huntr.dev.

Finding it

The tribe chat applies client-side validation, but that validation does not protect against payloads injected directly into modified socket requests. Because the socket message carries both a message field and a from.name field, and the server appears to trust what the client sends, two separate problems follow: markup in either field is stored and rendered to other users, and the sender identity in the message can be rewritten.

The leaderboard endpoint accepts a full result object from the client. A crafted POST can inject any user into the leaderboard with any wpm value.

Exploitation

Step 1: stored XSS in tribe chat

  1. Configure BurpSuite to intercept browser traffic.
  2. Navigate to https://dev.monkeytype.com/tribe.
  3. Click on "create room".
  4. Turn on BurpSuite proxy interception.
  5. Enter a new chat string.
  6. Intercept the web socket traffic and change the chat string to an XSS payload.
  7. Stop intercepting traffic and browse the chat room. The payload executes; in this example it executes on click.

The report shows the raw socket message being intercepted and modified by adding an svg alert payload:

From the original on web.archive.org

The payload used is:

Text
42["mp_chat_message",{"isSystem":false,"isLeader":true,"message":"Hey <svg/onload=alert('foo');>","from":{"id":"UocD_4qRZiXGbXf8AA-n","name":"alice"}}]

The socket.io frame prefix 42 marks an event message. The event name is mp_chat_message. The message field holds the chat text, and the injected <svg/onload=alert('foo');> element fires its handler when the message is rendered. The from object carries the sender's id and name, and the flags isSystem and isLeader are also supplied by the client. The vulnerability applies to both the message and the name parameters.

Step 2: impersonation in tribe chat

  1. Go to a tribe chat room, for example https://dev.monkeytype.com/tribe_1d849e.
  2. Send a message, capturing the socket.io message:
Text
42["mp_chat_message",{"isSystem":false,"isLeader":true,"message":"Hey this is still alice","from":{"id":"UocD_4qRZiXGbXf8AA-n","name":"alice"}}]
  1. Modify the name parameter and re-send:
Text
42["mp_chat_message",{"isSystem":false,"isLeader":true,"message":"Hey this is still alice","from":{"id":"UocD_4qRZiXGbXf8AA-n","name":"bob"}}]

Only the name value changes, from alice to bob, and the message is then displayed as coming from bob. The same technique can produce messages that appear to come from the system.

Step 3: leaderboard injection

The following request overwrites the leaderboard, injecting the user pwnville_foo into position 9 with a faked wpm of 200:

HTTP
POST /checkLeaderboards HTTP/2
Host: us-central1-monkey-type.cloudfunctions.net
Content-Length: 750
Sec-Ch-Ua: " Not A;Brand";v="99", "Chromium";v="90"
Authorization: Bearer [redacted]
Sec-Ch-Ua-Mobile: ?0
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36
Content-Type: application/json
Accept: */*
Origin: https://monkeytype.com
Sec-Fetch-Site: cross-site
Sec-Fetch-Mode: cors
Sec-Fetch-Dest: empty
Referer: https://monkeytype.com/
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.9
Connection: close

{"data":{"uid":"aXi5udatSndUhoQR5pUtR6GpvGF3","lbMemory":{"time15":{"global":null,"daily":null},"time60":{"global":null,"daily":null}},"name":"pwnville_foo","banned":null,"verified":null,"discordId":null,"result":{"wpm":200.00,"rawWpm":200.00,"correctChars":250,"incorrectChars":6,"allChars":250,"acc":92,"mode":"time","mode2":15,"quoteLength":-1,"punctuation":false,"numbers":false,"timestamp":1622147912060,"language":"english","restartCount":0,"incompleteTestSeconds":0,"difficulty":"normal","testDuration":15.001134999999515,"afkDuration":0,"blindMode":false,"theme":"9009","tags":[],"consistency":83.22,"keyConsistency":45.56,"funbox":"none","bailedOut":false,"customText":null,"uid":"aXi5udatSndUhoQR5pUtR6GpvGF3","id":"vZkPA1dmzeUvaGQPkE4Z"}}}

The request targets /checkLeaderboards on the cloud function host. The Authorization: Bearer header carries the caller's token. The JSON body wraps everything in a data object: uid identifies the account, name is the display name to publish, lbMemory holds per-board memory for the 15 and 60 second boards, and result is the full test result, including wpm and rawWpm of 200, character counts, accuracy, mode, timestamp, language and the rest of the fields the client normally reports. The report notes that the server does invalidate requests containing cross-site scripting payloads, so the researcher believes this endpoint is not vulnerable to XSS.

The report shows the leaderboard spoofed using this crafted request sent in BurpSuite:

From the original on web.archive.org

After the request, the fake user appears as a top leader in words per minute:

From the original on web.archive.org

Root cause

The chat problems come from trusting client-supplied fields in socket.io messages. The message and from.name values are accepted as sent, and the client-side validation can be bypassed simply by editing the frame in transit. The isSystem and isLeader flags are also supplied by the client. The report says messages can be made to appear to come from other users or the system. The impersonation issue is described as improper authorisation in the socket.io implementation: the server does not check that the sender identity matches the authenticated session.

The leaderboard problem is an authentication bypass on /checkLeaderboards: users can spoof POST requests to inject any user into the leaderboard with any wpm. The developer's response, quoted in the report, was that he was "Looking into moving to a token-based auth system for this endpoint. All the other cloud functions will be moved to the token system after this has been solved since the publicity of this (having the ability to alter public leaderboards) takes priority".

Impact

Stored XSS in a chat room is described as severe. Once injected, the payload executes in the browsers of other users in the same room, and could be used to steal authentication tokens, allowing complete account takeover. Tribe also lets users invite others to specific rooms, so a room that has been exploited can be shared to increase the number of potential victims.

Impersonation lets a malicious user post as other users or as the system, which could enable abusive behaviour affecting users.

On the leaderboard, a malicious user can overwrite the entire leaderboard with username strings of their choosing, which could be used to deface the website.

Fix

The developer added client-side and server-side input validation to mitigate the XSS. The report includes the sanitiser:

JavaScript
function sanitize(string) {
  const map = {
      '&': '&amp;',
      '<': '&lt;',
      '>': '&gt;',
      '"': '&quot;',
      "'": '&#x27;',
      "/": '&#x2F;',
  };
  const reg = /[&<>"'/]/ig;
  return string.replace(reg, (match)=>(map[match]));
}
From the original on web.archive.org

For impersonation, the developer had already addressed the issue in a patch that was not yet released when the vulnerability was found. On 3 June the patch was merged into the development site at dev.monkeytype.com (issue 1503).

For the leaderboard, the stated plan was to move the endpoint to a token-based auth system, then migrate the other cloud functions.

Separately, the researcher and developer added a disclosure policy following the security.txt standard at /.well-known/security.txt, plus a security policy page on the main site, in pull request 1505. The security.txt content is:

Text
Contact: mailto:[redacted]
Contact: message @Miodec on discord.gg/monkeytype
Expires: 2022-06-03T21:00:00.000Z
Preferred-Languages: en
Canonical: https://monkeytype.com/.well-known/security.txt
Policy: https://monkeytype.com/security-policy
From the original on web.archive.org

The policy tells researchers that new vulnerabilities can be disclosed to the developer by email or private Discord chat.

Variants to test

  • Socket.io chat frames on other applications. Capture a chat frame, then edit the text field with a harmless marker such as <svg/onload=alert(1)> and the sender name field separately. A positive result is the marker executing in another user's browser, or the message rendering under the edited name.
  • Client-supplied identity fields. Change the from.id and from.name values to another user's and re-send. A positive result is the message appearing as that user, or as a system message when isSystem is set.
  • Client-supplied role flags. Set isLeader or equivalent privilege flags in the frame. A positive result is the UI granting the sender privileges it should not have.
  • Score submission endpoints. Replay a legitimate result submission with altered wpm, rawWpm or uid values. A positive result is the altered entry appearing on a public leaderboard.
  • Cross-user object references. Submit a result carrying another account's uid and name. A positive result is the entry being attributed to that account.
  • Server-side payload filtering. Where the report notes the server rejects XSS payloads on one endpoint, try the same payloads on other endpoints and in other fields to see whether the filtering is applied consistently.

Bug bounty

The leaderboard issue was the researcher's first submission on huntr.dev, a platform that pays for triaged vulnerabilities in open-source software that does not already run a programme with the large platforms. Authentication is through GitHub. The researcher opened an issue, waited for the developer to respond with a patch, and after the fix was awarded a 40 USD bounty.

From the original on web.archive.org

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

What happened, in plain words

Monkeytype is a website for practising typing. You are shown words, you type them, and the site measures how fast and how accurately you did it. It started in early 2020 and grew quickly: by late May 2021 the lead developer was reporting 100k daily unique visitors, 228k registered accounts, 139 million started tests, 54 million completed tests and 2.22 billion seconds of typing, which the researcher points out is around 70 years. The site had over 40 million page views at the time.

The part of the site this story is about is called tribe, and it lived on the beta version of the site at dev.monkeytype.com. Tribe lets people join a room, chat with each other, and compete in typing challenges together. Think of it as a small group chat attached to a typing game. The chat messages travel over a technology called socket.io, and the score table (the leaderboard) is run by a piece of code hosted in the cloud at us-central1-monkey-type.cloudfunctions.net.

In May 2021 an independent security researcher, Tyler Butler, found three problems:

  1. Stored cross-site scripting in the tribe chat. In plain words: a message could contain hidden instructions that a browser would run as if the site itself had written them.
  2. User impersonation in the same chat. A person could make a message look as though someone else had sent it.
  3. An authentication bypass on the leaderboard. A person could send a fake test result and put any name at any position with any score.

All three were triaged (reviewed and accepted as real), and the developer also accepted a pull request adding a security policy and a security.txt file to the site.

Setup

Before the details, a few words about the tools and ideas involved, because the rest of the article assumes them.

What a browser request is. When you load a page or send a chat message, your browser sends a request to a server and the server sends something back. Most of the time you never see this. A proxy is a program that sits between your browser and the server so you can look at, and change, those requests on the way through. The only tool named in the report is BurpSuite, configured to intercept browser traffic. "Intercept" means BurpSuite pauses each request and lets you edit it before it continues.

What a token is. After you log in, a site often gives your browser a short string of characters that proves who you are, so you do not have to type your password on every action. That string is a token (sometimes called a session token or cookie). Anyone who has it can act as you, which is why stealing one matters so much later in this story.

What an API is. An API is the set of addresses a website offers for programs to talk to it, rather than for people to click. For example, the leaderboard is not updated by a person clicking a button on a page; the page sends a request to an address like /checkLeaderboards and the server decides what to do. When we talk about an "endpoint", we mean one of those addresses.

What a cloud function is. A cloud function is a small piece of code that runs on a big provider's computers (here, Google's) and only when someone calls it. The site's own servers do not have to stay awake for it; the provider runs it on demand. The leaderboard endpoint lives on such a function.

What socket.io is. Ordinary web requests are one-off: you ask, the server answers, done. A chat needs a connection that stays open so messages can arrive at any moment. Socket.io is a library that keeps that kind of live connection open, and it sends small packets of text called frames back and forth. Each frame has a short numeric prefix that says what kind of frame it is.

The proof of concept for the chat problems needs an account that can create or join a tribe room. The leaderboard request carries a bearer token, so it is made as a logged-in user. The researcher used the beta site https://dev.monkeytype.com/tribe for the chat issues and https://monkeytype.com as the origin for the leaderboard request.

Disclosure went through the project's bug report policy at the time: the researcher contacted the developer on Discord and opened GitHub issues. The leaderboard issue was the first one submitted through huntr.dev.

Finding it

What "client-side validation" means. Validation is a check that input is acceptable. Client-side means the check happens in your own browser, in the page's code. That is useful for honest mistakes, but it is no defence against an attacker, because the attacker controls their own browser and can simply skip the check. The tribe chat applied client-side validation, but that validation did not protect against payloads injected directly into modified socket requests.

Because the socket message carries both a message field (the chat text) and a from.name field (who sent it), and the server appears to trust what the client sends, two separate problems follow: markup in either field is stored and shown to other users, and the sender identity in the message can be rewritten.

What "stored" means in stored XSS. A cross-site scripting (XSS) flaw is when a site lets someone else's text be treated as code by a visitor's browser. "Stored" means the bad text is saved on the server and then shown to everyone who views it later, rather than only affecting the person who sent it. A useful comparison: it is the difference between writing graffiti on your own notebook and writing it on a public noticeboard that everyone walks past.

The leaderboard endpoint accepts a full result object from the client. A crafted POST can inject any user into the leaderboard with any wpm value. A POST is simply the kind of request a browser uses to send data to a server, as opposed to a GET, which asks for a page.

Exploitation

Step 1: stored XSS in tribe chat

  1. Configure BurpSuite to intercept browser traffic.
  2. Navigate to https://dev.monkeytype.com/tribe.
  3. Click on "create room".
  4. Turn on BurpSuite proxy interception.
  5. Enter a new chat string.
  6. Intercept the web socket traffic and change the chat string to an XSS payload.
  7. Stop intercepting traffic and browse the chat room. The payload executes; in this example it executes on click.

Why each step: steps 1 to 3 get you into a room with the proxy watching. Step 4 is the important one, because it is what lets you see the raw chat frame instead of the friendly chat box. Step 5 gives you a normal message to edit, so you know exactly what a real frame looks like. Step 6 replaces the harmless text with something a browser will run. Step 7 lets the edited frame go through and then looks at the result, which is where the payload fires.

The report shows the raw socket message being intercepted and modified by adding an svg alert payload:

From the original on web.archive.org

The payload used is:

Text
42["mp_chat_message",{"isSystem":false,"isLeader":true,"message":"Hey <svg/onload=alert('foo');>","from":{"id":"UocD_4qRZiXGbXf8AA-n","name":"alice"}}]

Line by line, in plain words:

  • 42 is the socket.io frame prefix. The 4 marks an event message and the 2 marks the kind of event packet. In everyday terms, it is the envelope that says "this is a chat event".
  • ["mp_chat_message", ...] is the content of the envelope. The first item, mp_chat_message, is the event name: the server's label for "a chat message arrived".
  • "isSystem":false says this is not a system message. It is a flag supplied by the client, not decided by the server.
  • "isLeader":true says the sender is a room leader. Again, the client supplies it.
  • "message":"Hey <svg/onload=alert('foo');>" is the chat text. The Hey is ordinary text. The <svg/onload=alert('foo');> part is the trick: svg is a kind of image element a browser understands, and onload is an instruction that runs when that element loads. So when the message is displayed, the browser tries to load the svg and runs alert('foo'), which pops up a small box saying foo. A pop-up is harmless in itself; it is used here only to prove that code chosen by the sender ran in the viewer's browser.
  • "from":{"id":"UocD_4qRZiXGbXf8AA-n","name":"alice"} is the sender block. id is the account identifier and name is the display name shown next to the message.

The vulnerability applies to both the message and the name parameters, so the same kind of markup can be placed in the display name as well as in the text.

Step 2: impersonation in tribe chat

  1. Go to a tribe chat room, for example https://dev.monkeytype.com/tribe_1d849e.
  2. Send a message, capturing the socket.io message:
Text
42["mp_chat_message",{"isSystem":false,"isLeader":true,"message":"Hey this is still alice","from":{"id":"UocD_4qRZiXGbXf8AA-n","name":"alice"}}]
  1. Modify the name parameter and re-send:
Text
42["mp_chat_message",{"isSystem":false,"isLeader":true,"message":"Hey this is still alice","from":{"id":"UocD_4qRZiXGbXf8AA-n","name":"bob"}}]

Only the name value changes, from alice to bob, and the message is then displayed as coming from bob. The same technique can produce messages that appear to come from the system.

Why this works: the server takes the sender's name from the message itself instead of from the logged-in session. A comparison: it is like a postal service that prints the return address exactly as the sender wrote it, without checking it against the sender's ID. The isSystem and isLeader flags are also supplied by the client. The report says messages can be made to appear to come from other users or the system.

Step 3: leaderboard injection

The following request overwrites the leaderboard, injecting the user pwnville_foo into position 9 with a faked wpm of 200:

HTTP
POST /checkLeaderboards HTTP/2
Host: us-central1-monkey-type.cloudfunctions.net
Content-Length: 750
Sec-Ch-Ua: " Not A;Brand";v="99", "Chromium";v="90"
Authorization: Bearer [redacted]
Sec-Ch-Ua-Mobile: ?0
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36
Content-Type: application/json
Accept: */*
Origin: https://monkeytype.com
Sec-Fetch-Site: cross-site
Sec-Fetch-Mode: cors
Sec-Fetch-Dest: empty
Referer: https://monkeytype.com/
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.9
Connection: close

{"data":{"uid":"aXi5udatSndUhoQR5pUtR6GpvGF3","lbMemory":{"time15":{"global":null,"daily":null},"time60":{"global":null,"daily":null}},"name":"pwnville_foo","banned":null,"verified":null,"discordId":null,"result":{"wpm":200.00,"rawWpm":200.00,"correctChars":250,"incorrectChars":6,"allChars":250,"acc":92,"mode":"time","mode2":15,"quoteLength":-1,"punctuation":false,"numbers":false,"timestamp":1622147912060,"language":"english","restartCount":0,"incompleteTestSeconds":0,"difficulty":"normal","testDuration":15.001134999999515,"afkDuration":0,"blindMode":false,"theme":"9009","tags":[],"consistency":83.22,"keyConsistency":45.56,"funbox":"none","bailedOut":false,"customText":null,"uid":"aXi5udatSndUhoQR5pUtR6GpvGF3","id":"vZkPA1dmzeUvaGQPkE4Z"}}}

Line by line, in plain words:

  • POST /checkLeaderboards HTTP/2 is the request line. POST means "I am sending data". /checkLeaderboards is the endpoint being called. HTTP/2 is the version of the web protocol used.
  • Host: us-central1-monkey-type.cloudfunctions.net says which server the request is for: the cloud function host.
  • Content-Length: 750 is the size of the body that follows, in bytes.
  • Sec-Ch-Ua, Sec-Ch-Ua-Mobile and User-Agent describe the browser that is supposedly making the request. They are normal browser headers; here they simply make the request look like a real browser's.
  • Authorization: Bearer [redacted] is the token that proves who is calling. Bearer means "whoever holds this string is treated as the owner". The value is redacted here because it is a secret.
  • Content-Type: application/json says the body is in JSON, a common text format for structured data.
  • Accept: */* says the caller will accept any kind of response.
  • Origin: https://monkeytype.com and Referer: https://monkeytype.com/ say which site the request came from. They are part of how browsers describe the context of a request.
  • Sec-Fetch-Site, Sec-Fetch-Mode and Sec-Fetch-Dest are newer browser headers that describe the same context in more detail.
  • Accept-Encoding, Accept-Language and Connection: close are ordinary housekeeping headers: what formats and languages are welcome, and that the connection can be closed after the reply.
  • The blank line separates the headers from the body.
  • The body is one JSON object. data wraps everything. uid identifies the account. name is the display name to publish, here pwnville_foo. lbMemory holds per-board memory for the 15 and 60 second boards. banned, verified and discordId are account fields sent as null. result is the full test result: wpm and rawWpm of 200, correctChars 250, incorrectChars 6, allChars 250, acc 92, mode time, mode2 15, plus timestamp, language, duration, theme, consistency and the rest of the fields the client normally reports. The uid appears again inside result, and id is the identifier of the result itself.

The point of the request is that a crafted POST can inject any user into the leaderboard with any wpm value.

The report notes that the server does invalidate requests containing cross-site scripting payloads, so the researcher believes this endpoint is not vulnerable to XSS.

The report shows the leaderboard spoofed using this crafted request sent in BurpSuite:

From the original on web.archive.org

After the request, the fake user appears as a top leader in words per minute:

From the original on web.archive.org

Root cause

Root cause means the underlying mistake that makes a problem possible, as opposed to the particular trick used to show it.

The chat problems come from trusting client-supplied fields in socket.io messages. The message and from.name values are accepted as sent, and the client-side validation can be bypassed simply by editing the frame in transit. The isSystem and isLeader flags are likewise supplied by the client, which is why messages can be made to look like they come from the system. The impersonation issue is described as improper authorisation in the socket.io implementation: the server does not check that the sender identity matches the authenticated session. Authorisation is the check that a person is allowed to do what they are trying to do; here, the check that the name on a message really belongs to the person sending it.

The leaderboard problem is an authentication bypass on /checkLeaderboards: users can spoof POST requests to inject any user into the leaderboard with any wpm. Authentication is the check of who you are; a bypass means that check can be avoided or does not apply where it should.

The developer's response, quoted in the report, was that he was "Looking into moving to a token-based auth system for this endpoint. All the other cloud functions will be moved to the token system after this has been solved since the publicity of this (having the ability to alter public leaderboards) takes priority".

Impact

Impact means what harm the problem could actually cause, which is what decides how seriously it is treated.

Stored XSS in a chat room is described as severe. Once injected, the payload executes in the browsers of other users in the same room, and could be used to steal authentication tokens, allowing complete account takeover. Account takeover means someone else ends up in control of your account. Tribe also lets users invite others to specific rooms, so a room that has been exploited can be shared to increase the number of potential victims.

Impersonation lets a malicious user post as other users or as the system, which could enable abusive behaviour affecting users.

On the leaderboard, a malicious user can overwrite the entire leaderboard with username strings of their choosing, which could be used to deface the website. Deface means to change a public page so it shows content the owners did not intend.

Fix

The developer added client-side and server-side input validation to mitigate the XSS. Server-side validation is the important half: the check happens on the server, where the attacker cannot edit it. The report includes the sanitiser:

JavaScript
function sanitize(string) {
  const map = {
      '&': '&amp;',
      '<': '&lt;',
      '>': '&gt;',
      '"': '&quot;',
      "'": '&#x27;',
      "/": '&#x2F;',
  };
  const reg = /[&<>"'/]/ig;
  return string.replace(reg, (match)=>(map[match]));
}

Line by line, in plain words:

  • function sanitize(string) { starts a function called sanitize that takes one piece of text, string, and returns a cleaned version.
  • const map = { ... }; is a lookup table. Each dangerous character on the left is paired with a safe replacement on the right. & becomes &amp;, < becomes &lt;, > becomes &gt;, the double quote becomes &quot;, the single quote becomes &#x27;, and the forward slash becomes &#x2F;. These replacements are called HTML entities: the browser displays them as the original character but does not treat them as markup.
  • const reg = /[&<>"'/]/ig; is a pattern that matches any one of those six characters. The i means ignore upper and lower case, and the g means find every occurrence, not just the first.
  • return string.replace(reg, (match)=>(map[match])); walks through the text, and for each character the pattern matches, swaps in the safe replacement from the table. The result is text that can be displayed without the browser running anything.

The idea in one sentence: turn every character that could start markup into a harmless lookalike before the text is stored or shown.

From the original on web.archive.org

For impersonation, the developer had already addressed the issue in a patch that was not yet released when the vulnerability was found. On 3 June the patch was merged into the development site at dev.monkeytype.com (issue 1503).

For the leaderboard, the stated plan was to move the endpoint to a token-based auth system, then migrate the other cloud functions.

Separately, the researcher and developer added a disclosure policy following the security.txt standard at /.well-known/security.txt, plus a security policy page on the main site, in pull request 1505. security.txt is a small text file placed at a fixed address on a website so researchers can find out how to report problems. The security.txt content is:

Text
Contact: mailto:[redacted]
Contact: message @Miodec on discord.gg/monkeytype
Expires: 2022-06-03T21:00:00.000Z
Preferred-Languages: en
Canonical: https://monkeytype.com/.well-known/security.txt
Policy: https://monkeytype.com/security-policy

Line by line, in plain words:

  • Contact: mailto:[redacted] gives an email address for reports. The address is redacted here because it belongs to a private person.
  • Contact: message @Miodec on discord.gg/monkeytype gives a second way to make contact, through the project's Discord server.
  • Expires: 2022-06-03T21:00:00.000Z says when this file should be considered out of date, so researchers know to check for a newer one.
  • Preferred-Languages: en says English is the preferred language for reports.
  • Canonical: https://monkeytype.com/.well-known/security.txt says where the official copy of this file lives.
  • Policy: https://monkeytype.com/security-policy points to the fuller policy page.
From the original on web.archive.org

The policy tells researchers that new vulnerabilities can be disclosed to the developer by email or private Discord chat.

Variants to test

These are the same ideas applied elsewhere, written as things a beginner could try on a site they are allowed to test. In each case, a "positive result" means the site did the wrong thing.

  • Socket.io chat frames on other applications. Capture a chat frame, then edit the text field with a harmless marker such as <svg/onload=alert(1)> and the sender name field separately. A positive result is the marker executing in another user's browser, or the message rendering under the edited name.
  • Client-supplied identity fields. Change the from.id and from.name values to another user's and re-send. A positive result is the message appearing as that user, or as a system message when isSystem is set.
  • Client-supplied role flags. Set isLeader or equivalent privilege flags in the frame. A positive result is the UI granting the sender privileges it should not have.
  • Score submission endpoints. Replay a legitimate result submission with altered wpm, rawWpm or uid values. A positive result is the altered entry appearing on a public leaderboard.
  • Cross-user object references. Submit a result carrying another account's uid and name. A positive result is the entry being attributed to that account.
  • Server-side payload filtering. Where the report notes the server rejects XSS payloads on one endpoint, try the same payloads on other endpoints and in other fields to see whether the filtering is applied consistently.

Bug bounty

A bug bounty is a scheme where a company or project pays people for reporting security problems. The leaderboard issue was the researcher's first submission on huntr.dev, a platform that pays for triaged vulnerabilities in open-source software that does not already run a programme with the large platforms. Authentication is through GitHub, meaning you log in with your existing GitHub account. The researcher opened an issue, waited for the developer to respond with a patch, and after the fix was awarded a 40 USD bounty.

From the original on web.archive.org

Glossary

  • API: the set of addresses and rules a website offers so that programs, rather than people clicking, can talk to it.
  • Account takeover: a situation where an attacker gains control of someone else's account.
  • Authentication: the check of who you are, usually by password or token.
  • Authorisation: the check of whether you are allowed to do a particular thing.
  • Bearer token: a string that proves identity by possession; whoever holds it is treated as its owner.
  • Bug bounty: a scheme that pays people for reporting security problems.
  • BurpSuite: a tool that sits between a browser and a server so requests can be inspected and edited.
  • Client-side validation: an input check that runs in the visitor's own browser, which the visitor can bypass.
  • Cloud function: a small piece of code that runs on a provider's computers only when called.
  • Cross-site scripting (XSS): a flaw where text supplied by one person is treated as code by another person's browser.
  • Deface: to change a public page so it shows content the owners did not intend.
  • Endpoint: one specific address offered by an API, such as /checkLeaderboards.
  • Frame (socket.io): one small packet of text sent over a live connection, with a numeric prefix saying what kind of packet it is.
  • HTML entity: a coded form of a character, such as &lt; for <, that displays as the character but is not treated as markup.
  • HTTP/2: a version of the protocol browsers and servers use to exchange requests and responses.
  • Impact: the harm a problem could actually cause.
  • Impersonation: making a message or action appear to come from someone else.
  • JSON: a common text format for structured data, built from names and values.
  • Leaderboard: a public table ranking users by score.
  • POST: the kind of request used to send data to a server, as opposed to fetching a page.
  • Proxy: a program that sits between your browser and a server so traffic can be viewed and changed.
  • Root cause: the underlying mistake that makes a problem possible.
  • security.txt: a small text file at a fixed address on a website that tells researchers how to report problems.
  • Server-side validation: an input check that runs on the server, where the visitor cannot edit it.
  • Socket.io: a library that keeps a live connection open between browser and server so messages can arrive at any time.
  • Stored XSS: cross-site scripting where the bad text is saved on the server and shown to everyone who views it later.
  • Token: a short string that proves who you are after logging in, so you do not resend your password each time.
  • Triage: the step where a report is reviewed and accepted as a real issue.
  • Tribe: Monkeytype's feature for joining rooms, chatting and competing in typing challenges together.
  • wpm: words per minute, the speed measure used by the typing test.

More by Tyle Butler

View all

1 more disclosed report, 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.