Tchap est le nomb de la nouvelle messagerie sécurisée développée par les services de l'Etat, a société…
The Tchap messaging app's registration process validated email addresses using a flawed parser that accepted malformed addresses, allowing the researcher to register with an @elysee.fr domain without owning such an email. This gave access to public rooms as an Elysée employee.
medium.com
Published on medium.com
On Wednesday 17th April 2019, the French Government launched a messaging application called “Tchap”. The day of the launch a lot of articles appeared:
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
On Wednesday 17 April 2019 the French Government launched a messaging application called Tchap, and the launch was covered by a wave of articles describing it as a messaging app more secure than Telegram and as a replacement for Telegram and WhatsApp. The author had previously worked on Kimbho, an Indian app presented as the new WhatsApp, which did not end well, and decided to spend one hour looking at Tchap.
Tchap is an Android app, distributed on the PlayStore, and it is a fork of the Riot Android app, itself a messaging client made by Matrix. The app is open source, published in the dinsic-pim/tchap-android repository. Registration is restricted: to create an account you need a @gouv.fr or @elysee.fr email address. That restriction became the first goal: create an account without such an address.
Setup
The app was downloaded from the PlayStore, current version 1.0.22_a. The approach was the usual one: first use the app as a normal user to see the available functionalities, then decompile it and do static analysis, then move to dynamic analysis.
The app implements certificate pinning. The author disabled it with Frida. During the registration process the app requests a token.

Depending on the email address entered, the app uses the "correct" id_server. All the available servers are defined in the AndroidManifest.xml:
- matrix.agent.dev-durable.tchap.gouv.fr
- matrix.agent.dinum.tchap.gouv.fr
- matrix.agent.intradef.tchap.gouv.fr
- matrix.agent.diplomatie.tchap.gouv.fr
- matrix.agent.justice.tchap.gouv.fr
- matrix.agent.agriculture.tchap.gouv.fr
- matrix.agent.interieur.tchap.gouv.fr
- matrix.agent.social.tchap.gouv.fr
- matrix.agent.education.tchap.gouv.fr
- matrix.agent.finances.tchap.gouv.fr
- matrix.agent.ssi.tchap.gouv.fr
- matrix.agent.pm.tchap.gouv.fr
- matrix.agent.elysee.tchap.gouv.fr
- matrix.agent.culture.tchap.gouv.fr
- matrix.agent.tchap.gouv.fr
Finding it
The static analysis quickly showed that the app is open source and a fork of Riot, so the registration flow could be understood from the code and from the traffic. The interesting part is the token request made during registration: the app picks an id_server according to the email address, and the server is then asked to send a validation email.
The author set id_server to matrix.agent.elysee.tchap.gouv.fr. The Elysée is the French presidential palace, so choosing this server implied that an @elysee.fr address was expected. The question was whether the server actually validated the address it was given, or only parsed it.
Exploitation
Step 1: a first malformed address
In the requestToken request the author modified the email to [redacted]@elysee.fr. No validation email arrived in the inbox.
Step 2: guessing a known address
The hypothesis was that the server was waiting for a known @elysee.fr email address. The author did a Google search for "email @elysee.fr".

Step 3: a second malformed address
A second attempt was made, again in the requestToken request, with the email modified to [redacted]@[redacted]. This time a validation email from Tchap arrived and the account was validated.

Step 4: logged in as an Elysée employee
The author was logged in as an Elysée employee and had access to the public rooms.


Among the public rooms, an employee of the Ministry of Agriculture had created a "Yellow room" for "people who loves the yellow".



Root cause
The flaw is in the validation of email addresses by Sydent, the Matrix reference identity server. The parseaddr method from the Python email.utils module is RFC compliant, but it does not do the job correctly here: it turns a malformed address into a valid one. The fix made by Matrix requires that parsed mail addresses match the raw input.
An issue on the Python bug tracker about email.utils.parseaddr mistakenly parsing an email had been open since 2018-07-19.
Impact
The author was able to create an account and log in as an Elysée employee, and had access to the public rooms of Tchap. The report does not describe access to private rooms or to other users' messages. In this case the author guessed that a known @elysee.fr address was needed and found one with a Google search.
Fix
Matrix fixed the issue on the Tchap backend the same day, and published a blog post explaining the security issue in detail. The patch requires that parsed mail addresses match the raw input. An issue on the Python bug tracker about parseaddr had been open since 2018-07-19.
Timeline
- 9:00 am: beginning of the analysis
- 10:15 am: the author is in
- 10:35 am: phone calls to contact the French government employee in charge of Tchap
- 11:19 am: details of the vulnerability disclosed to the Matrix security team
- 2:00 pm: Matrix fixed the issue on the Tchap backend
- 5:42 pm: phone call with French government officials
- 7:48 pm: Matrix published a blog post explaining the security issue in detail
Variants to test
- Registration and invitation flows that take an email address and pick a backend by domain: submit an address of the form
[redacted]@known-user@target-domainand see whether a validation email is sent to the attacker. A positive result is a validation email arriving at the attacker's mailbox for an account on the target domain. - Any endpoint that parses an address with a permissive library and then compares only the domain: check whether the comparison is done on the parsed value or on the raw input. A positive result is a domain check that passes while the raw string contains a second
@. - Identity servers and SSO token endpoints that accept an email or identifier and return a token: try malformed inputs with extra
@, comments and quoted local parts, and watch for a token being issued. A positive result is a token issued for an identifier the attacker does not own. - Mobile apps with certificate pinning: disable pinning with Frida and inspect the registration requests to find parameters such as
id_serverthat the client chooses. A positive result is a server-side trust in a client-supplied routing parameter that can be pointed at a different backend.
What happened, in plain words
On Wednesday 17 April 2019 the French Government launched a messaging application called Tchap. The launch was covered by a wave of articles describing it as a messaging app more secure than Telegram and as a replacement for Telegram and WhatsApp.
The author had previously worked on Kimbho, an Indian app presented as the new WhatsApp, which did not end well, and decided to spend one hour looking at Tchap. The goal was modest: see whether something could be found in about an hour.
Tchap is an Android app, distributed on the PlayStore, and it is a fork of the Riot Android app, itself a messaging client made by Matrix. A fork means a copy of an existing program that someone takes and modifies for their own use. The app is open source, published in the dinsic-pim/tchap-android repository, so its code can be read by anyone.
Registration is restricted: to create an account you need a @gouv.fr or @elysee.fr email address. That restriction became the first goal: create an account without such an address. In the end the author managed to register and log in as an Elysée employee, and had access to the public rooms of Tchap.
The cause was a small mistake in how a server component read email addresses. A function that was supposed to check an address turned a malformed one into a valid one, so a check on the domain passed even though the address belonged to the attacker. Matrix fixed the issue on the Tchap backend the same day.
Setup
The app was downloaded from the PlayStore, current version 1.0.22_a. The approach was the usual one for this kind of work, in three stages:
- First use the app as a normal user to see the available functionalities.
- Then decompile it and do static analysis. Decompiling means turning the installed app back into readable code; static analysis means reading that code without running it.
- Then move to dynamic analysis, which means running the app and watching what it sends over the network.
The app implements certificate pinning. When an app talks to a server over HTTPS, the server presents a certificate to prove its identity, and normally the app accepts any certificate signed by a trusted authority. Certificate pinning means the app only accepts one specific certificate, so that even someone who can intercept the traffic cannot present a fake certificate. The author disabled it with Frida. Frida is a tool that attaches to a running app and changes its behaviour in memory, so the pinning check can be switched off without modifying the app on disk.
During the registration process the app requests a token. A token here is a short piece of data that proves something, in this case that the person registering really controls the email address they typed. The server sends it by email.

Depending on the email address entered, the app uses the "correct" id_server. An id_server is an identity server: a service that keeps the link between an account and the email address behind it, and that sends the validation emails. The app chooses which one to talk to based on the domain of the address, so an address ending in one ministry's domain goes to that ministry's server. All the available servers are defined in the AndroidManifest.xml, a file inside every Android app that declares its components and settings:
- matrix.agent.dev-durable.tchap.gouv.fr
- matrix.agent.dinum.tchap.gouv.fr
- matrix.agent.intradef.tchap.gouv.fr
- matrix.agent.diplomatie.tchap.gouv.fr
- matrix.agent.justice.tchap.gouv.fr
- matrix.agent.agriculture.tchap.gouv.fr
- matrix.agent.interieur.tchap.gouv.fr
- matrix.agent.social.tchap.gouv.fr
- matrix.agent.education.tchap.gouv.fr
- matrix.agent.finances.tchap.gouv.fr
- matrix.agent.ssi.tchap.gouv.fr
- matrix.agent.pm.tchap.gouv.fr
- matrix.agent.elysee.tchap.gouv.fr
- matrix.agent.culture.tchap.gouv.fr
- matrix.agent.tchap.gouv.fr
Each line is a hostname, that is a name that identifies a machine on the internet, the same way a postal address identifies a building. The names follow a pattern: matrix.agent. followed by the name of a French institution, followed by tchap.gouv.fr. gouv.fr is the domain used by the French state, so these are all government machines. The list covers institutions such as the defence ministry, the interior ministry, the justice ministry, the Elysée and so on.
Finding it
The static analysis quickly showed that the app is open source and a fork of Riot, so the registration flow could be understood from the code and from the traffic. Reading the code tells you which requests the app can send and with which parameters; watching the traffic tells you which ones it actually sends and with which values.
The interesting part is the token request made during registration: the app picks an id_server according to the email address, and the server is then asked to send a validation email. The question that mattered was simple. Does the server actually validate the address it is given, or does it only parse it? Parsing means splitting a piece of text into its parts, here the local part before the @ and the domain after it. Validating means checking that the address is acceptable, for example that its domain is one the server is responsible for. A server that parses and then checks only the domain can be fooled if the parsing is too permissive.
The author set id_server to matrix.agent.elysee.tchap.gouv.fr. The Elysée is the French presidential palace, so choosing this server implied that an @elysee.fr address was expected. The id_server value is chosen by the app, which means it is sent by the client, the program running on the user's phone. Anything the client sends can be changed by the person holding the phone, so this value could be edited before the request left the device.
Exploitation
Step 1: a first malformed address
In the requestToken request the author modified the email to [redacted]@elysee.fr. No validation email arrived in the inbox.
Read the address from left to right. [redacted] is a complete, real address on a mail service the author controls. Then comes a second @, followed by elysee.fr. A normal email address has exactly one @, so this string is not a valid address. It did not work: no email arrived.
Step 2: guessing a known address
The hypothesis was that the server was waiting for a known @elysee.fr email address. Perhaps the server did not accept any address on the domain, but only addresses that already existed in some list. The author did a Google search for "email @elysee.fr".

The screenshot shows the search results, which is how a real address on the Elysée domain was found. This is worth pausing on: the missing ingredient was not a secret. It was a piece of information anyone can find with a search engine.
Step 3: a second malformed address
A second attempt was made, again in the requestToken request, with the email modified to [redacted]@[redacted]. This time a validation email from Tchap arrived and the account was validated.
[redacted]@[redacted]
Again, read it in pieces. The first part is the author's own address, [redacted]. Then a second @, then presidence, then a third @, then elysee.fr. The middle piece, presidence, is the part of a real Elysée address that was found in the previous step. The string as a whole is not a valid address, but it contains a valid one. The validation email therefore went to the author, and the account was confirmed.

The screenshot shows the validation email received from Tchap, the proof that the trick worked.
Step 4: logged in as an Elysée employee
The author was logged in as an Elysée employee and had access to the public rooms.


The screenshots show the app after login, with the account presented as belonging to an Elysée employee and the list of public rooms available. A room in Tchap is a conversation, the same way a group chat is a conversation in any messaging app. Public rooms are the ones anyone in the app can join, as opposed to private ones.
Among the public rooms, an employee of the Ministry of Agriculture had created a "Yellow room" for "people who loves the yellow".



Root cause
The flaw is in the validation of email addresses by Sydent, the Matrix reference identity server, which is what the id_server endpoints run. "Reference" here means the official implementation that others copy or deploy.
The parseaddr method from the Python email.utils module is RFC compliant, but it does not do the job correctly here: it turns a malformed address into a valid one by removing anything after and including the second @. An RFC is a document that describes how internet standards work; being RFC compliant means following the written rule for the format. The problem is that the rule is loose enough to allow strange inputs, and the function resolves the ambiguity in a way that suits an attacker.
The parsed address therefore matched the domain the server was checking, while the raw input was an address the attacker controlled. The fix made by Matrix requires that parsed mail addresses match the raw input. In plain terms: if cleaning up the address changes it, reject it.
An issue on the Python bug tracker about email.utils.parseaddr mistakenly parsing an email had been open since 2018-07-19. A bug tracker is a public list where problems in a piece of software are reported and discussed. An issue on the Python bug tracker about parseaddr had been open since 2018-07-19.
Impact
The author was able to create an account and log in as an Elysée employee, and had access to the public rooms of Tchap. The report does not describe access to private rooms or to other users' messages. In this case the author guessed that a known @elysee.fr address was needed and found one with a Google search.
Fix
Matrix fixed the issue on the Tchap backend the same day, and published a blog post explaining the security issue in detail. The patch requires that parsed mail addresses match the raw input.
Timeline
- 9:00 am: beginning of the analysis
- 10:15 am: the author is in
- 10:35 am: phone calls to contact the French government employee in charge of Tchap
- 11:19 am: details of the vulnerability disclosed to the Matrix security team
- 2:00 pm: Matrix fixed the issue on the Tchap backend
- 5:42 pm: phone call with French government officials
- 7:48 pm: Matrix published a blog post explaining the security issue in detail
The order is worth noticing. The author found the problem at 10:15, started trying to reach the people responsible at 10:35, told the security team at 11:19, and the fix was live at 2:00 pm. Disclosure here means telling the people who can fix the problem, not publishing it to the world.
Variants to test
- Registration and invitation flows that take an email address and pick a backend by domain: submit an address of the form
[redacted]@known-user@target-domainand see whether a validation email is sent to the attacker. A positive result is a validation email arriving at the attacker's mailbox for an account on the target domain. - Any endpoint that parses an address with a permissive library and then compares only the domain: check whether the comparison is done on the parsed value or on the raw input. A positive result is a domain check that passes while the raw string contains a second
@. - Identity servers and SSO token endpoints that accept an email or identifier and return a token: try malformed inputs with extra
@, comments and quoted local parts, and watch for a token being issued. A positive result is a token issued for an identifier the attacker does not own. - Mobile apps with certificate pinning: disable pinning with Frida and inspect the registration requests to find parameters such as
id_serverthat the client chooses. A positive result is a server-side trust in a client-supplied routing parameter that can be pointed at a different backend.
An endpoint is a specific address on a server where a particular request can be sent, like a counter in a building where one specific service is handled. SSO means single sign-on, a system where one login gives access to several services. A quoted local part is a way of writing the part before the @ in an email address with quotation marks around it, which some parsers treat differently. A routing parameter is a value in a request that tells the server which internal service should handle it.
Glossary
- Android app: a program that runs on phones using Google's Android operating system.
- AndroidManifest.xml: a file inside every Android app that declares its components, permissions and settings.
- API: a defined way for one program to ask another program for something, like a service counter with a fixed list of requests it accepts.
- Backend: the part of a system that runs on the server, as opposed to the client that runs on the user's device.
- Certificate pinning: a setting where an app accepts only one specific certificate for a server, instead of any certificate signed by a trusted authority.
- Client: the program running on the user's own device, which sends requests to a server.
- Decompile: turn an installed program back into readable source code.
- Disclosure: telling the people responsible about a security problem, so that it can be fixed.
- Domain: the part of an address after the
@, or the part of a hostname after the first dot, that identifies an organisation, such aselysee.fr. - Dynamic analysis: running a program and observing what it does, for example the network traffic it sends.
- Endpoint: a specific address on a server where a particular kind of request is handled.
- Fork: a copy of an existing program that someone takes and modifies for their own use.
- Frida: a tool that attaches to a running app and changes its behaviour in memory.
- Hostname: a name that identifies a machine on the internet, such as
matrix.agent.elysee.tchap.gouv.fr. - HTTPS: the encrypted version of the protocol browsers and apps use to talk to servers.
- id_server: an identity server, a service that keeps the link between an account and the email address behind it and sends validation emails.
- Local part: the part of an email address before the
@. - Matrix: the organisation and protocol behind the Riot messaging app, on which Tchap is based.
- Open source: software whose code is published and can be read by anyone.
- Parameter: a named value sent with a request, such as
id_serveroremail. - Parse: split a piece of text into its parts according to a format.
- Patch: a change to software that fixes a problem.
- PlayStore: Google's official store for downloading Android apps.
- Public room: a conversation in Tchap that anyone in the app can join, as opposed to a private one.
- Quoted local part: a way of writing the part of an email address before the
@with quotation marks around it. - requestToken: the registration request in which the app asks the server to send a validation token by email.
- RFC: a document that describes how an internet standard works; being RFC compliant means following that written rule.
- Riot: the Android messaging app made by Matrix, of which Tchap is a fork.
- Routing parameter: a value in a request that tells the server which internal service should handle it.
- SSO: single sign-on, a system where one login gives access to several services.
- Static analysis: reading a program's code without running it.
- Sydent: the Matrix reference identity server, the software the id_server endpoints run.
- Token: a short piece of data that proves something, here that the person registering controls the email address they typed.
- Validation email: an email containing a token, sent to confirm that an address really belongs to the person registering.
- Vulnerability: a weakness in software that someone can use to make it behave in a way its authors did not intend.