Registration bypass with leaked Invite Token
The validateInviteToken API route passed an unauthenticated user-supplied token directly to a database lookup without checking its type, so an attacker could send a MongoDB regex object instead of a string. By testing regex prefixes and observing the boolean response, an attacker could guess a valid invite token and then use it to register an account or join a private channel.
- Triaged in 4 hours
- Fixed in 23 days
- Disclosed after 3.6 years
Summary:
Regular expressions in the validateInviteToken route allows unauthenticated users to guess a valid invite token, that allows them to access a private channel or register accounts on a remote server with "Secret URL" registration method enabled.
Description:
The API route validateInviteToken passes an unauthenticated clients token bodyParam to the validateInviteToken method as found in app/api/server/v1/invites.js#L45-L62
API.v1.addRoute('validateInviteToken', { authRequired: false }, {
post() {
const { token } = this.bodyParams;
if (!token) {
throw new Meteor.Error('error-invalid-token', 'The invite token is invalid.', { method: 'validateInviteToken', field: 'token' });
}
let valid = true;
try {
validateInviteToken(token);
} catch (e) {
valid = false;
}
return API.v1.success({ valid });
},
});
The token is then passed to Invites.findOneById(token) without further checks of the input data, which allows to send an Object instead of a string. This object can be a $regex Mongo DB query, that reduces the number of queries required to leak a valid invite token.
Once found, an attacker can navigate to /invite/:token to then register a new account with access to the specific channel. After initial registration, the process can be repeated to join more rooms with non-expired invites.
curl 'https://open.rocket.chat/api/v1/validateInviteToken'
-H "content-type: application/json"
-d '{ "token": { "$regex": ".*" } }'
Expired invite token might mask other token because Mongo DB only returns one document (sorted by order of insertion). A valid strategy to leak a 6 character token (case-sensitive letters and numbers) is to prefix the regex (e.g. ^a.*, ^b.*, etc) and check the boolean result.
Releases Affected:
- 3.9.4
Steps To Reproduce (from initial installation to vulnerability):
(Add details for how we can reproduce the issue)
1.) Leak a valid token with consecutive validateInviteToken checks
2.) Browse to /invite/:leaked_token
3.) Register account
Suggested mitigation
- validate user input to be a String
Impact
Unauthenticated attackers can leak invite links to register new accounts, although public registration is disabled. Authenticated users might gain unauthorized access to private chat rooms.
Context
Rocket.Chat is a self-hosted team chat platform. Like most such products it supports invite links: an existing user creates an invite for a room, and the resulting link can be used to join that room, or, depending on configuration, to register a new account on the server. The link carries a token, and the server exposes an API route, validateInviteToken, that lets a client check whether a token is still valid before showing the registration or join flow.
The route is deliberately unauthenticated (authRequired: false), because the person following an invite link does not have an account yet. That design decision is the starting point of this report: an unauthenticated endpoint that takes attacker-controlled input and answers a yes/no question about it.
Setup
The report lists Rocket.Chat 3.9.4 as the affected release. The interesting precondition is a server configuration: the vulnerability matters most when the "Secret URL" registration method is enabled, because in that mode the invite token is what stands between an anonymous visitor and a new account. The report also states that authenticated users might gain unauthorised access to private chat rooms.
No special account is needed to send the request; the endpoint is reachable without authentication. The only tooling shown is curl.
Finding it
The researcher looked at the server-side handler for the route in app/api/server/v1/invites.js (lines 45 to 62 of the referenced commit) and found that the request body parameter is passed straight through to the validation function:
API.v1.addRoute('validateInviteToken', { authRequired: false }, {
post() {
const { token } = this.bodyParams;
if (!token) {
throw new Meteor.Error('error-invalid-token', 'The invite token is invalid.', { method: 'validateInviteToken', field: 'token' });
}
let valid = true;
try {
validateInviteToken(token);
} catch (e) {
valid = false;
}
return API.v1.success({ valid });
},
});
The handler only checks that token is present, not that it is a string. The value is handed to validateInviteToken(token), which in turn calls Invites.findOneById(token) without further checks on the input data. Because the body is JSON, token can be an object rather than a string, and an object is exactly what a MongoDB query operator needs. A $regex value turns the lookup into a pattern match, and the boolean valid in the response tells the caller whether the pattern matched any invite document.
That is the flaw: a lookup that was meant to answer "is this exact token valid" now answers "does any invite token match this pattern", to anyone, without authentication.
Exploitation
Step 1: Confirm that the operator is accepted
The researcher sent a JSON body whose token is an object containing a $regex operator matching everything:
curl 'https://open.rocket.chat/api/v1/validateInviteToken'
-H "content-type: application/json"
-d '{ "token": { "$regex": ".*" } }'
Here token is not a string but a query document. .* matches any token, so if a matching invite document exists the lookup succeeds and the route reports the token as valid.. That single response confirms that the input reaches the database query unmodified.
Step 2: Leak a token character by character
A wildcard match only proves that some invite exists. To recover an actual token, the researcher used the boolean oracle as a prefix test. The report describes a strategy for leaking a 6-character token made of case-sensitive letters and numbers. By anchoring the regex at the start of the string and fixing one character at a time, each request answers whether any invite token begins with that prefix:
- send
^a.*,^b.*, and so on, and keep the prefix for whichvalidistrue; - extend the prefix one character at a time, testing each candidate against the alphabet of letters and digits;
- after six successful rounds the full token is known.
The report notes one complication: expired invite tokens can mask other tokens, because MongoDB returns only one document, sorted by order of insertion. If the first matching document is an expired invite, the boolean result reflects that document rather than a live one, so a prefix that matches only expired invites can mislead the search. The researcher's strategy is to work with the prefix oracle and the boolean result rather than relying on a single wildcard match.
Step 3: Use the leaked token
With a valid token in hand, the attacker browses to /invite/:token. From there the normal invite flow applies: register a new account, which, on a server using the "Secret URL" registration method, is otherwise closed to the public, and land in the channel the invite points to. The report adds that the process can be repeated to join more rooms whose invites have not expired.
Root cause
The handler trusts the shape of the request body. this.bodyParams.token is used as-is, and the only guard is a truthiness check, so a JSON object passes where a string was intended. Downstream, Invites.findOneById(token) receives that object and MongoDB interprets $regex as a query operator. The route's own error handling does not help: it catches exceptions from validateInviteToken and converts them into valid: false, so a malformed or unexpected input simply looks like an invalid token rather than being rejected as bad input.
The design also amplifies the bug. The endpoint is unauthenticated by necessity, and it returns a boolean derived from a database lookup, which is a classic oracle: each request leaks one bit about data the caller should not be able to query.
Impact
Unauthenticated attackers can leak invite links and use them to register new accounts even when public registration is disabled, provided the server uses the "Secret URL" registration method. Authenticated users can also gain unauthorised access to private chat rooms through non-expired invites. Registration applies when the server uses the "Secret URL" registration method, and room access requires a non-expired invite.
Fix
The suggested mitigation in the report is to validate that the user input is a String. Rejecting any non-string token before it reaches validateInviteToken removes the operator injection at the source, since a string cannot carry a $regex key. The report does not describe a patch that was applied, so the concrete change made by the maintainers is not stated here.
Variants to test
- Other operators on the same parameter. If
$regexis accepted, try$ne,$gt,$inor$existsagainst the sametokenfield. A positive result is a response that differs from the invalid-token path for a value that is not a real token. - Other unauthenticated lookup routes. Any route with
authRequired: falsethat takes an identifier frombodyParamsor query parameters and passes it to a database lookup is a candidate. A positive result is a boolean or object response that changes when the value is replaced by an operator object. - Other boolean oracles. Routes that answer "does this exist" or "is this valid" without authentication can be turned into extraction oracles the same way. A positive result is a response that lets you narrow a secret one character at a time.
- Expired versus live documents. Where the lookup returns a single document, test whether expired or older records mask live ones, as the report describes. A positive result is a prefix that matches but does not lead to a usable token, which tells you the ordering of documents matters.
Hunting notes
The pattern to look for during recon is an unauthenticated endpoint whose name suggests validation or existence checking (validate*, check*, exists*) and whose response is a boolean. Source code is the fastest way to confirm it: find the route definition, check authRequired, and follow the parameter into the database call. If the parameter is used without a type check, the endpoint is worth a request.
The report's impact argument rests on two concrete consequences rather than on the oracle alone: account registration on a server where public registration is disabled, and access to private channels. Demonstrating either end to end, by leaking a token and then using it at /invite/:token, is what turns a theoretical injection into an accepted finding.
What happened, in plain words
Rocket.Chat is a chat program that a company or group can install on its own server, a bit like running your own Slack. To let new people in, it uses invite links. An existing member creates an invite for a room, and the link that comes out can be used to join that room. Depending on how the server is set up, the same link can also be used to create a brand new account on the server.
Each invite link carries a short secret code, called a token. Before showing the join or sign-up screen, the server checks whether the token is still valid. It does this through a small web address, an API route called validateInviteToken. An API is simply a way for one program to talk to another over the internet: you send a request to a web address, and you get an answer back, usually in a structured format rather than a web page. This particular route is open to anyone, even people who are not logged in, because the person clicking an invite link does not have an account yet.
That openness is where the problem starts. The route takes whatever the caller sends as the token and asks the database whether it matches an invite. The researcher found that the server never checks that the token is actually text. If you send a special instruction instead of text, the database treats it as a search pattern rather than a single code. The route then answers a simple yes or no: does any invite match this pattern? By asking that yes/no question over and over with slightly different patterns, an attacker can work out a real token one character at a time, without ever logging in. With a real token in hand, they can open the invite link and, on a server using the "Secret URL" registration method, register an account even when public registration is switched off.
Context
Rocket.Chat is a self-hosted team chat platform. "Self-hosted" means the organisation runs the software on its own computer (server) rather than using someone else's service. Like most such products it supports invite links: an existing user creates an invite for a room, and the resulting link can be used to join that room, or, depending on configuration, to register a new account on the server. The link carries a token, and the server exposes an API route, validateInviteToken, that lets a client check whether a token is still valid before showing the registration or join flow.
A token here is a short piece of text that acts as proof that you were invited. Think of a paper invitation with a unique reference number printed on it: the number itself is the proof, so whoever holds it can use it. A cookie is a similar idea in a browser, a small piece of data the browser stores and sends back to a site so the site can recognise you; a token in a link works the same way, except it travels in the web address instead of a cookie.
The route is deliberately unauthenticated (authRequired: false), because the person following an invite link does not have an account yet. "Unauthenticated" means the server does not ask who you are before answering. That design decision is the starting point of this report: an unauthenticated endpoint that takes attacker-controlled input and answers a yes/no question about it. An endpoint is just one specific web address on a server that does one specific job.
Setup
The report lists Rocket.Chat 3.9.4 as the affected release. The interesting precondition is a server configuration: the vulnerability matters most when the "Secret URL" registration method is enabled, because in that mode the invite token is what stands between an anonymous visitor and a new account. "Secret URL" means the server does not offer a public sign-up page; the only way in is a link that contains the secret. The report also states that authenticated users might gain unauthorised access to private chat rooms.
No special account is needed to send the request; the endpoint is reachable without authentication. The only tooling shown is curl. curl is a command-line program that sends web requests and prints the answer; you can think of it as a browser without a window, useful for talking to APIs directly.
Finding it
The researcher looked at the server-side handler for the route in app/api/server/v1/invites.js (lines 45 to 62 of the referenced commit) and found that the request body parameter is passed straight through to the validation function:
API.v1.addRoute('validateInviteToken', { authRequired: false }, {
post() {
const { token } = this.bodyParams;
if (!token) {
throw new Meteor.Error('error-invalid-token', 'The invite token is invalid.', { method: 'validateInviteToken', field: 'token' });
}
let valid = true;
try {
validateInviteToken(token);
} catch (e) {
valid = false;
}
return API.v1.success({ valid });
},
});
Line by line, in plain words:
API.v1.addRoute('validateInviteToken', { authRequired: false }, {registers a new API route namedvalidateInviteToken. TheauthRequired: falsepart says: do not require the caller to be logged in.post() {means this handler runs when someone sends a POST request, which is the kind of request used to send data to a server.const { token } = this.bodyParams;takes the value calledtokenout of the data the caller sent in the request body. The body is the part of the request that carries the data, here in JSON format, a simple text format for structured data.if (!token) {checks only that something was sent. It does not check what kind of thing it is.- The
throw new Meteor.Error(...)line produces an error saying the invite token is invalid when nothing was sent at all. let valid = true;starts by assuming the token is good.try { validateInviteToken(token); }calls the validation function with the value exactly as received.catch (e) { valid = false; }means: if validation throws an error, just record that the token is not valid.return API.v1.success({ valid });sends back a small JSON answer containing the true/false result.
The handler only checks that token is present, not that it is a string. A string is plain text, like abc123. The value is handed to validateInviteToken(token), which in turn calls Invites.findOneById(token) without further checks on the input data. findOneById is a database lookup that finds one record by its identifier. Because the body is JSON, token can be an object rather than a string, and an object is exactly what a MongoDB query operator needs. MongoDB is the database Rocket.Chat uses; a query operator is a special instruction inside a query that changes how the search works, for example "match by pattern" instead of "match exactly". A $regex value turns the lookup into a pattern match, and the boolean valid in the response tells the caller whether the pattern matched any invite document. A boolean is simply true or false. A regex (regular expression) is a pattern language for describing text, where .* means "any characters at all".
That is the flaw: a lookup that was meant to answer "is this exact token valid" now answers "does any invite token match this pattern", to anyone, without authentication. Security people call this kind of leak an oracle: a service that answers a yes/no question about secret data, which an attacker can ask repeatedly to learn the secret piece by piece. The vulnerability class here is improper authentication, meaning the server fails to properly establish who is allowed to do what.
Exploitation
Step 1: Confirm that the operator is accepted
The researcher sent a JSON body whose token is an object containing a $regex operator matching everything:
curl 'https://open.rocket.chat/api/v1/validateInviteToken'
-H "content-type: application/json"
-d '{ "token": { "$regex": ".*" } }'
Line by line:
curl 'https://open.rocket.chat/api/v1/validateInviteToken'sends a request to the validation route on a public Rocket.Chat server.-H "content-type: application/json"tells the server that the data being sent is in JSON format, so the server should read it as structured data.-d '{ "token": { "$regex": ".*" } }'is the data itself. Instead of a text token,tokenis an object with one key,$regex, whose value.*matches any text.
Here token is not a string but a query document. .* matches any token, so if a matching invite document exists the lookup succeeds and the route reports the token as valid.. That single response confirms that the input reaches the database query unmodified. In other words, the server took the attacker's instruction and used it as a search rule, which is the whole bug in one request.
Step 2: Leak a token character by character
A wildcard match only proves that some invite exists. To recover an actual token, the researcher used the boolean oracle as a prefix test. A prefix is the beginning of a piece of text: for hello, the prefixes are h, he, hel, and so on. The report describes a strategy for leaking a 6-character token made of case-sensitive letters and numbers. Case-sensitive means a and A count as different characters. By anchoring the regex at the start of the string and fixing one character at a time, each request answers whether any invite token begins with that prefix. Anchoring means forcing the pattern to match from the very first character, which is what the ^ symbol does.
- Send
^a.*,^b.*, and so on, and keep the prefix for whichvalidistrue. - Extend the prefix one character at a time, testing each candidate against the alphabet of letters and digits.
- After six successful rounds the full token is known.
Why this works: each answer is one bit of information, true or false, but it narrows the possibilities enormously. Instead of guessing all 6-character combinations, the attacker only has to try the roughly 62 possible characters (letters upper and lower case plus digits) at each of six positions.
The report notes one complication: expired invite tokens can mask other tokens, because MongoDB returns only one document, sorted by order of insertion. A document here is one record in the database, in this case one invite. If the first matching document is an expired invite, the boolean result reflects that document rather than a live one, so a prefix that matches only expired invites can mislead the search. The researcher's strategy is to work with the prefix oracle and the boolean result rather than relying on a single wildcard match.
Step 3: Use the leaked token
With a valid token in hand, the attacker browses to /invite/:token. In that address, :token is a placeholder for the real token that was leaked. From there the normal invite flow applies: register a new account, which, on a server using the "Secret URL" registration method, is otherwise closed to the public, and land in the channel the invite points to. The report adds that the process can be repeated to join more rooms whose invites have not expired.
Root cause
The handler trusts the shape of the request body. this.bodyParams.token is used as-is, and the only guard is a truthiness check, so a JSON object passes where a string was intended. Downstream, Invites.findOneById(token) receives that object and MongoDB interprets $regex as a query operator. The route's own error handling does not help: it catches exceptions from validateInviteToken and converts them into valid: false, so a malformed or unexpected input simply looks like an invalid token rather than being rejected as bad input.
The design also amplifies the bug. The endpoint is unauthenticated by necessity, and it returns a boolean derived from a database lookup, which is a classic oracle: each request leaks one bit about data the caller should not be able to query.
Impact
Unauthenticated attackers can leak invite links and use them to register new accounts even when public registration is disabled, provided the server uses the "Secret URL" registration method. Authenticated users can also gain unauthorised access to private chat rooms through non-expired invites. Registration applies when the server uses the "Secret URL" registration method, and room access requires a non-expired invite.
Fix
The suggested mitigation in the report is to validate that the user input is a String. Rejecting any non-string token before it reaches validateInviteToken removes the operator injection at the source, since a string cannot carry a $regex key. The report does not describe a patch that was applied, so the concrete change made by the maintainers is not stated here.
Variants to test
- Other operators on the same parameter. If
$regexis accepted, try$ne,$gt,$inor$existsagainst the sametokenfield. These are other MongoDB query operators with different meanings, such as "not equal" or "exists". A positive result is a response that differs from the invalid-token path for a value that is not a real token. - Other unauthenticated lookup routes. Any route with
authRequired: falsethat takes an identifier frombodyParamsor query parameters and passes it to a database lookup is a candidate. A positive result is a boolean or object response that changes when the value is replaced by an operator object. - Other boolean oracles. Routes that answer "does this exist" or "is this valid" without authentication can be turned into extraction oracles the same way. A positive result is a response that lets you narrow a secret one character at a time.
- Expired versus live documents. Where the lookup returns a single document, test whether expired or older records mask live ones, as the report describes. A positive result is a prefix that matches but does not lead to a usable token, which tells you the ordering of documents matters.
Hunting notes
The pattern to look for during recon is an unauthenticated endpoint whose name suggests validation or existence checking (validate*, check*, exists*) and whose response is a boolean. Recon means the early stage of looking around a target to see what it is made of. Source code is the fastest way to confirm it: find the route definition, check authRequired, and follow the parameter into the database call. If the parameter is used without a type check, the endpoint is worth a request.
The report's impact argument rests on two concrete consequences rather than on the oracle alone: account registration on a server where public registration is disabled, and access to private channels. Demonstrating either end to end, by leaking a token and then using it at /invite/:token, is what turns a theoretical injection into an accepted finding.
Glossary
- API: a way for one program to talk to another over the internet, sending requests to specific web addresses and getting structured answers back.
- API route: one specific web address on a server that performs one specific job.
- Authentication: the process of proving who you are, usually by logging in.
- Unauthenticated: reachable without logging in or proving identity.
- Endpoint: another word for an API route, a specific address that handles a specific request.
- Token: a short piece of secret text that acts as proof, here the code inside an invite link.
- Cookie: a small piece of data a browser stores and sends back to a site so the site can recognise the visitor.
- JSON: a simple text format for structured data, built from keys and values.
- Request body: the part of a web request that carries the data being sent.
- POST request: a web request used to send data to a server.
- curl: a command-line program that sends web requests and prints the responses.
- String: plain text, such as
abc123. - Boolean: a value that is either true or false.
- MongoDB: the database software Rocket.Chat uses to store its data.
- Document: one record in a MongoDB database, here one invite.
- Query operator: a special instruction inside a database query that changes how the search works, such as matching by pattern.
$regex: a MongoDB query operator that matches text against a pattern.- Regex (regular expression): a pattern language for describing text;
.*means any characters at all. - Prefix: the beginning of a piece of text.
- Anchoring: forcing a pattern to match from the first character, done with
^. - Case-sensitive: treating upper-case and lower-case letters as different characters.
- Oracle: a service that answers yes/no questions about secret data, which can be asked repeatedly to learn the secret piece by piece.
- Improper authentication: a vulnerability class where the server fails to properly establish who is allowed to do what.
- Operator injection: slipping a database query operator into input that was meant to be plain text.
- Wildcard: a pattern that matches anything, such as
.*. - Recon: the early stage of looking around a target to understand what it is made of.
- Self-hosted: software run on an organisation's own server rather than someone else's service.
- Secret URL registration: a sign-up mode where there is no public registration page and the only way in is a link containing a secret.
- Mitigation: a change that removes or reduces a vulnerability.