OTP brute-force via rate limit bypass
The password reset flow limited how many OTP guesses a client could make, but the limit was keyed on the client's IP address taken from the X-Forwarded-For header. By rotating that header value, an attacker could send unlimited OTP guesses and brute-force the six-digit code, potentially taking over accounts.
Published on bilalabdulmuqeet.medium.com
Bilal Muqeet
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
This is a write-up of a bug found on a private bug bounty program, and it was the researcher's first bug bounty write-up. The affected feature is the forget password flow. On the forget password page you supply an email address, the application sends a one time password (OTP) to that address, and you enter the OTP to create a new password.
The report does not name the target, the application or the technology stack. What it does describe is that rate limiting was in place on this feature, and that the rate limit could be bypassed in two places: on the sending of the OTP, and on the verification of the OTP. The second bypass is what turns the finding into an OTP brute-force.
A rate-limiting technique, in the report's own words, is implemented in order to restrict the number of requests being sent that seem to be abnormal in nature.
Setup
The researcher used a proxy, Burp Suite, to intercept and replay requests, and Burp Intruder to send the same request repeatedly with varying payloads. No accounts, roles or versions are described.
Finding it
The researcher did not start by attacking the OTP check. The first observation was that the prevention was set up at the forget password endpoint, that is, on the request that triggers the OTP email.
Exploitation
Step 1: capture the forget password request
After clicking the forget password button, the intercepted request in Burp Suite looks like this:
Step 2: confirm the rate limit exists
Sending the request to Intruder and repeating it almost 20 times produced responses like these:

Step 3: bypass the rate limit with X-Forwarded-For
The trick was to add an X-Forwarded-For header to the request. The report points to the HackTricks page on rate limit bypass for background:
https://book.hacktricks.xyz/pentesting-web/rate-limit-bypass
The request was looped 50 times, with the value of the X-Forwarded-For header going from [redacted] up to [redacted]:
The screenshot below shows 10 repeated requests with the indication emailSent: True. The result was that the researcher's inbox was flooded with the desired number of OTPs:

The rate limit on the forget password feature had been bypassed. The researcher reported this vulnerability separately.
Step 4: move to the OTP verification step
The second part of the scenario starts at the point where the user has to input the OTP that was sent to them:

An incorrect OTP was supplied, and that specific action was proxied:
Step 5: confirm the rate limit on OTP verification
The same action was repeated with 5 incorrect OTPs, and the server responded with:

Rate limit occurrence.
At this point the researcher connected the dots: the rate limit on the forget password feature had already been bypassed, so why not try the same technique on the OTP check? Brute forcing an OTP can open the door to a possible account takeover in an instance like this.
In the highlighted portions of the request above, the host ID of the X-Forwarded-For parameter was looped from 0 to 255, and an arbitrary amount of 6 digit numbers was supplied in the tokenVerify parameter, which is the parameter that carries the OTP.
Step 6: compare response lengths with and without the bypass
With rate limiting on the OTP in place:

Response length 545 denotes rate limit present.
After the rate limit on the OTP had been bypassed, with Payload1 containing X-Forwarded-For and Payload2 for the tokenVerify parameter:

Response length 520 denoting normal workflow.
The payload set below indicates the successful OTP brute-force attempt, with the absence of a rate limit:

The report notes a response length of 545 when the rate limit is present and 520 for the normal workflow.
Root cause
The report does not state the root cause; the behaviour is consistent with the rate limiter keying on the header value. Because the header can be set to any value by the sender, each request can be made to look like it comes from a different address, so the per-client counter never fills up. The same technique worked on both the OTP sending endpoint and the OTP verification endpoint.
Impact
Two distinct impacts are described. On the forget password endpoint, the rate limit bypass lets an attacker flood a victim's inbox with OTP emails. On the OTP verification endpoint, the bypass removed the limit on incorrect guesses, allowing a brute-force attempt against the 6 digit OTP. The report frames the consequence as a possible account takeover in an instance like this.
Fix
The change that addresses the root cause is to stop keying the rate limiter on a client-controlled header such as X-Forwarded-For, and to derive the client identity from the connection or from a header that is set and sanitised by a trusted proxy in front of the application. Rate limiting should also be applied per account or per OTP session on the verification endpoint, not only per source address, so that rotating the apparent source does not reset the guess budget.
Variants to test
- Other forwarding headers. Send the same request with
X-Forwarded-For,X-Real-IP,X-Originating-IP,X-Remote-IP,X-Client-IPandForwarded, each with a different value per request. A positive result is that the rate limit response stops appearing and the normal response length or body returns. - Header value formats. Try single addresses, comma-separated lists, and values with ports or brackets. A positive result is any format that changes the limiter's key without changing the application's behaviour.
- Per-account limits on OTP verification. Keep the source address constant but vary the account or session. A positive result is that the guess budget is not shared across accounts, or that it resets when the session changes.
- Response-length or status differences. Compare the response for a wrong OTP with the response for a correct one, including length, status code and body. A positive result is a reliable oracle that distinguishes the two, which is what makes brute force practical.
- OTP lifetime and reuse. Request an OTP, wait, and try it, and also try reusing an OTP after a successful verification. A positive result is an OTP that stays valid longer than expected or can be reused.
- Sending endpoint limits. Repeat the forget password request with rotating forwarding headers and count the emails received. A positive result is more emails than the stated limit, as in the inbox flooding described here.
What happened, in plain words
A security researcher found a way to guess a one time password (OTP) on a website's password reset page, even though the site had a protection in place that was supposed to stop exactly that kind of guessing. The protection is called rate limiting, and the researcher got around it by adding a header to each request that made every request look like it came from a different computer.
The same trick worked in two places. First, on the request that sends the OTP email, which let the researcher flood an inbox with OTP messages. Second, on the request that checks whether the OTP you typed is correct, which removed the limit on wrong guesses and made it possible to brute force the 6 digit code. Brute forcing means trying many possibilities one after another until one works. If an attacker can guess the OTP for someone else's account, they can finish the password reset and take over that account.
This was the researcher's first bug bounty write-up, and the bug was found on a private bug bounty program. A bug bounty program is a scheme where a company invites researchers to look for security problems in its systems and pays them for reporting what they find. The report does not name the target, the application or the technology it runs on.
Before going further, a few words on the pieces involved.
- A web request is the message your browser sends to a website when you click a button or load a page. It contains a method (like
GETorPOST), a URL, some headers (small labelled pieces of information such as which browser you use), and sometimes a body with data. - A proxy is a tool that sits between your browser and the website. It lets you pause a request, look at it, change it, and send it again. Burp Suite is a well known proxy used for security testing. Burp Intruder is a part of it that sends the same request many times, each time with a different value in a chosen spot, which is how you try lots of guesses quickly.
- A header is a line in a request that carries extra information.
X-Forwarded-Foris a header that proxies use to tell a website which original address a request came from, because when a proxy forwards traffic the website only sees the proxy's address otherwise. - An endpoint is a specific address on a server that does a specific job, for example the address that handles the forget password form.
- Rate limiting is a cap on how many requests a client may send in a period of time. In the report's own words, a rate-limiting technique is implemented in order to restrict the number of requests being sent that seem to be abnormal in nature. A simple everyday comparison: a shop assistant who will only serve you three questions per minute, and tells you to come back later if you ask a fourth.
- An OTP is a short code, here 6 digits, sent to your email so that typing it proves you control that email address.
The affected feature is the forget password flow. On the forget password page you supply an email address, the application sends an OTP to that address, and you enter the OTP to create a new password.
The report describes rate limiting as being in place on this feature, and shows that it could be bypassed in two places: when the OTP is sent, and when the OTP is checked. The second bypass is what turns the finding into an OTP brute force.
Setting up
The researcher used Burp Suite to intercept and replay requests, and Burp Intruder to send the same request repeatedly with varying values. No accounts, roles or software versions are described.
Finding it
The researcher did not start by attacking the OTP check. The first observation was that the protection was set up at the forget password endpoint, meaning the request that triggers the OTP email.
Exploitation
Step 1: capture the forget password request
After clicking the forget password button, the intercepted request in Burp Suite looks like this:
Capturing the request is the first step because you cannot study or replay something you have not seen. The proxy holds the request so the researcher can read every header and field the browser was about to send.
Step 2: confirm the rate limit exists
Sending the request to Intruder and repeating it almost 20 times produced responses like these:

A response is the server's reply to a request. Without this baseline you would not be able to tell later whether a change in behaviour is caused by your bypass or by something else.
Step 3: bypass the rate limit with X-Forwarded-For
The trick was to add an X-Forwarded-For header to the request. The report points to the HackTricks page on rate limit bypass for background:
https://book.hacktricks.xyz/pentesting-web/rate-limit-bypass
This is a link to a public collection of notes on how rate limits can be bypassed. The researcher used it as a reference for the technique.
The request was looped 50 times, with the value of the X-Forwarded-For header going from [redacted] up to [redacted]:
In plain words: the same request was sent 50 times, and each time the header claimed a different source address, starting at [redacted] and ending at [redacted].
The screenshot below shows 10 repeated requests with the indication emailSent: True. The result was that the researcher's inbox was flooded with the desired number of OTPs:

The screenshot shows 10 repeated requests with the indication emailSent: True. Seeing it on request after request means the server kept accepting them instead of refusing once the limit was reached. The rate limit on the forget password feature had been bypassed, and the researcher reported this vulnerability separately.
Step 4: move to the OTP verification step
The second part of the scenario starts at the point where the user has to input the OTP that was sent to them:

An incorrect OTP was supplied, and that specific action was proxied:
Supplying a wrong code on purpose is how you see what a failed attempt looks like. You need that picture before you can tell whether the server is still treating your later attempts as failures or has started blocking them.
Step 5: confirm the rate limit on OTP verification
The same action was repeated with 5 incorrect OTPs, and the server responded with:

Rate limit occurrence.
So the OTP check does have its own limit: after 5 incorrect OTPs the server responded with a rate limit. At this point the researcher connected the dots. The rate limit on the forget password feature had already been bypassed, so why not try the same technique on the OTP check? Brute forcing an OTP can open the door to a possible account takeover in an instance like this. Account takeover means logging in as the victim and controlling their account.
In the highlighted portions of the request above, the host ID of the X-Forwarded-For parameter was looped from 0 to 255, and an arbitrary amount of 6 digit numbers was supplied in the tokenVerify parameter, which is the parameter that carries the OTP.
In plain words: two things change from request to request. The X-Forwarded-For value walks through addresses so the server sees a new client each time, and the tokenVerify value is filled with different 6 digit numbers, which are the guesses at the code.
Step 6: compare response lengths with and without the bypass
With rate limiting on the OTP in place:

Response length 545 denotes rate limit present.
Response length is simply how many bytes the server's reply contains. Different replies have different lengths, so the length acts as a fingerprint: a reply of 545 bytes means the rate limit was hit.
After the rate limit on the OTP had been bypassed, with Payload1 containing X-Forwarded-For and Payload2 for the tokenVerify parameter:

Response length 520 denoting normal workflow.
Here Payload1 and Payload2 are the two lists of values Intruder cycles through: one list for the header, one list for the code. A reply of 520 bytes means the request was processed normally, as if no limit existed.
The payload set below indicates the successful OTP brute-force attempt, with the absence of a rate limit:

The report notes a response length of 545 when the rate limit is present and 520 for the normal workflow.
Root cause
The report does not state the root cause; the behaviour is consistent with the rate limiter keying on the header value. Because the header can be set to any value by the sender, each request can be made to look like it comes from a different address, so the per-client counter never fills up. The same technique worked on both the OTP sending endpoint and the OTP verification endpoint.
An everyday comparison: a bouncer who counts how many people enter per queue, but believes whatever name each person gives at the door. Give a new name every time and the count never goes up.
Impact
Two distinct impacts are described. On the forget password endpoint, the rate limit bypass lets an attacker flood a victim's inbox with OTP emails. On the OTP verification endpoint, the bypass removed the limit on incorrect guesses, allowing a brute-force attempt against the 6 digit OTP. The report frames the consequence as a possible account takeover in an instance like this.
Fix
The change that addresses the root cause is to stop keying the rate limiter on a client-controlled header such as X-Forwarded-For, and to derive the client identity from the connection or from a header that is set and sanitised by a trusted proxy in front of the application. Rate limiting should also be applied per account or per OTP session on the verification endpoint, not only per source address, so that rotating the apparent source does not reset the guess budget.
Variants to test
- Other forwarding headers. Send the same request with
X-Forwarded-For,X-Real-IP,X-Originating-IP,X-Remote-IP,X-Client-IPandForwarded, each with a different value per request. A positive result is that the rate limit response stops appearing and the normal response length or body returns. - Header value formats. Try single addresses, comma-separated lists, and values with ports or brackets. A positive result is any format that changes the limiter's key without changing the application's behaviour.
- Per-account limits on OTP verification. Keep the source address constant but vary the account or session. A positive result is that the guess budget is not shared across accounts, or that it resets when the session changes.
- Response-length or status differences. Compare the response for a wrong OTP with the response for a correct one, including length, status code and body. A positive result is a reliable oracle that distinguishes the two, which is what makes brute force practical. An oracle here just means any observable difference that tells you whether a guess was right.
- OTP lifetime and reuse. Request an OTP, wait, and try it, and also try reusing an OTP after a successful verification. A positive result is an OTP that stays valid longer than expected or can be reused.
- Sending endpoint limits. Repeat the forget password request with rotating forwarding headers and count the emails received. A positive result is more emails than the stated limit, as in the inbox flooding described here.
Glossary
- Account takeover: gaining control of someone else's account, for example by completing a password reset for their address.
- Baseline: the normal behaviour you record before changing anything, used for comparison later.
- Brute force: trying many possible values one after another until one is accepted.
- Bug bounty program: a scheme where a company invites researchers to report security problems and rewards them.
- Burp Intruder: the part of Burp Suite that sends one request many times with different values in chosen positions.
- Burp Suite: a proxy tool used to intercept, inspect, modify and replay web requests.
- Endpoint: a specific address on a server that performs a specific function.
- Header: a labelled line of extra information in a web request or response.
- OTP (one time password): a short code sent to you, here by email, that proves you control that address.
- Payload: in Intruder, one value from a list that is placed into a chosen position in the request.
- Private bug bounty program: a program that only invited researchers can take part in.
- Proxy: a tool or server that sits between your browser and a website and can pause and alter traffic.
- Rate limiting: a cap on how many requests a client may send in a period of time.
- Request: the message your browser sends to a website.
- Response: the server's reply to a request.
- Response length: the size in bytes of the server's reply, which can be used as a fingerprint for what happened.
tokenVerify: the parameter in the request that carries the OTP being checked.X-Forwarded-For: a header that tells a server which original address a forwarded request came from; it can be set by the sender.