The eMudhra certificate flaw affecting Flutter

The eMudhra certificate flaw affecting Flutter

Table of Contents

I don’t know if you’ve seen all the commotion surrounding eMudhra’s compromised certificates. In this article, I’m going to explain in simple terms what happened, which versions of Dart, Flutter, and Firebase are affected and, above all, whether you should hurry to publish an update for your Flutter app that includes the security patch.

Info

📽 Video version available on YouTube

How TLS certificate validation protects your apps

Let’s try to understand, in broad terms, what happened. I won’t go into overly specific technical details, because the goal of this article is to give you a general idea of the problem and help you understand how it could affect your Flutter apps.

When an operating system, app, or browser wants to connect to a server, it needs to know that the server it is talking to really is who it claims to be. For example, when you want to download Flutter and go to flutter.dev, your web browser needs to know that it is the legitimate website. Otherwise, an attacker could impersonate it and, when you download the Flutter binary to use it, you could actually be downloading malware.

To do this, the client looks at the web service’s certificate and follows its certificate chain until it finds a certificate it trusts. If it finds one, it will trust that web service. If it doesn’t, it will terminate the connection because someone might be trying to intercept it. To determine who can be trusted, operating systems and browsers have a list of root certificates that belong to trusted certificate authorities. And what are these certificate authorities? They are companies that issue certificates and that Google, Apple, Mozilla, and other providers have decided to include in their trust lists.

So, when you visit flutter.dev, your browser looks at its certificate and checks that it is part of a chain that ends in one of the root certificates it trusts. These lists of trusted certificates can be part of the operating system itself, although a browser or app can also include its own. Keep this in mind, because it is relevant to understanding what happened with Flutter.

How the eMudhra certificate compromise affects Flutter

Now that we have a general idea of how communication between an app or browser and an internet service is protected, let’s look at exactly what happened with eMudhra and how it relates to Flutter.

eMudhra is a certificate authority. Or rather, it used to be part of the public TLS certificate ecosystem, because after this incident it announced that it would leave that business. Among other things, it was responsible for generating keys used to sign certificates. What happened is that several of those keys were found to have been generated without enough randomness, making them predictable. This allowed an independent researcher to recover those keys using only public information contained in the certificates themselves. And this is important: to do this, the researcher did not have to hack eMudhra’s systems, steal information, or access its infrastructure. They were simply able to recover those private keys, which could then be used to impersonate a legitimate web service and carry out what is known as a man-in-the-middle attack. In other words, an attacker could position themselves between the client and the server to read or alter the data. In that case, the client would not block the connection because the fake certificate would appear legitimate.

After discovering the problem, the researcher notified eMudhra and the major players in the industry so that they would stop trusting the affected certificates. That is why, in the following days, we saw security updates and emergency blocks in browsers and operating systems. Apps that used the system’s certificate validation were protected automatically… but not every app checks that information. And this is where Dart and Flutter come in.

Specifically, on Android and Windows, the dart:io library used its own system to validate certificates and did not check the operating system’s list of blocked certificates. So, even if the operating system had stopped trusting the compromised certificates, an app compiled with one of the affected versions could still accept them as valid.

The solution was to publish patched versions of Dart and Flutter that explicitly block these certificates. In addition, on Android 14 and later, Dart now obtains root certificates from an updatable system component, which will help respond to similar situations in the future. But because these changes are part of the app binary, updating the operating system is not enough. The app must be rebuilt and a new version published.

Affected Dart and Flutter versions and security patches

On the stable channel, the affected versions are those earlier than Dart 3.13.7 and Flutter 3.47.8. In other words, Dart 3.13.7 and Flutter 3.47.8 already include the security patch.

This means that if the Android or Windows app you currently have published was compiled with a Flutter version earlier than 3.47.8, it could still accept the affected certificates. On Linux, the problem may also exist if the system or container does not have an up-to-date certificate list. If the app is written only in Dart, it must use version 3.13.7 or later.

If this applies to you, I recommend updating as soon as possible. To do so, update the version of Flutter you use to compile your app, rebuild it, and distribute it through the app stores again. If your app handles particularly sensitive data, it would also be appropriate to send a notice to your users asking them to download the update as soon as possible.

In my opinion, one of our responsibilities as developers is to distribute secure applications to our users, and that includes responding quickly to security issues like this one. In this case, the solution is as simple as updating Flutter, rebuilding the app, and releasing a new version. That would be enough to fix this issue in Dart and Flutter, but wait, because there may still be more things you need to update.

The Firebase and Cloud Firestore security update

If your app uses Firebase, specifically Cloud Firestore on iOS, macOS, or Windows, it may also have been affected. The cloud_firestore plugin used its own list of trusted certificates, which meant that an old version could continue accepting eMudhra certificates even after the operating system had blocked them. To be clear, the Cloud Firestore backend was not affected. The problem was in the plugin included in the app. If this applies to you, you should update cloud_firestore to a version that includes the security patch, rebuild the application, and publish it again.

For this to happen, an attacker would need to carry out a somewhat sophisticated attack in which they impersonate Firebase. It is not something that is extremely easy to do or that happens every day, but it is certainly possible and something we need to consider so that we can apply the corresponding patch.

By the way, other services could also be affected. If that were the case, the provider should have sent you an email or notification explaining the problem and the proposed solution so that you can apply the necessary fixes.

How to protect your Flutter apps from the eMudhra vulnerability

In this article, I have tried to explain the entire eMudhra problem in simple terms and how it can affect the Flutter apps we already have published. If you are distributing an app to end users, you should check whether it was compiled with an affected version of Flutter or uses any of the affected SDKs and, if so, apply the patches and publish a new version.

I hope I have explained it in a simple way that everyone can understand. Thank you for reading this article all the way to the end.

See you next time!