<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Chinomnso Awazie</title>
    <description>The latest articles on DEV Community by Chinomnso Awazie (@coawazie).</description>
    <link>https://dev.to/coawazie</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F670399%2Fbaf93b4a-bd00-4914-b630-ddfe516b32fb.jpeg</url>
      <title>DEV Community: Chinomnso Awazie</title>
      <link>https://dev.to/coawazie</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/coawazie"/>
    <language>en</language>
    <item>
      <title>Firebase Email Enumeration Rules: A Workaround For fetchSignInMethodsForEmail</title>
      <dc:creator>Chinomnso Awazie</dc:creator>
      <pubDate>Sun, 04 Feb 2024 08:37:24 +0000</pubDate>
      <link>https://dev.to/coawazie/firebase-email-enumeration-rules-a-workaround-for-fetchsigninmethodsforemail-1d51</link>
      <guid>https://dev.to/coawazie/firebase-email-enumeration-rules-a-workaround-for-fetchsigninmethodsforemail-1d51</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2u4f65nz6ritjzvj8n5u.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2u4f65nz6ritjzvj8n5u.jpeg" alt="Email Protection" width="800" height="457"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you manage users with Firebase Auth, this article will help you understand recent Google security implementation aimed at improving security of your users' identity information. You probably &lt;em&gt;noticed&lt;/em&gt; that &lt;code&gt;fetchSignInMethodsForEmail&lt;/code&gt; started failing for &lt;strong&gt;&lt;em&gt;new&lt;/em&gt;&lt;/strong&gt; projects created after September 15, 2023. That is &lt;strong&gt;NOT&lt;/strong&gt; a bug! Also, if you use Firebase Auth for users management, you probably got a nice email from Google letting you know that new projects from the date aforementioned now have e_mail enumeration protection enabled by default_. What does this mean? Why? What are the consequences to be expected? Speculations on possible direction Google is headed?&lt;/p&gt;

&lt;p&gt;First, let us clarify a few things.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is email enumeration?
&lt;/h3&gt;

&lt;p&gt;Google Cloud documentation has a clean definition of this, so let me not reinvent the wheel here. In this &lt;a href="https://cloud.google.com/identity-platform/docs/admin/email-enumeration-protection"&gt;article&lt;/a&gt; by Google Cloud, there is this concise definition of email enumeration:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Email enumeration is a type of brute-force attack in which a malicious actor attempts to guess or confirm users in a system by passing an email address to the API and checking the response.&lt;/em&gt;&amp;gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In the case of case of Firebase Auth, the attacker calls the Identity Platform API and tries to guess the existence or not of a particular user on the target project. There are a few ways this call can be made, eg via a REST API like &lt;a href="https://cloud.google.com/identity-platform/docs/reference/rest/v1/accounts/createAuthUri"&gt;createAuthUri&lt;/a&gt;, via a client SDK, etc. Basically, anyone who can access your &lt;code&gt;https://www.googleapis.com/identitytoolkit&lt;/code&gt; or &lt;a href="https://cloud.google.com/gcp?hl=en"&gt;https://cloud.google.com/gcp&lt;/a&gt; technically can enumerate users on the chosen project if they know their emails. A good Auth quota limit means emails obtained from a security breach, can be looped through to determine which emails are being used in that project. A more sinister case will be a bad actor, eg a scammer, a bad state actor, etc, who somehow gets access (eg API key, reverse-engineer an app to operated under the radar of that app's authentication, etc) being able to confirm the existence or otherwise of an account under the email of their victim. Zoom out a bit, and you realize how dangerous this is: in some places, &lt;em&gt;belonging&lt;/em&gt; to an organization, group, using certain products or services, etc, can immediately spell grave threat to the life and safety of the individual if found by the government. I can already think of a few ways this would even get worse from there: confirm 'A' belongs to an organization, and then start fishing around 'A's circle to see who else is in that organization with them. I will not go further down that rabbit hole, but you get the point. And we are just painting the picture of one scenario!&lt;/p&gt;

&lt;p&gt;There are quite a few ways to hit the &lt;code&gt;EMAIL_NOT_FOUD&lt;/code&gt; error on GCP, or its lil nephew &lt;code&gt;auth/user-not-found&lt;/code&gt;. What makes this a bit problematic is that you don't need a OAuth credential to get these responses, just the email, and an app with Firebase Auth properly initialized, or API key in the case of a REST API call.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is the problem?
&lt;/h3&gt;

&lt;p&gt;Abuse of a feature suggests the existence of a legitimate use. This also means that &lt;strong&gt;a lot&lt;/strong&gt; of apps built their auth flow around this feature that enables them to first confirm the existence of an email on their platform, or lack of it. Typical scenario is most user onboarding process where you want to confirm there is no existing account with the email supplied by the new user trying to sign up, or you want to be sure someone trying to request a password reset even exists on your platform.&lt;/p&gt;

&lt;p&gt;Now, here is the problem in my opinion: in &lt;strong&gt;&lt;em&gt;a new user scenario&lt;/em&gt;&lt;/strong&gt;, if that user comes in authenticated from a social auth provider, eg Google, Facebook, Apple, etc, trying to sign them in &lt;strong&gt;&lt;em&gt;will create a new user in Firebase with their credentials!&lt;/em&gt;&lt;/strong&gt; The cherry on top? The only method that has separate login and signup functions is the "email and password". Take a cursory look at the documentation around the &lt;a href="https://firebase.google.com/docs/reference/node/firebase.auth.Auth#methods"&gt;methods&lt;/a&gt; available for &lt;code&gt;Auth&lt;/code&gt; service instance for an app. There is only but one "creatUser…" method, and that is &lt;code&gt;createUserWithEmailAndPassword&lt;/code&gt;. If you are coming from an &lt;a href="https://firebase.google.com/docs/reference/node/firebase.auth.AuthProvider"&gt;auth provider&lt;/a&gt;, you just have to sign in, and if you do, and no user existed, a new one is created. Then there is the the &lt;a href="https://firebase.google.com/docs/reference/kotlin/com/google/firebase/auth/AdditionalUserInfo#isNewUser()"&gt;isNewUser&lt;/a&gt; boolean that I have filed under "blink and you miss it": you get it only once. Interpretation: if for any reason a new user onboarding is incomplete, you will have to find other indirect ways to deduce they are new users on &lt;em&gt;subsequent logins&lt;/em&gt;. Do you really want to expose too much user metadata to the FE in an attempt to maybe try figuring out the user age via their creation time? So how do we circumvent or at least mitigate email enumeration risks and still have a functionality that mimics &lt;a href="https://firebase.google.com/docs/reference/node/firebase.auth.Auth#fetchsigninmethodsforemail"&gt;fetchSignInMethodsForEmail&lt;/a&gt;? That is the point of this article.&lt;/p&gt;

&lt;h3&gt;
  
  
  My Solution
&lt;/h3&gt;

&lt;p&gt;My suggested solution in one sentence: lean into Firebase Function. A function endpoint gives you some superpowers within your Firebase project, &lt;em&gt;&lt;strong&gt;and&lt;/strong&gt;&lt;/em&gt; you can still pile on other security measures. My go to defence mechanisms are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Enable &lt;a href="https://firebase.google.com/docs/app-check"&gt;AppCheck&lt;/a&gt; on your project and use it to protect your APIs.&lt;/li&gt;
&lt;li&gt;Implement strong encryption in transit. This is a good playground for security easter eggs: spice things up with encrypted stuff that should respond in a specific way in line with your business logic, a deviation of which will indicate malicious attempt.&lt;/li&gt;
&lt;li&gt;Use header information to filter for allowed origins at your API.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A sample code for the API could look like this:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;The trick here is to use &lt;a href="https://firebase.google.com/docs/reference/admin/node/firebase-admin.auth.baseauth.md#baseauthgetuserbyemail"&gt;getUserByEmail&lt;/a&gt; method from the function API. This method is available with the elevated privileges of the admin . You can even mess with &lt;a href="https://firebase.google.com/docs/reference/admin/node/firebase-admin.auth.baseauth.md#baseauthgetuserbyphonenumber"&gt;getUserByPhoneNumber&lt;/a&gt; if you so wish.&lt;/p&gt;

&lt;p&gt;In my tests, with &lt;a href="https://cloud.google.com/identity-platform/docs/admin/email-enumeration-protection"&gt;email enumeration&lt;/a&gt; turned on,&lt;a href="https://firebase.google.com/docs/reference/node/firebase.auth.Auth#fetchsigninmethodsforemail"&gt;fetchSignInMethodsForEmail&lt;/a&gt; fails at the client, but the API methods worked like charm.&lt;/p&gt;

&lt;p&gt;If you liked this article, bookmark it for later, and share to help others.&lt;/p&gt;

</description>
      <category>reactnative</category>
      <category>react</category>
      <category>webdev</category>
      <category>firebase</category>
    </item>
  </channel>
</rss>
