account takeover on 3.0.1 version
- Triaged in 27 hours
- Fixed in 14 days
- Disclosed after 2 months
I find user reset password hash info and other security info on "/api/v1/users.info"
note : I login on rocketchat with ldap account (my role : user)
note: in request "https://target/api/v1/users.info?username=[x]" you should change usrname to userId
1- please login with user ldap account (role user)
2- send a request to https://target/api/v1/users.list and copy _id value
3- send a request to https://target/api/v1/users.info?userId=[userId] and copy email value (in response you can see important security information )
4- logout and click "forget your password" link on https://target/home and send an email to above email address that you copied
4- login with Your account and send a request to https://target/api/v1/users.list and search the same email in response and copy _id value
5- send a request to https://target/api/v1/users.info?userId=[userId] and copy reset hash value
6- logout your account and send a request to https://target/reset-password/[reset_hash]
7- set new password
8- login and enjoy
Impact
account takeover
Context
Rocket.Chat is a self-hosted team chat platform with a REST API under /api/v1/. The report concerns the users.info endpoint, which returns details about a single user, and the password reset flow exposed at /reset-password/[reset_hash] and reachable from the "forget your password" link on /home.
Normally users.info should return only the profile data the caller is allowed to see, and a password reset hash should be usable only by the person who received the reset email. The report shows an ordinary authenticated user can pull another user's email address and, after triggering a reset for that address, read the reset hash back out of the API and use it to set a new password.
Setup
The researcher logged in to Rocket.Chat with an LDAP account whose role was plain user, not an administrator. That is the only precondition stated: a low-privileged authenticated session on a 3.0.1 instance. No special tools are mentioned; the steps are carried out with ordinary HTTP requests against the API and the web interface.
Finding it
The researcher found that /api/v1/users.info returns a user's password reset hash along with other security-related information. The endpoint is meant to describe a user, not to hand out credentials-recovery material. The report also notes that the username parameter of the same endpoint can be swapped for a userId, which is how the later steps address arbitrary accounts.
Exploitation
Step 1: log in as a low-privileged user
Log in with an LDAP account that has the user role. Nothing more privileged is needed for any of the following steps.
Step 2: enumerate users and take an _id
Send a request to the user list endpoint and copy the _id value of a target:
https://target/api/v1/users.list
The _id is the internal identifier used to address that account in the next request.
Step 3: read the target's email and security information
Query users.info by userId:
https://target/api/v1/users.info?userId=[userId]
The response contains the target's email address and, according to the report, important security information as well. The email is what the attacker needs next, because the reset flow is keyed on it.
Step 4: trigger a password reset for the victim
Log out, go to https://target/home, click the "forget your password" link and submit a reset request for the email address copied in the previous step. The report then has the attacker log back in and read the reset hash for that account.
Step 5: log back in and locate the victim's _id
Log in with your own account again, request the user list:
https://target/api/v1/users.list
and search the response for the same email address, then copy the corresponding _id value.
Step 6: read the reset hash
Query users.info for that _id:
https://target/api/v1/users.info?userId=[userId]
and copy the reset hash value from the response. This is the reset hash value returned by the API for that account.
Step 7: use the hash to set a new password
Log out of your own account and open the reset page with the stolen hash:
https://target/reset-password/[reset_hash]
Step 8: set the new password
Choose a new password on that page. The report then sets a new password and logs in with it.
Step 9: log in as the victim
Log in with the victim's account and the password just set. The report closes the chain with "login and enjoy".
Root cause
The users.info endpoint returns fields that should never leave the server for a caller other than the account owner, in particular the password reset hash. The API returns the reset hash to an authenticated user who addresses another account by userId. The reset page accepts the hash and lets the password be changed. The report does not describe the server-side code, so the exact serialisation or permission check that failed is not stated; the behaviour is consistent with a missing field-level authorisation check on the user object returned by users.info.
Impact
Account takeover. An authenticated user with the lowest role can take over an account whose _id and email they can obtain through the same API, by triggering a reset and reading the hash back. The report does not discuss whether unauthenticated users can reach the same data, nor which accounts were tested beyond the researcher's own LDAP user and the victim account used in the walkthrough.
Fix
The report does not describe a fix or a patch.
Variants to test
- Request
users.infofor your own account and for another account, and diff the field sets. A positive result is any field in the other user's response that is absent from your own, especially anything named like a token, hash, secret or reset value. - Try the same endpoint with
usernameinstead ofuserId, as the report notes the parameter can be changed. A positive result is the same leaked fields returned for an account you do not own. - Walk the rest of the user-related API (
users.listand similar) looking for the same fields. A positive result is a reset hash or equivalent token appearing in a list response. - Trigger a password reset for a test account you control, then immediately query that account through the API from a second, low-privileged session. A positive result is the freshly generated hash appearing in the response.
- Check whether the reset hash changes after use or after a new reset request. A positive result is a hash that stays valid across requests, widening the window for abuse.
Hunting notes
This class of bug hides where an API returns a whole user object and the client is expected to ignore fields it does not need. The signal during recon is a users.info-style endpoint that accepts an identifier for any user and returns a rich object; compare the response for your own account with the response for another and look for fields that only make sense server-side. The report shows the impact by carrying the leak all the way through the reset flow to a successful login as the victim, which is what turns a suspicious field into an accepted account takeover: the chain from enumeration, to email disclosure, to reset trigger, to hash disclosure, to password change is what demonstrates that the leaked value is actually usable.
One practical detail from the report: the username parameter can be changed to userId, so a hunter who only tests one parameter form may miss the leak.
What happened, in plain words
Rocket.Chat is a chat program that a company can install on its own server, so staff can talk to each other in channels, much like Slack. It has two faces: the web pages you click around in (the chat window, the login screen, the "forget your password" page) and an API, which is a second, machine-facing door into the same system.
An API is a set of web addresses that return raw data instead of pretty pages. Think of the web interface as a restaurant menu with pictures, and the API as the kitchen hatch where you can ask for the ingredients directly. Programs use the API, but a person with a browser or a tool can call it too, and that is what this report does.
The researcher had an ordinary account on a Rocket.Chat server, the kind of account a normal employee gets, with no administrator powers. They found that one of the API addresses, users.info, which is supposed to describe a user, also handed back sensitive security information about that user, including the password reset hash. With that code, a logged-in low-privileged user could set a new password on someone else's account and then log in as them. That is called account takeover: you end up inside another person's account, with their identity and their access.
The weakness is classed as an Insecure Direct Object Reference, or IDOR. The idea is simple: a program hands you an object (here, a user record) and lets you name which one you want by putting an identifier in the request. If the server does not check that you are allowed to see that particular object, you can simply change the identifier and read someone else's data. Compare it to a hotel: the receptionist gives you a key card for room 204, and the door lock only checks that the card is valid, not that it belongs to room 204. Try the card on room 305 and the door opens.
The pieces involved
Before walking through the steps, here are the parts of Rocket.Chat the report touches.
/api/v1/: the base path of the API. Every API address in this report starts with it.users.list: an API address that returns a list of users. Each entry in the list has an_id, which is the internal identifier the system uses for that account. Think of it as the account's row number in a database, not something a person chose.users.info: an API address that returns the details of one single user. You tell it which user you want by giving an identifier./home: the web page with the "forget your password" link./reset-password/[reset_hash]: the web page where a password reset is completed. The[reset_hash]part is a long random-looking string that identifies one specific reset request.
A password reset normally works like this. You click "forget your password", type your email address, and the system creates a one-time secret code (the reset hash) and sends you a link containing it. Only someone who can read that email gets the code, so possessing the code is treated as proof that you own the mailbox. The whole security of the reset rests on that code staying secret. This report shows what happens when it does not.
Setting up
The researcher logged in to Rocket.Chat using an LDAP account whose role was plain user, not an administrator. LDAP is a common way for companies to keep all staff accounts in one central directory, so people sign in to many internal systems with the same username and password. The point of mentioning it is that the account was a normal, low-privilege one: no special rights were needed to carry out the attack.
That is the only precondition the report states: a low-privileged logged-in session on a Rocket.Chat 3.0.1 instance. No special tools are mentioned. The steps are done with ordinary requests to the API and the normal web interface.
Finding it
The researcher found that /api/v1/users.info leaks a user's password reset hash, along with other security-related information. The endpoint is meant to describe a user, not to hand out the material used to recover an account, so seeing the reset hash in its response was the signal that something was wrong.
The report also notes that the username parameter of the same endpoint can be swapped for a userId. In other words, you can ask for a user either by their username or by their internal _id, and the second form is how the later steps address any account they like.
Exploitation
Step 1: log in as a low-privileged user
Log in with an LDAP account that has the user role. Nothing more privileged is needed for any of the following steps. The reason to start here is to prove the attack works from the weakest position: if a normal employee can do it, so can anyone who gets hold of any account.
Step 2: list users and take an _id
Send a request to the user list endpoint and copy the _id value of a target:
https://target/api/v1/users.list
Line by line: https:// is the secure web protocol, target stands for the address of the Rocket.Chat server (the report replaces the real host with the word target), and /api/v1/users.list is the API address that returns the list of users. The response is data, not a web page, and each user in it carries an _id. You copy the _id of the account you want to attack because that identifier is what the next request needs in order to point at that specific account.
Step 3: read the target's email and security information
Query users.info by userId:
https://target/api/v1/users.info?userId=[userId]
Line by line: this is the same server, calling the users.info endpoint. Everything after the ? is the query string, the part of a web address that carries parameters. Here there is one parameter, userId, and its value is [userId], a placeholder where you paste the _id you copied in step 2. The response contains the target's email address and, according to the report, important security information as well. The email matters because the password reset flow is keyed on the email address: to trigger a reset for the victim, you need to know which address to submit.
Step 4: trigger a password reset for the victim
Log out, go to https://target/home, click the "forget your password" link and submit a reset request for the email address copied in the previous step. The report then has the attacker log back in and read the reset hash for that account.
Why log out first? Because the reset request is made the way a stranger would make it, from the public login page, without being signed in. The system does not know who is asking; it only sees an email address. The next steps show that it can be read from the API instead.
Step 5: log back in and locate the victim's _id
Log in with your own account again, request the user list:
https://target/api/v1/users.list
and search the response for the same email address, then copy the corresponding _id value. This is the same request as step 2, repeated for a reason: you now have the victim's email from step 3, and you use it to pick out the right entry in the list and confirm the _id that belongs to it. The _id is the handle you will use to ask for that account's details in the next step.
Step 6: read the reset hash
Query users.info for that _id:
https://target/api/v1/users.info?userId=[userId]
and copy the reset hash value from the response. This is the reset hash value returned by the API for that account. A token here means a short piece of secret data that stands in for proof of identity: whoever holds it is treated as entitled to do the thing it unlocks. Because the API returns the token to any logged-in user who asks about that account, the secrecy the reset flow depends on is gone.
Step 7: use the hash to set a new password
Log out of your own account and open the reset page with the stolen hash:
https://target/reset-password/[reset_hash]
Line by line: this is the normal reset page a victim would reach by clicking the link in their email. The [reset_hash] placeholder is where the stolen value goes. Logging out first matters because you are now acting as the victim, not as yourself: the page is meant for someone who is not signed in and who proves ownership by holding the code. You hold the code, so the page treats you as the owner.
Step 8: set the new password
Choose a new password on that page. The report then sets a new password and logs in with it.
Step 9: log in as the victim
Log in with the victim's account and the password just set. The report closes the chain with "login and enjoy". At this point the attacker is inside the victim's account with the victim's identity and access, which is the account takeover.
Why it works
The users.info endpoint returns fields that should never leave the server for anyone other than the account owner, in particular the password reset hash. The API returns the reset hash to a logged-in user who names another account by userId. The reset page accepts the hash and lets the password be changed.
The report does not describe the server-side code, so the exact check that failed is not stated. The behaviour fits a missing field-level permission check on the user object returned by users.info: the server decides whether you may see the user at all, but does not decide, field by field, whether you may see this particular secret.
Impact
Account takeover. A logged-in user with the lowest role can take over an account whose _id and email they can obtain through the same API, by triggering a reset and reading the hash back. The report does not discuss whether users who are not logged in can reach the same data, nor which accounts were tested beyond the researcher's own LDAP user and the victim account used in the walkthrough.
Fix
The report does not describe a fix or a patch.
Variants to test
These are follow-up checks in the same spirit, useful if you want to look for the same mistake elsewhere.
- Request
users.infofor your own account and for another account, and compare the field sets. A positive result is any field in the other user's response that is absent from your own, especially anything named like a token, hash, secret or reset value. - Try the same endpoint with
usernameinstead ofuserId, as the report notes the parameter can be changed. A positive result is the same leaked fields returned for an account you do not own. - Walk the rest of the user-related API (
users.listand similar) looking for the same fields. A positive result is a reset hash or equivalent token appearing in a list response. - Trigger a password reset for a test account you control, then immediately query that account through the API from a second, low-privileged session. A positive result is the freshly generated hash appearing in the response.
- Check whether the reset hash changes after use or after a new reset request. A positive result is a hash that stays valid across requests, widening the window for abuse.
Hunting notes
This class of bug hides where an API returns a whole user object and the client is expected to ignore fields it does not need. The signal during recon is a users.info-style endpoint that accepts an identifier for any user and returns a rich object. Compare the response for your own account with the response for another and look for fields that only make sense on the server side.
The report shows the impact by carrying the leak all the way through the reset flow to a successful login as the victim. That is what turns a suspicious field into an accepted account takeover: the chain from listing users, to disclosing an email, to triggering a reset, to disclosing the hash, to changing the password is what demonstrates that the leaked value is actually usable.
One practical detail from the report: the username parameter can be changed to userId, so someone who only tests one parameter form may miss the leak.
Glossary
- API: a set of web addresses that return raw data for programs (and curious people) to use, rather than pages for a browser to display.
- Endpoint: one specific API address, such as
users.info, that performs one job. - REST API: an API style where each address represents a thing (a user, a message) and the address plus parameters say which one you mean.
- Parameter: a named value attached to a web address after a
?, such asuserIdinusers.info?userId=.... - Query string: the part of a web address after the
?that carries parameters. _id: the internal identifier a system uses for a record, here a user account; not chosen by the person.- IDOR (Insecure Direct Object Reference): a flaw where a program lets you name which record you want by an identifier but does not check that you are allowed to see that record.
- Authentication: proving who you are, usually by logging in.
- Authorisation: what a logged-in user is allowed to do or see; a missing check here is what this report exploits.
- Low-privileged user: an account with the fewest rights, such as a normal employee rather than an administrator.
- LDAP: a central company directory of staff accounts, used so people sign in to many systems with one set of credentials.
- Role: the label that decides what an account may do; here
userversus administrator. - Token: a piece of secret data that stands in for proof of identity or permission; whoever holds it is treated as entitled to what it unlocks.
- Reset hash: the one-time secret code generated by a password reset and normally delivered only by email.
- Password reset flow: the sequence of pages and requests that lets someone who forgot their password set a new one, usually by proving they can read the account's email.
- Account takeover: gaining control of someone else's account, here by setting a new password and logging in as them.
- Field-level permission check: a check that decides, for each individual piece of data in a response, whether this particular caller may see it.
- Serialisation: turning a stored record into the data format sent over the network, such as the JSON returned by an API.
- Recon: the exploratory phase of security testing, where you map what a system exposes before trying to break anything.
- Diff: comparing two responses side by side to spot differences, such as fields present for one user but not another.