Login email verification bypass via `/oauth/token`.
The email verification restriction on GitLab's /oauth/token endpoint was bypassed because the server only checked for an active session that had completed email verification, regardless of IP address. An attacker with valid credentials could poll the endpoint and gain tokens once the victim completed verification on any device.
- Disclosed after 12 days
Summary by the researcher
If an app supports ROPC flow, try to bypass any MFA or additional login verification.
Bypass the Gitlab's email verification on login
The report
Summary
Hello team, I want to report a security issue on the GitLab authentication functionality. The email verification on login provides an additional layer of security despite 2FA not being implemented. This security measure is being triggered once the account has three or more failed sign-in attempts in 24 hours or a user attempts to sign in from a new IP address. Reference here
Gitlab also supports another basic authentication which is the Resource Owner Password Credentials (ROPC) flow. It is where the user credentials(username and password) will be exchanged for an access token with full read and write scope on the endpoint /oauth/token. Just like the web authentication, there is also an implemented restriction on this endpoint to avoid any unauthorized authentication. For example, sending the token exchange request on the said endpoint from a new IP address will result to the following API error response:
{"error":"invalid_grant","error_description":"The provided authorization grant is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client."}
However, this restriction is only being implemented if there is no active session on the account.
I have discovered that it is possible to bypass this restriction. During my testing, the restriction on /oauth/token is being voided once the victim authenticates and completes the email verification regardless of the IP difference between the attacker and the victim.
##Exploit
#!/usr/bin/sh
USERNAME=gitlab_username
PASSWORD=gitlab_password
while true
do
curl --data "grant_type=password&username=$USERNAME&password=$PASSWORD&scope=api" \
--request POST "https://gitlab.com/oauth/token"
echo ''
sleep 1.5
done
The simple bash script above will serve as an event listener for the attacker. Please note that if the account has already an active session (which means it already completed the email verification) the token exchange will be successful on the first request. Otherwise, it will loop with errors until the victim authenticates and completes the verification on any device or IP.
##Current Behavior
- The server only checks whether the account has an active session that has completed an email verification on any device and IP address.
##Expected Behavior
- The server must somehow validate the authenticity of the user sending the request on
/oauth/token. E.g. sending an email verification link(not code).
##Clarification This bug only affects accounts with 2FA disabled / no configured.
Steps to reproduce
For this to reproduce, your GitLab account must trigger the email verification feature on login. To do this, you can do one of the following.
- Logout all your session and restart your pc
- Logout all your session and deliberately commit 3 to 5 incorrect password attempt until you see the warning
Maximum login attempts exceeded. Wait 10 minutes and try again.. Then wait for 10 minutes to login the correct credentials.
You need two(2) devices with different IP addresses. In my case (my VPS terminal and my local machine).
As an attacker:
1. Login the account via /oauth/token endpoint by running the bash script on your terminal to prove the RESTRICTION (IP is flagged and the API will respond an error message mentioned earlier this report).
2. Keep it running and notice that there is no success on the authentication.
As the Victim:
3. Login the account on victim on web login which will require an email verification.
4. Complete the verification by providing the verification code sent to the email. Sometimes it is delayed, so you might want to resend the code .
Once the victim is successfully authenticated, the attacker request on the terminal is also being authenticated and able to get access and refresh token.
##Demo and PoC █████
##Suggested Fix The implemented mitigation is somehow not sufficient. Relying on the active sessions simply gives the attacker the success since victims always complete this verification step on their trusted devices. There should be a more strict verification process on the vulnerable endpoint such as sending a verification link on the victim's email address notifying them that an ROPC access request is being attempted from a certain device and IP address.
Impact
This bug makes the implemented additional layer of security ineffective. This is simply a demonstration where the victim unknowingly completes an email verification for the attacker to access his/her own compromised credentials.
Context
GitLab's web login has an email verification step that acts as an additional layer of security even when two-factor authentication is not configured. According to the report, this step is triggered when an account has three or more failed sign-in attempts in 24 hours, or when a user attempts to sign in from a new IP address. The researcher links to GitLab's email verification documentation for this behaviour.
GitLab also supports a second basic authentication mechanism: the Resource Owner Password Credentials (ROPC) flow. In this flow the user's credentials, a username and password, are exchanged for an access token with full read and write scope at the endpoint /oauth/token. The report notes that this endpoint has its own restriction intended to prevent unauthorised authentication. For example, sending the token exchange request from a new IP address returns the following API error response:
{"error":"invalid_grant","error_description":"The provided authorization grant is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client."}
That restriction, however, is only applied when there is no active session on the account. The researcher's finding is that this condition can be abused to bypass the email verification on login.
Setup
To reproduce the issue, the GitLab account must trigger the email verification feature on login. The report gives two ways to reach that state:
- Log out all sessions and restart the PC.
- Log out all sessions and deliberately make 3 to 5 incorrect password attempts until the warning
Maximum login attempts exceeded. Wait 10 minutes and try again.appears, then wait 10 minutes and log in with the correct credentials.
Two devices with different IP addresses are needed. In the researcher's case these were a VPS terminal and a local machine. The bug only affects accounts with 2FA disabled or not configured.
Finding it
The researcher started from a general idea: if an application supports the ROPC flow, try to bypass any MFA or additional login verification through it. The email verification on login is described in the report as an additional layer of security despite 2FA not being implemented, and the /oauth/token endpoint has a restriction that should stop authentication from a new IP address.
What the researcher noticed is that the restriction on /oauth/token is voided once the victim authenticates and completes the email verification, regardless of the IP difference between the attacker and the victim. In other words, the server only checks whether the account has an active session that has completed an email verification on any device and IP address, rather than validating the authenticity of the user sending the request to /oauth/token.
Exploitation
Step 1: Prepare the attacker's request loop
The attacker runs a small script that repeatedly tries to exchange the victim's username and password for a token through the ROPC flow. The report presents it as follows:
#!/usr/bin/sh
USERNAME=gitlab_username
[redacted]
while true
do
curl --data "grant_type=password&username=$USERNAME&[redacted]&scope=api" \
--request POST "https://gitlab.com/oauth/token"
echo ''
sleep 1.5
done
The script sets USERNAME and PASSWORD for the target account and loops forever. Each iteration sends a POST to https://gitlab.com/oauth/token with a form body containing grant_type=password, the username, the password and scope=api, then prints a newline and sleeps for 1.5 seconds. The researcher describes this script as an event listener for the attacker.
Step 2: Confirm the restriction is in place
As the attacker, log in to the account via the /oauth/token endpoint by running the bash script on the terminal. This proves the restriction: the IP is flagged and the API responds with the error message quoted earlier in the report. The attacker keeps the script running and observes that there is no success on the authentication.
The report notes that if the account already has an active session, meaning it has already completed the email verification, the token exchange succeeds on the first request. Otherwise it loops with errors.
Step 3: The victim logs in on the web
As the victim, log in to the account through the web login at https://gitlab.com/users/sign_in. This login requires an email verification.
Step 4: The victim completes the verification
The victim completes the verification by providing the verification code sent to the email. The report notes that the code is sometimes delayed, so the victim may need to resend it.
Step 5: The attacker's loop succeeds
Once the victim is successfully authenticated, the attacker's request on the terminal is also authenticated and is able to obtain an access token and a refresh token. Once the victim is successfully authenticated, the attacker's request on the terminal is also authenticated and able to obtain an access token and a refresh token.
Root cause
The server only checks whether the account has an active session that has completed an email verification on any device and IP address. The report says relying on active sessions gives the attacker success, since victims complete the verification step on their trusted devices.
Impact
The bug makes the additional layer of security ineffective. The report describes it as a demonstration where the victim unknowingly completes an email verification for the attacker to access their own compromised credentials. The attacker needs the victim's username and password, and the account must have 2FA disabled or not configured. Under those conditions, the attacker obtains an access token and a refresh token through the ROPC flow.
Fix
The report states that the implemented mitigation is not sufficient and that relying on active sessions gives the attacker success because victims always complete the verification step on their trusted devices. It recommends a stricter verification process on the vulnerable endpoint, such as sending a verification link to the victim's email address that notifies them an ROPC access request is being attempted from a certain device and IP address. The report does not describe any change that was actually made.
Variants to test
- Other applications that support the ROPC flow: check whether a token request from a new IP address is rejected while no session exists, then whether it succeeds once a legitimate user logs in elsewhere. A positive result is a token issued to the attacker's request after the victim's login, without the attacker completing any verification.
- Applications that gate ROPC behind email verification or MFA: run a request loop from one IP while a legitimate user completes verification from another. A positive result is the loop returning a token after the victim's verification.
- Applications that tie security checks to session state rather than to the requesting client: compare the response to the same token request before and after a legitimate session is created. A positive result is a change from an error such as
invalid_grantto a successful token response with no change on the attacker's side. - Accounts with MFA enabled: the report says the bug only affects accounts with 2FA disabled, so test whether the same session-based bypass applies when MFA is configured. A positive result would be a token issued without the second factor being satisfied by the attacker.
What happened, in plain words
GitLab is a website where teams keep their code and work on it together. To get in, you type a username and a password. Sometimes GitLab asks for one more thing: a code sent to your email inbox. That extra step is called email verification, and it exists to make life harder for someone who has stolen your password.
This report is about a way to skip that extra step. The researcher found that GitLab has a second, less visible way to log in, meant for programs rather than people. If an attacker knows your username and password, they can keep asking that second door for access over and over. Normally the door stays shut because the request comes from an unfamiliar place. But the moment you log in yourself on your own computer and type the email code, the attacker's waiting requests are let in too. The victim unknowingly completes an email verification for the attacker to access their own compromised credentials.
The report was filed on HackerOne against GitLab, by the researcher cybxis, and disclosed on 3 September 2024. The platform records the weakness as a missing critical step in authentication, with no severity score and no bounty listed.
The pieces you need to know first
Before the details make sense, here are the ideas the report leans on, explained from scratch.
An API. Think of a restaurant. The dining room is the website you see in your browser: menus, buttons, pictures. The kitchen is the API, a set of doors where a program can ask for things directly, without any decoration. GitLab's website uses its own API behind the scenes, and so can anyone else who knows the address of a door and what to say.
An endpoint. An endpoint is one specific door of that API, identified by a web address. The report talks about one endpoint in particular, /oauth/token, which is the door you knock on when you want to trade a username and password for a key.
A token. A token is a temporary key. Instead of sending your password with every single request, a program asks for a token once and then shows the token. GitLab hands out two kinds: an access token, which is the key that opens the account, and a refresh token, which is used to get a fresh access token later when the first one expires. The report says the access token here has full read and write scope, meaning it can look at and change the account's data.
A session. A session is the website remembering that you are already logged in. When you sign in through the browser, the site gives your browser a small piece of proof, and your browser shows it on every following page so you do not have to type your password again. A session belongs to a browser on a device, not to a person.
An IP address. Every device on the internet has a numeric address, a bit like a postal address, so that replies can find their way back. Two different devices, or the same device on a different network, usually have different IP addresses. Security systems often use the IP address to judge whether a login looks familiar.
Two-factor authentication (2FA). A second proof of identity on top of the password, usually a short code from an app or a text message. The report repeatedly says this bug only affects accounts where 2FA is switched off or not set up.
The ROPC flow. ROPC stands for Resource Owner Password Credentials. It is a standard way for a program, rather than a person clicking buttons, to log in: the program sends the username and password in one request and receives a token back. The report links to GitLab's documentation for this flow. The name sounds grand, but the idea is simple: hand over the password, get a key.
Email verification on login. GitLab's extra check. According to the report, it kicks in when an account has had three or more failed sign-in attempts in 24 hours, or when someone tries to sign in from a new IP address. The report links to GitLab's documentation on email verification for this behaviour. When it triggers, you must fetch a code from your inbox before you are let in.
A bypass. A bypass is not breaking a lock with force. It is finding another way around it, a window left open next to the locked door. The vulnerability class here, a missing critical step in authentication, means the system checks some things but forgets one check that the whole protection depends on.
The two doors, and the rule on the second one
GitLab's normal web login has the email verification step. The report describes it as an additional layer of security that exists even though 2FA is not implemented.
The second door is the ROPC flow at /oauth/token. The report says this endpoint has its own restriction to prevent unauthorised authentication. For example, if you send the token exchange request from a new IP address, you get this API error response:
{"error":"invalid_grant","error_description":"The provided authorization grant is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client."}
In plain words: the server says no, the grant is invalid. The long description lists several possible reasons in one sentence, which is typical of OAuth error messages; the important part for us is that the request was refused.
Here is the catch the researcher found. That restriction is only applied when there is no active session on the account. If the account already has a session somewhere, the door at /oauth/token behaves differently. The researcher's finding is that this condition can be abused to bypass the email verification on login.
Setting up the test
To see this happen, the account must be in a state where the email verification will trigger on login. The report gives two ways to get there:
- Log out of all sessions and restart the PC.
- Log out of all sessions and deliberately make 3 to 5 incorrect password attempts until the warning
Maximum login attempts exceeded. Wait 10 minutes and try again.appears, then wait 10 minutes and log in with the correct credentials.
Why these steps? The second one deliberately trips the failed-attempt counter, which is one of the triggers for email verification. Both are ways of making GitLab decide that this login deserves the extra check.
You also need two devices with different IP addresses. In the researcher's case these were a VPS terminal and a local machine. A VPS is a rented computer in a data centre that you control remotely through a terminal, a text window where you type commands. Using it gives the attacker a different IP address from the victim's home machine, which is exactly the difference the restriction is supposed to notice.
The report states that the bug only affects accounts with 2FA disabled or not configured.
How the researcher found it
The starting idea was general: if an application supports the ROPC flow, try to bypass any MFA or additional login verification through it. MFA means multi-factor authentication, the same family of ideas as 2FA.
The email verification on login is described in the report as an additional layer of security despite 2FA not being implemented, and the /oauth/token endpoint has a restriction that should stop authentication from a new IP address.
What the researcher noticed is that the restriction on /oauth/token is voided once the victim authenticates and completes the email verification, regardless of the IP difference between the attacker and the victim. In other words, the server only checks whether the account has an active session that has completed an email verification on any device and IP address, rather than validating the authenticity of the user sending the request to /oauth/token.
Think of a building where the front desk checks your ID and gives you a visitor badge. The side entrance is supposed to be locked for strangers, but its lock is wired to the front desk's badge printer: once a badge is printed for that account, the side door opens for the waiting request. The side door checks the account's session, not who is standing in front of it.
Exploitation, step by step
Step 1: Prepare the attacker's request loop
The attacker runs a small script that repeatedly tries to exchange the victim's username and password for a token through the ROPC flow. The report presents it as follows:
#!/usr/bin/sh
USERNAME=gitlab_username
[redacted]
while true
do
curl --data "grant_type=password&username=$USERNAME&[redacted]&scope=api" \
--request POST "https://gitlab.com/oauth/token"
echo ''
sleep 1.5
done
Line by line, in plain words:
#!/usr/bin/shtells the computer which program should read this file. It is a script for a Unix-style shell, the text interface where you type commands.USERNAME=gitlab_usernameand `[redacted] store the target account's credentials in two named boxes, so they can be reused without retyping. In a real attack these would be the stolen values.while truestarts a loop that never ends on its own. The script will keep going until someone stops it.domarks the beginning of the commands that repeat.curlis a command-line tool for sending web requests. It is the browser's cousin without the window.--data "grant_type=password&username=$USERNAME&[redacted]&scope=api"is the body of the request. It is written in the same format a web form uses when you press submit: pairs of a name and a value joined by&.grant_type=passwordsays which login method is being used, the ROPC flow.usernameandpasswordare filled in from the boxes above.scope=apiasks for permission to use the API, which the report describes as full read and write scope.--request POSTsays this is a POST request, the kind used to send data rather than just ask for a page."https://gitlab.com/oauth/token"is the endpoint being knocked on.echo ''prints an empty line, so the responses do not run together on screen and are easier to read.sleep 1.5pauses for one and a half seconds before trying again, so the script does not hammer the server.donecloses the loop.
The researcher describes this script as an event listener for the attacker. That phrase is borrowed from programming: an event listener is something that sits quietly waiting for an event, then reacts. Here the script sits waiting for the account's session state to change, and reacts by finally getting a token.
Step 2: Confirm the restriction is in place
As the attacker, log in to the account via the /oauth/token endpoint by running the bash script on the terminal. This proves the restriction: the IP is flagged and the API responds with the error message quoted earlier in the report. The attacker keeps the script running and observes that there is no success on the authentication.
Why do this first? Because a bypass only means something if you can show the lock was working beforehand. Seeing the invalid_grant error proves the attacker's IP address is being noticed and refused. The report notes that if the account already has an active session, meaning it has already completed the email verification, the token exchange succeeds on the first request. Otherwise it loops with errors.
Step 3: The victim logs in on the web
As the victim, log in to the account through the web login at https://gitlab.com/users/sign_in. This login requires an email verification.
This is the ordinary thing a real user does every day. The victim has no idea a script is waiting on the other side.
Step 4: The victim completes the verification
The victim completes the verification by providing the verification code sent to the email. The report notes that the code is sometimes delayed, so the victim may need to resend it.
The victim completes the verification, and the attacker's pending requests are then authenticated.
Step 5: The attacker's loop succeeds
Once the victim is successfully authenticated, the attacker's request on the terminal is also authenticated and is able to obtain an access token and a refresh token. The attacker never needed to complete the email verification themselves; the victim's completion of the step on their own device and IP was enough to unlock the attacker's pending ROPC requests.
The report says the access token has full read and write scope, and the attacker also obtains a refresh token.
Why it works
The server only checks whether the account has an active session that has completed an email verification on any device and IP address. The check is tied to the account's session state rather than to the request that is being made to /oauth/token. Because the victim always completes the verification step on their trusted devices, the attacker's pending ROPC requests are authorised as soon as that session exists, even though the requests come from a different IP address.
Put simply: the question the server asks is "does this account have a verified session somewhere?" when the question it should ask is "is the person making this particular request the account owner?". The first question is about the account. The second is about the request. The report's expected behaviour is that the server must somehow validate the authenticity of the user sending the request on /oauth/token, for example by sending an email verification link rather than a code.
What it means in practice
The bug makes the additional layer of security ineffective. The report describes it as a demonstration where the victim unknowingly completes an email verification for the attacker to access their own compromised credentials.
Two conditions are needed. The attacker must already know the victim's username and password, so this is not a way to guess a password. And the account must have 2FA disabled or not configured. Under those conditions, the attacker obtains an access token and a refresh token with full read and write scope through the ROPC flow, without ever passing the email verification themselves.
That is why the email verification matters in the first place: it is the safety net for the case where a password has already leaked. This bug cuts the net.
The suggested fix
The report states that the implemented mitigation is not sufficient and that relying on active sessions gives the attacker success because victims always complete the verification step on their trusted devices. It recommends a stricter verification process on the vulnerable endpoint, such as sending a verification link to the victim's email address that notifies them an ROPC access request is being attempted from a certain device and IP address. The report does not describe any change that was actually made.
The difference between a code and a link matters here. The report recommends sending a verification link to the victim's email address notifying them an ROPC access request is being attempted from a certain device and IP address.
Similar things to look for elsewhere
- Other applications that support the ROPC flow: check whether a token request from a new IP address is rejected while no session exists, then whether it succeeds once a legitimate user logs in elsewhere. A positive result is a token issued to the attacker's request after the victim's login, without the attacker completing any verification.
- Applications that gate ROPC behind email verification or MFA: run a request loop from one IP while a legitimate user completes verification from another. A positive result is the loop returning a token after the victim's verification.
- Applications that tie security checks to session state rather than to the requesting client: compare the response to the same token request before and after a legitimate session is created. A positive result is a change from an error such as
invalid_grantto a successful token response with no change on the attacker's side. - Accounts with MFA enabled: the report says the bug only affects accounts with 2FA disabled, so test whether the same session-based bypass applies when MFA is configured. A positive result would be a token issued without the second factor being satisfied by the attacker.
Glossary
- 2FA (two-factor authentication): a second proof of identity on top of a password, usually a code from an app or a message.
- Access token: a temporary key that lets a program use an account through the API.
- API: the set of doors a program uses to talk to a service directly, without the website's pages.
- Bash script: a text file of commands for a Unix-style shell, run in order.
- Bypass: getting around a protection without breaking it, by finding another path.
- curl: a command-line tool for sending web requests.
- Email verification on login: GitLab's extra step that asks for a code sent to the account's email before letting a login through.
- Endpoint: one specific address of an API, such as
/oauth/token. - Event listener: a piece of code that waits quietly for something to happen and then reacts.
invalid_grant: the error name returned when a token request is refused because the grant is not acceptable.- IP address: the numeric address of a device on the internet, used to route replies and often to judge whether a login looks familiar.
- MFA (multi-factor authentication): logging in with more than one kind of proof, of which 2FA is the common case.
- Missing critical step in authentication: a weakness where the system performs some checks but omits one that the protection depends on.
- OAuth: the family of standards behind token-based login, including the ROPC flow and the
/oauth/tokenendpoint. - POST request: a web request that sends data to the server, as opposed to simply asking for a page.
- Refresh token: a longer-lived key used to obtain a new access token when the old one expires.
- ROPC (Resource Owner Password Credentials): a login flow where a program sends a username and password and receives a token in return.
- Scope: the set of permissions a token carries;
scope=apiasks for API access, described in the report as full read and write. - Session: the website's memory that a particular browser is already logged in.
- Shell / terminal: the text window where commands are typed and their output appears.
- Token: a temporary key issued after a successful login, used instead of repeating the password.
- VPS: a rented computer in a data centre that you control remotely, useful for getting a different IP address.
- Web login: signing in through the website's pages in a browser, at
https://gitlab.com/users/sign_in.