Finding a security bug in Discord and what it taught me
The OAuth client credentials grant issued an access token for a Discord Team, which is a managed user object, allowing the token to act as that user. The attacker could use the token to add the team user to a guild, causing inconsistent API behaviour.
Published on medium.com
On the 10th of November, I was looking through some of Discords documentation for OAuth because of a project I’m working on when something interesting caught my eye, the “Client Credentials Grant” system for quickly retrieving an OAuth token for testing purposes. Now I had never used this system before, but the gist…
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
Discord's OAuth documentation describes a Client Credentials Grant, a flow intended for quickly retrieving an OAuth token for testing purposes. Instead of sending a user through the full OAuth flow, you make a request to an API endpoint with a client id and client secret and receive the OAuth token for the application owner.
The researcher was reading that documentation on 10 November for an unrelated project when the flow caught his eye. He had never used it before. The question he asked was what happens when the application is not owned by a single user but by a Team. On Discord, teams are groups of users that own and together manage one or more applications.
Setup
The write-up does not describe any special tooling, accounts or versions. The precondition is simply an application owned by a team, plus its client id and client secret, which are the inputs the client credentials grant expects.
Finding it
The thought was simple: the client credentials grant returns the token of the application owner, and a team is not a single user. If the backend treated the team as the owner anyway, the token would be issued for something that is not an ordinary account. He decided to see what happens when a client_credentials request is made for a team project.
Exploitation
Step 1: request a token with client credentials for a team-owned application
The researcher made a client_credentials request for a team project. The write-up does not reproduce the raw request, only the outcome: an access_token was returned.
Step 2: confirm the token works
Using that token against the API returned a user object.

The image shows the user object returned when making a request to the API with the team's access_token; the identifiers in it are redacted. Two things follow from this response. The token is accepted, so requests can be made on behalf of the team, and a team appears to be represented as a managed User object. That second point is the interesting one: the credential is not scoped to an application context but to something the API treats as a user.
Step 3: add the managed user to a guild
Having tested a few different endpoints, the researcher tried the Add Guild Member endpoint to see whether the managed user object could be joined to a server or guild. The request went through successfully. The write-up does not reproduce the request body or the response.
He did not believe the response at first, so he checked in the Discord client.

The image shows the team user object present in the server, offline. The managed user had become a member of a guild.
Step 4: observe the inconsistent state
The user object caused all kinds of weird issues in the client.

The console shows fetchProfile error: 10013 - Unknown User. Parts of the API accepted that the user existed, while other parts did not agree.

In the team user's profile view inside the Discord client, the user did exist. Parts of the API thought this user existed, other parts did not agree with them.
Root cause
The report does not include a post-mortem or any statement from Discord about the underlying code, so the following is inferred from the observed behaviour. The client credentials grant issued a token for the team, and requests made with it returned a user object. The Add Guild Member endpoint accepted it. Other services, such as the profile fetcher, could not resolve it and returned 10013 - Unknown User.
Impact
The researcher demonstrated that a token obtained through the client credentials grant for a team-owned application can act as the team's managed user object, including joining a guild. The report does not describe what else the token could reach, whether the joined member could read messages or interact in the guild, or what permissions it held. It also does not state a severity, a CVSS score or a bounty amount. The token returned for the team could be used to add the team user object to a guild, and parts of the API then disagreed about whether that user existed.
Fix
The researcher reported the issue to Discord's Bug Bounty Program, and a few days later a Discord employee replied and quickly addressed the issue. He received the OK to disclose the previous evening.
Variants to test
- Other shared-ownership models. Look for platforms where an application, bot or service account can be owned by an organisation, team or group rather than a person, and try the client credentials or equivalent machine-to-machine flow against it. A positive result is a token that resolves to an object the rest of the product treats as a user.
- Cross-service consistency checks. After obtaining such a token, call endpoints from different services (profile, membership, messaging) with it. A positive result is one service accepting the object while another returns an unknown-entity error, as with
10013here. - Membership endpoints. Try adding the machine identity to a guild, workspace or group through the membership API. A positive result is a successful add followed by the identity appearing in the client but failing to load elsewhere.
- Permission probing. If the managed identity can join, enumerate what it can then do: read channels, send messages, list members. A positive result is any capability beyond what a testing token should have.
On 10 November the researcher was reading the OAuth documentation for a project he was working on, and he notes that this kind of random thought is often the most effective route to a bug, because you do not spend time chasing issues that may not exist.
What happened, in plain words
Discord is a chat platform where people gather in servers (also called guilds) to talk in text and voice channels. Applications can be built on top of Discord, and those applications need permission to act. That permission comes in the form of a token, a long string of characters that works like a temporary key: whoever holds it can make the platform do things on behalf of the account it was issued for.
Discord's developer documentation describes a shortcut for getting such a token, called the Client Credentials Grant. You send your application's id and its secret (think of the id as a username and the secret as a password, both belonging to the application rather than to a person) and you get back a token for the application's owner, without any human having to click through a login screen.
The researcher was reading that documentation on 10 November for a project he was working on when the shortcut caught his eye. He had never used it before. He asked himself a simple question: what happens if the application is not owned by one person but by a Team? On Discord, a team is a group of users who own and manage one or more applications together. If the shortcut is documented as returning the token of the owner, and the owner is a group rather than a person, what does the platform hand back?
He tried it. The platform returned a token. Using that token, he could make requests as the team, and the team turned out to be represented internally as a kind of user account. He then used the token to add that team user to a server, and the request succeeded. The result was a member that existed for some parts of Discord and did not exist for others, which produced strange errors in the client. He reported it to Discord's bug bounty programme, an employee replied a few days later and fixed the issue quickly, and the researcher was given permission to write about it publicly.
The background you need first
A few ideas come up again and again below, so here they are from zero.
API. An API is the set of addresses a service exposes so that programs, rather than people clicking buttons, can ask it to do things. If a website is a restaurant's dining room, the API is the serving hatch where orders are handed in and dishes come back. Discord's API is what the Discord app itself uses behind the scenes, and what developers use to build bots and integrations.
Endpoint. An endpoint is one specific address in that API, each one tied to one action: one endpoint for fetching a profile, another for adding someone to a server. It is like one counter in the serving hatch, labelled with what it does.
Request and response. A request is the message a program sends to an endpoint, and a response is what comes back. A response usually contains data in a structured text format called JSON, which looks like labelled boxes nested inside each other.
OAuth. OAuth is a standard way for one program to be granted permission to act on a service without ever seeing the user's password. Normally the user is sent to a login page, approves the request, and the program receives a token. That is the full OAuth flow.
Token. A token is that permission slip: a long string that the program attaches to every request to prove it is allowed. It is like a coat-check ticket. You do not need to prove who you are each time; you just show the ticket.
Client id and client secret. These are the credentials of an application itself, not of a person. The id is public and identifies the application; the secret is private and proves the application is genuine. Together they are like a shop's name badge and its safe combination.
Client Credentials Grant. This is a shortcut in OAuth meant for testing. Instead of a person logging in, the application sends its id and secret and receives a token for the application's owner. It is the machine equivalent of a staff key kept behind the desk so the owner does not have to unlock the door in person every time.
Team. On Discord, a team is a group of users who jointly own and manage applications. The documentation describes teams as groups of users that own application(s) that they together manage.
Guild. A guild is Discord's internal name for a server, the place where members and channels live.
User object. When the API describes an account, it sends back a user object: a JSON bundle of fields such as an id, a username and similar details. It is the API's description of an account, not the account itself.
Bug bounty programme. A scheme where a company invites outside researchers to report security problems and rewards them for doing so responsibly, instead of the researcher publishing the problem or exploiting it.
The idea: a shortcut built for one owner, applied to many
The idea came from a random thought about how the system is described, not from trying random things. The Client Credentials Grant is documented as returning the token of the application owner. A team is not a single user, so he tried a client_credentials request for a team project. He decided to see what happens when a client_credentials request is made for a team project.
In everyday terms: a form asks for "the owner's name" and assumes there is exactly one. You hand it the name of a committee. If the clerk does not check, the committee gets a membership card meant for an individual.
Setup
The write-up does not describe any special tooling, accounts or versions. The precondition is simply an application owned by a team, plus its client id and client secret, which are the inputs the client credentials grant expects.
Finding it
This section is the reasoning step, and it is worth slowing down on because it is where the bug was actually found. Nothing was scanned or brute-forced. The researcher read the documentation, saw the Client Credentials Grant, and wondered what happens when the application is owned by a team.
Exploitation
Step 1: request a token with client credentials for a team-owned application
The researcher made a client_credentials request for a team project. The write-up does not reproduce the raw request, only the outcome: an access_token was returned.
Why this step: the whole question was whether the shortcut would issue a token at all when the owner is a team rather than a person. Getting a token back is the first half of the answer.
Step 2: confirm the token works
Using that token against the API returned a user object.

The image shows the user object returned when making a request to the API with the team's access_token; the identifiers in it are redacted.
Why this step: a token that is issued but rejected is harmless. The researcher needed to know whether the platform would actually accept it. It did.
Two things follow from this response. First, the token is accepted, so requests can be made on behalf of the team. Second, a team appears to be represented as a managed User object. That second point is the interesting one: the credential is not scoped to an application context but to something the API treats as a user. In plain words, the platform did not hand back a special "team key"; it handed back a key that opens doors labelled "user account".
Step 3: add the managed user to a guild
Having tested a few different endpoints, the researcher tried the Add Guild Member endpoint to see whether the managed user object could be joined to a server or guild. The request went through successfully. The write-up does not reproduce the request body or the response.
Why this step: a user object that merely exists is a curiosity. A user object that can be placed inside a server is a real identity with a place in the product, and that is where the mismatch starts to matter.
He did not believe the response at first, so he checked in the Discord client.

The image shows the team user object present in the server, offline. The managed user had become a member of a guild.
Checking in the client matters because the API response alone could have been misleading. The client is the ordinary product, the thing a normal person sees, so seeing the team user listed there confirmed that the change was real and not just a quirk of one response.
Step 4: observe the inconsistent state
The user object caused all kinds of weird issues in the client.

The console shows fetchProfile error: 10013 - Unknown User. Parts of the API accepted that the user existed, while other parts did not agree.
A console is the panel in a browser or app that shows technical messages, including errors. Here it reports that one part of Discord tried to load the profile of this member and was told, in effect, that no such user exists. The error code 10013 is the platform's way of saying "unknown user".

In the team user's profile view inside the Discord client, the user did exist. Parts of the API thought this user existed, other parts did not agree with them.
This is the heart of the finding. One service says the member is there; another says there is no such account. The platform is holding two contradictory beliefs about the same object at the same time.
Root cause
The report does not include a post-mortem or any statement from Discord about the underlying code, so the following is inferred from the observed behaviour. The client credentials grant issued a token for the team, and requests made with it returned a user object. The Add Guild Member endpoint accepted it. Other services, such as the profile fetcher, could not resolve it and returned 10013 - Unknown User.
A comparison: a building's reception desk issues a visitor badge to "the finance department" because the form only asks for a name. Security lets the badge through the main door because it looks valid. But the staff directory has no entry for a department as a person, so the internal phone book cannot find it, and the badge holder is stuck in a corridor that half the building insists does not exist.
Impact
The researcher demonstrated that a token obtained through the client credentials grant for a team-owned application can act as the team's managed user object, including joining a guild. The report does not describe what else the token could reach, whether the joined member could read messages or interact in the guild, or what permissions it held. It also does not state a severity, a CVSS score or a bounty amount. The token returned for the team could be used to add the team user object to a guild, and parts of the API then disagreed about whether that user existed.
Fix
The researcher reported the issue to Discord's Bug Bounty Program, and a few days later a Discord employee replied and quickly addressed the issue. He received the OK to disclose the previous evening.
Variants to test
These are directions for looking for similar problems elsewhere. They are written for someone learning, so each one says what a positive result would look like.
- Other shared-ownership models. Look for platforms where an application, bot or service account can be owned by an organisation, team or group rather than a person, and try the client credentials or equivalent machine-to-machine flow against it. A positive result is a token that resolves to an object the rest of the product treats as a user.
- Cross-service consistency checks. After obtaining such a token, call endpoints from different services (profile, membership, messaging) with it. A positive result is one service accepting the object while another returns an unknown-entity error, as with
10013here. - Membership endpoints. Try adding the machine identity to a guild, workspace or group through the membership API. A positive result is a successful add followed by the identity appearing in the client but failing to load elsewhere.
- Permission probing. If the managed identity can join, enumerate what it can then do: read channels, send messages, list members. A positive result is any capability beyond what a testing token should have.
A closing thought on how the bug was found
On 10 November the researcher was reading the OAuth documentation for a project he was working on, and he notes that this kind of random thought is often the most effective route to a bug, because you do not spend time chasing issues that may not exist. For a beginner, the lesson is that reading documentation carefully and asking "what if this assumption is wrong?" costs nothing and can be more productive than running tools.
Glossary
- API: the set of addresses a service exposes so that programs can ask it to do things, rather than a person clicking buttons.
- Endpoint: one specific address in an API, tied to one action, such as fetching a profile or adding a guild member.
- Request: the message a program sends to an endpoint.
- Response: what the service sends back, often data in JSON format.
- JSON: a structured text format for data, made of labelled fields nested inside each other.
- OAuth: a standard way for a program to be granted permission to act on a service without seeing the user's password.
- OAuth flow: the normal process where a user is sent to a login page, approves the request, and the program receives a token.
- Token: a long string that proves permission, attached to requests so the service knows the caller is allowed.
- access_token: the name of the token returned in this case, used to make requests on behalf of the team.
- Client id: the public identifier of an application.
- Client secret: the private value that proves an application is genuine, like a password for the application.
- Client Credentials Grant: an OAuth shortcut for testing, where an application sends its id and secret and receives a token for the application's owner without a user logging in.
- client_credentials: the name of that request type, as used in the write-up.
- Team: on Discord, a group of users who own and together manage one or more applications.
- Guild: Discord's internal name for a server, where members and channels live.
- Add Guild Member: the API endpoint used to add an account to a guild.
- User object: the JSON bundle of fields, such as an id and username, that the API returns to describe an account.
- Managed User object: the internal representation of a team that the API treats like a user account.
- Console: the panel in a browser or app that shows technical messages, including errors.
- Error code 10013: the platform's "Unknown User" error, meaning the requested account could not be found.
- Bug bounty programme: a scheme where a company invites outside researchers to report security problems and rewards them for doing so responsibly.
- Disclosure: making the details of a fixed security issue public, usually with the company's approval.
- Root cause: the underlying reason a bug exists, as opposed to its visible symptoms.
- Authorisation model: the set of rules a system uses to decide who is allowed to do what.