Skip to content
Race condition Disclosed report Intermediate

The endpoint /api/internal/graphql/requestAuthEmail on Khanacademy.or is vulnerable to Race Condition Attack.

The endpoint that sends confirmation emails for linking an account could be hit with many simultaneous requests, so a single email address received a large number of sign-up emails with mostly invalid links. An attacker could use this to flood a random user's inbox.

sim4n6 Follow

Originally disclosed on HackerOne

  • Triaged in 10 hours
  • Fixed in 12 days
  • Disclosed after 8 months

Summary

The endpoint /api/internal/graphql/requestAuthEmail on www.khanacademy.org is vulnerable to a Race condition attack. That may cause a random e-mail user to receive an important amount of emails to Finish signing up for Khan Academy with invalid links. The attack is because your web applications checks the state of a resource (endpoint) before using that resource, but the resource's state can change between the check and the use in a way that invalidates the results of the check. This can cause the software to perform invalid actions when the resource is in an unexpected state.

Steps to reproduce:

  1. Connect to an account on www.khanacademy.org.
  2. Go to your ** Profile name > Settings > Account tab > Linked accounts > Connect another email.**
  3. Confirm your identity by providing your password.

█████

  1. Write out a valid email, and then intercept the request using Burp Suite at least community edition when you click on Send confirmation email. Downgrade the HTTP communication protocol to HTTP 1.1 and add the following header to the request : X-Request: %s (for the Turbo intruder extension).
  2. Send the intercepted request to Turbo intruder burp suite extension, and use the following python code to perform the attack :
def queueRequests(target, wordlists):
    engine = RequestEngine(endpoint=target.endpoint,
                           concurrentConnections=30,
                           requestsPerConnection=100,
                           pipeline=False
                           )

    # the 'gate' argument blocks the final byte of each request until openGate is invoked
    for i in range(30):
        engine.queue(target.req, target.baseInput, gate='race1')

    # wait until every 'race1' tagged request is ready
    # then send the final byte of each request
    # (this method is non-blocking, just like queue)
    engine.openGate('race1')

    engine.complete(timeout=60)


def handleResponse(req, interesting):
    table.add(req)
  1. Start the attack, the results are a lot of 200 OK as can be shown in the following screenshot:
2.png
2.png From the original on HackerOne

As you can, I've send only 30 requests in a small time frame.
7. The results is definitely an unwanted behavior. Where a random user, in our case ███ receives 30 emails inviting him to finish signing up for Khan-academy.

3.png
3.png From the original on HackerOne
  1. The invitation link within those e-mails are most invalid and produce the following error.
4.png
4.png From the original on HackerOne
  1. This behavior is not expected by your system since if you try to add an already added email your get the following warning.

███████

Impact

  • The endpoint /api/internal/graphql/requestAuthEmail on www.khanacademy.org is vulnerable to a Race condition attack. That may cause a bombing e-mail a random user with an important amount of emails (in our PoC we had only 30 but it could be much more). The emails sent are Finish signing up for Khan Academy with mostly invalid links.

The original report as published on HackerOne, by sim4n6. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 5 min read.

Context

Khan Academy's web application at www.khanacademy.org lets a signed-in user attach additional email addresses to their account. The flow lives under Profile name > Settings > Account tab > Linked accounts > Connect another email. After the user re-confirms their identity with their password, the application sends a confirmation email so the new address can be verified and the sign-up or linking process finished.

The request that triggers that email is a GraphQL call to the endpoint /api/internal/graphql/requestAuthEmail. The researcher found that this endpoint is vulnerable to a race condition: the application checks the state of a resource before using it, but the state can change between the check and the use, so the check's result no longer holds when the action is performed. In practice this lets an attacker cause a large number of confirmation emails to be sent to an address.

Setup

  • A normal account on www.khanacademy.org, signed in.
  • The account settings page, where a second email address can be added.
  • The account password, needed to confirm identity before the email request is made.
  • Burp Suite, at least the Community edition, to intercept the request.
  • The Turbo Intruder extension for Burp Suite, used to fire the requests concurrently.
  • The HTTP communication protocol downgraded to HTTP 1.1 for the attack request.

Finding it

The researcher observed that the endpoint which sends the confirmation email does not behave correctly when many identical requests arrive at almost the same moment. The application checks the state of the resource (the endpoint) before using it, but that state can change between the check and the use, invalidating the result of the check. When the resource is in an unexpected state, the software performs invalid actions. Here the invalid action is sending a burst of confirmation emails, each inviting the recipient to finish signing up for Khan Academy, with links that are mostly invalid.

The behaviour is clearly unintended because the application normally refuses to add an email address that is already present, showing a warning instead. The race bypasses that expectation by hitting the endpoint many times before any single request has completed.

Exploitation

Step 1: sign in and open the linked accounts settings

Connect to an account on www.khanacademy.org, then go to Profile name > Settings > Account tab > Linked accounts > Connect another email.

Step 2: confirm identity

Confirm your identity by providing your password. This is the normal gate in front of the email request.

Step 3: enter an address and intercept the request

Write out a valid email address, then intercept the request with Burp Suite (at least Community edition) when you click Send confirmation email. Downgrade the HTTP communication protocol to HTTP 1.1 and add the following header to the request, which the Turbo Intruder extension uses:

HTTP
X-Request: %s

Step 4: send the request to Turbo Intruder and run the race

Send the intercepted request to the Turbo Intruder extension and use the following Python code to perform the attack:

Python
def queueRequests(target, wordlists):
    engine = RequestEngine(endpoint=target.endpoint,
                           concurrentConnections=30,
                           requestsPerConnection=100,
                           pipeline=False
                           )

    # the 'gate' argument blocks the final byte of each request until openGate is invoked
    for i in range(30):
        engine.queue(target.req, target.baseInput, gate='race1')

    # wait until every 'race1' tagged request is ready
    # then send the final byte of each request
    # (this method is non-blocking, just like queue)
    engine.openGate('race1')

    engine.complete(timeout=60)

def handleResponse(req, interesting):
    table.add(req)

Each of the 30 requests is queued with the gate label race1, which holds back the final byte of every request.

Step 5: read the responses

Start the attack. The results are a lot of 200 OK responses, as shown in the following screenshot:

2.png
2.png From the original on HackerOne

Only 30 requests were sent, within a small time frame.

Step 6: observe the email burst

The result is unwanted behaviour: a random user, in this case [redacted], receives 30 emails inviting them to finish signing up for Khan Academy.

3.png
3.png From the original on HackerOne

Step 7: check the links

The invitation links inside those emails are mostly invalid and produce the following error:

4.png
4.png From the original on HackerOne

Step 8: compare with normal behaviour

This is not expected by the system, because if you try to add an email address that has already been added, you get a warning instead.

Root cause

The endpoint checks the state of the resource before using it, but the state can change between the check and the use, which invalidates the result of the check. The report describes the flaw generically: the state is checked before use and can change in between, invalidating the check. The report notes that adding an already added email address normally produces a warning, which this behaviour bypasses. The report does not describe any locking, idempotency key or rate limit on the endpoint.

Impact

The endpoint /api/internal/graphql/requestAuthEmail on www.khanacademy.org is vulnerable to a race condition attack. That may cause email bombing of a random user with an important amount of emails; in the proof of concept there were only 30, but it could be much more. The emails sent are Finish signing up for Khan Academy with mostly invalid links.

Fix

The report does not state what was changed. Based on the root cause, the endpoint should make the check and the send atomic for a given address, for example by serialising requests per address or by using an idempotency key so that only one confirmation email is issued per pending request, and it should rate-limit repeated requests to the same address.

Variants to test

  1. Other email-triggering endpoints. Apply the same gated Turbo Intruder burst to password reset, email verification, invitation and magic-link endpoints. A positive result is many 200 OK responses and multiple emails arriving for a single address.
  2. Other state-changing GraphQL mutations. Target mutations that create, redeem or link resources. A positive result is duplicate resources or duplicate side effects that the sequential flow prevents.
  3. Different concurrency levels. Vary concurrentConnections and the number of queued requests to find the window where duplicates start appearing. A positive result is a count of side effects that scales with the number of concurrent requests.
  4. HTTP/2 versus HTTP/1.1. Repeat the attack on both protocol versions, since the report downgrades to HTTP 1.1. A positive result is duplicates on either version, showing the issue is not tied to the downgrade.
  5. Coupon, credit and quota operations. Race the redemption of single-use codes or balance deductions. A positive result is a code redeemed more than once or a balance going negative.

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

What happened, in plain words

Khan Academy is a learning website. When you are signed in, you can attach extra email addresses to your account, for example a work address next to your personal one. To do that you go to your account settings, confirm it is really you by typing your password, and then the site sends a confirmation email to the new address. You click the link in that email and the address is linked.

The researcher found that the part of the site that sends that confirmation email can be tricked into sending it many times at once. In the researcher's test, firing the request 30 times at once produced 30 emails to the same address. The links inside most of those emails do not work, so the person just gets a pile of useless messages. This kind of flood is often called email bombing.

The reason is a race condition. A race condition is when a program checks something, then acts on it, and something else changes the situation in between. A everyday comparison: you check that a fitting room is free, walk towards it, and by the time you open the door someone else is inside. You checked correctly, but the world changed before you acted. Here the site checks the state of the resource before using it, and that state can change between the check and the use.

A few words you will meet in this article:

  • An endpoint is a specific address on a website that does one job, like a counter in a shop. /api/internal/graphql/requestAuthEmail is the counter that sends the confirmation email.
  • GraphQL is a way for a website's own pages to ask its server for data or actions. You do not need to understand it to follow this; just know that the request in question is a GraphQL call.
  • Burp Suite is a tool that sits between your browser and the website so you can look at and change the requests your browser sends. Think of it as a transparent envelope you can open, edit and reseal.
  • Turbo Intruder is an add-on for Burp Suite that can send many copies of a request at almost exactly the same moment. That timing is the whole point of this attack.
  • HTTP is the language browsers and servers speak. Version 1.1 is an older version of that language; the researcher downgraded to it for the attack request.

Context

On www.khanacademy.org, a signed-in user can attach additional email addresses to their account. The flow lives under Profile name > Settings > Account tab > Linked accounts > Connect another email. After the user re-confirms their identity with their password, the application sends a confirmation email so the new address can be verified and the sign-up or linking process finished.

The request that triggers that email is a GraphQL call to the endpoint /api/internal/graphql/requestAuthEmail. The researcher found that this endpoint is vulnerable to a race condition: the application checks the state of a resource before using it, but the state can change between the check and the use, so the check's result no longer holds when the action is performed. In practice this lets an attacker cause a large number of confirmation emails to be sent to an address.

Setup

Before starting, the researcher needed the following:

  • A normal account on www.khanacademy.org, signed in.
  • The account settings page, where a second email address can be added.
  • The account password, needed to confirm identity before the email request is made.
  • Burp Suite, at least the Community edition, to intercept the request. Intercepting means catching the request on its way out so you can read and modify it.
  • The Turbo Intruder extension for Burp Suite, used to fire the requests concurrently. Concurrently means at the same time rather than one after another.
  • The HTTP communication protocol downgraded to HTTP 1.1 for the attack request.

Finding it

The researcher observed that the endpoint which sends the confirmation email does not behave correctly when many identical requests arrive at almost the same moment. The application checks the state of the resource (the endpoint) before using it, but that state can change between the check and the use, invalidating the result of the check. When the resource is in an unexpected state, the software performs invalid actions. Here the invalid action is sending a burst of confirmation emails, each inviting the recipient to finish signing up for Khan Academy, with links that are mostly invalid.

The behaviour is clearly unintended because the application normally refuses to add an email address that is already present, showing a warning instead. The race bypasses that expectation by hitting the endpoint many times before any single request has completed.

Exploitation

Step 1: sign in and open the linked accounts settings

Connect to an account on www.khanacademy.org, then go to Profile name > Settings > Account tab > Linked accounts > Connect another email.

This is just the normal path a user takes. The researcher starts here so the request that follows is the genuine one the site produces, not a hand-built guess.

Step 2: confirm identity

Confirm your identity by providing your password. This is the normal gate in front of the email request.

The site asks for the password so that someone who borrows an unlocked computer cannot quietly attach their own address. The researcher passes this gate honestly, because the weakness is not in the password check but in what happens after it.

Step 3: enter an address and intercept the request

Write out a valid email address, then intercept the request with Burp Suite (at least Community edition) when you click Send confirmation email. Downgrade the HTTP communication protocol to HTTP 1.1 and add the following header to the request, which the Turbo Intruder extension uses:

HTTP
X-Request: %s

A header is a small labelled line that travels with a request, like the address and handling notes on an envelope. This particular header is not something the website needs; it is a marker for Turbo Intruder. The report says this header is added for the Turbo Intruder extension.

Step 4: send the request to Turbo Intruder and run the race

Send the intercepted request to the Turbo Intruder extension and use the following Python code to perform the attack:

Python
def queueRequests(target, wordlists):
    engine = RequestEngine(endpoint=target.endpoint,
                           concurrentConnections=30,
                           requestsPerConnection=100,
                           pipeline=False
                           )

    # the 'gate' argument blocks the final byte of each request until openGate is invoked
    for i in range(30):
        engine.queue(target.req, target.baseInput, gate='race1')

    # wait until every 'race1' tagged request is ready
    # then send the final byte of each request
    # (this method is non-blocking, just like queue)
    engine.openGate('race1')

    engine.complete(timeout=60)

def handleResponse(req, interesting):
    table.add(req)

Line by line, in plain words:

  1. def queueRequests(target, wordlists): starts a function that prepares and sends the requests. target is the request you captured in Burp Suite.
  2. engine = RequestEngine(...) creates the sending engine, the part that actually pushes requests to the server.
  3. endpoint=target.endpoint tells the engine which server address to talk to, taken from your captured request.
  4. concurrentConnections=30 says to open 30 connections at the same time. More connections means more requests can arrive together.
  5. The comment explains the trick: the gate argument holds back the final byte of each request until openGate is called.
  6. for i in range(30): repeats the next line 30 times.
  7. engine.queue(target.req, target.baseInput, gate='race1') puts one copy of the request into the queue, tagged with the gate name race1. All 30 copies wait at the gate.
  8. engine.openGate('race1') opens the gate. The final byte of all 30 requests is released at once, so they reach the server in the smallest possible time window. This is the moment the race is run.
  9. def handleResponse(req, interesting): defines what to do with each reply that comes back.

Why hold the last byte? Because a server cannot act on a request it has not fully received.

Step 5: read the responses

Start the attack. The results are a lot of 200 OK responses, as shown in the following screenshot:

2.png
2.png From the original on HackerOne

200 OK is the standard HTTP status code meaning the server accepted and handled the request. The report shows a lot of 200 OK responses. Only 30 requests were sent, within a small time frame.

Step 6: observe the email burst

The result is unwanted behaviour: a random user, in this case [redacted], receives 30 emails inviting them to finish signing up for Khan Academy.

3.png
3.png From the original on HackerOne

Step 7: check the links

The invitation links inside those emails are mostly invalid and produce the following error:

4.png
4.png From the original on HackerOne

The report says the invitation links in those emails are mostly invalid and produce an error.

Step 8: compare with normal behaviour

This is not expected by the system, because if you try to add an email address that has already been added, you get a warning instead.

That warning is the site's normal defence against duplicates.

Root cause

The endpoint checks the state of the resource before using it, but the state can change between the check and the use, which invalidates the result of the check. The report describes the flaw generically: the state is checked before use and can change in between, invalidating the check. The report notes that adding an already added email address normally produces a warning, which this behaviour bypasses. The report does not describe any locking, idempotency key or rate limit on the endpoint.

In everyday terms: a bouncer checks a guest list at the door. If thirty people crowd the door at once and the bouncer checks all thirty before ticking any name off, all thirty get in. The list was correct; the timing was wrong.

Impact

The endpoint /api/internal/graphql/requestAuthEmail on www.khanacademy.org is vulnerable to a race condition attack. That may cause email bombing of a random user with an important amount of emails; in the proof of concept there were only 30, but it could be much more. The emails sent are Finish signing up for Khan Academy with mostly invalid links.

A business logic error means the code does what it was written to do, but the rule it enforces is wrong or incomplete.

Fix

The report does not state what was changed. Based on the root cause, the endpoint should make the check and the send atomic for a given address, for example by serialising requests per address or by using an idempotency key so that only one confirmation email is issued per pending request, and it should rate-limit repeated requests to the same address.

Two of those ideas in plain words. Serialising means letting only one request per address be handled at a time, so the second one sees what the first one did. An idempotency key is a unique label attached to a request, so the server can recognise a repeat of the same action and ignore it, the way a ticket inspector punches your ticket only once even if you show it twice. Rate limiting means refusing to serve too many requests from the same place in a short period.

Variants to test

These are other places where the same idea could be tried. Each one follows the same pattern: find an action that should happen once, then try to make it happen many times at the same instant.

  1. Other email-triggering endpoints. Apply the same gated Turbo Intruder burst to password reset, email verification, invitation and magic-link endpoints. A positive result is many 200 OK responses and multiple emails arriving for a single address.
  2. Other state-changing GraphQL mutations. Target mutations that create, redeem or link resources. A mutation is simply a GraphQL request that changes something rather than just reading it. A positive result is duplicate resources or duplicate side effects that the sequential flow prevents.
  3. Different concurrency levels. Vary concurrentConnections and the number of queued requests to find the window where duplicates start appearing. A positive result is a count of side effects that scales with the number of concurrent requests.
  4. HTTP/2 versus HTTP/1.1. Repeat the attack on both protocol versions, since the report downgrades to HTTP 1.1. A positive result is duplicates on either version, showing the issue is not tied to the downgrade.
  5. Coupon, credit and quota operations. Race the redemption of single-use codes or balance deductions. A positive result is a code redeemed more than once or a balance going negative.

Glossary

  • API: a defined set of addresses a website exposes so its own pages, or other software, can ask it to do things.
  • Atomic: done as a single indivisible step, so nothing else can slip in between the check and the action.
  • Burp Suite: a tool that sits between your browser and a website so you can inspect and modify requests.
  • Business logic error: a flaw in the rules a program enforces, rather than in its code crashing or leaking data.
  • Concurrent: happening at the same time rather than one after another.
  • Concurrent connections: several network connections open at once, so requests can travel in parallel.
  • Email bombing: flooding a person's inbox with a large number of messages.
  • Endpoint: a specific address on a server that performs one particular job.
  • Gate (in Turbo Intruder): a hold that keeps requests from being completed until released, so they can be sent together.
  • GraphQL: a way for a website's pages to ask its server for data or actions using structured requests.
  • Header: a labelled line sent with an HTTP request or response carrying extra information.
  • HTTP: the language browsers and servers use to exchange requests and responses.
  • HTTP 1.1: an older version of that language, used here for finer control over connections.
  • Idempotency key: a unique label on a request that lets the server recognise and ignore a repeat of the same action.
  • Intercept: to catch a request on its way out so it can be read or changed before it reaches the server.
  • Mutation (GraphQL): a request that changes something on the server rather than only reading it.
  • Pipelining: sending several requests down one connection without waiting for each reply.
  • Race condition: a flaw where a program checks something and then acts, but the situation changes in between, so the check no longer holds.
  • Rate limiting: refusing to serve too many requests from the same source in a short period.
  • Resource: the thing a program checks or acts on, such as an email address or an account setting.
  • Serialising: handling requests one at a time so each sees the effect of the previous one.
  • Status code: a number in an HTTP reply saying how the server handled the request; 200 OK means it was accepted and processed.
  • Turbo Intruder: a Burp Suite extension that sends many copies of a request at almost exactly the same moment.
  • Warning (in this report): the message the site shows when you try to add an email address that is already linked.

More by sim4n6

View all

5 more disclosed reports, best first.

More from Khan Academy

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Race conditions

The lesson behind this report.

Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.