Skip to content

Fix issue where accounts:lookup is case-sensitive for emails - #8351

Merged
joehan merged 1 commit into
masterfrom
aalej-auth-celookup
Mar 21, 2025
Merged

joehan merged 1 commit into
masterfrom
aalej-auth-celookup

Conversation

@aalej

@aalej aalej commented Mar 21, 2025 •

Copy link
Copy Markdown
Contributor

Description

Fixes #8344

Scenarios Tested

Verified that when connected to the Auth emulator, the 2 code snippets below output the same UserRecord

  1. All lowercase email
const admin = require('firebase-admin');

admin.initializeApp({
    projectId: "demo-project"
})

process.env.FIREBASE_AUTH_EMULATOR_HOST = "127.0.0.1:9099"

async function main() {
    try {
        const matchingCase = '[email protected]';
        const user = await admin.auth().getUserByEmail(matchingCase); // Throws auth/user-not-found
        console.log(user);
    } catch (e) {
        console.error(e); 
    }
}

main()
  1. Random uppercases in email
const admin = require('firebase-admin');

admin.initializeApp({
    projectId: "demo-project"
})

process.env.FIREBASE_AUTH_EMULATOR_HOST = "127.0.0.1:9099"

async function main() {
    try {
        const nonMatchingCase = '[email protected]';
        const user = await admin.auth().getUserByEmail(nonMatchingCase); // Throws auth/user-not-found
        console.log(user);
    } catch (e) {
        console.error(e); 
    }
}

main()

Sample Commands

Notes

AFAICT, all emails in the emulator are lowercased on signUp

assert(isValidEmailAddress(reqBody.email), "INVALID_EMAIL");
const email = canonicalizeEmailAddress(reqBody.email);
assert(!state.getUserByEmail(email), "EMAIL_EXISTS");
updates.email = email;
. Verified this manually as well.

canonicalizeEmailAddress converts the string to all lower-case

export function canonicalizeEmailAddress(email: string): string {
return email.toLowerCase();
}

expectStatusCode(200, res);
expect(res.body.users).to.have.length(1);
expect(res.body.users[0].email).to.equal(email);
});

Check failure

Code scanning / CodeQL

Hard-coded credentials

The hard-coded value "Bearer owner" is used as [authorization header](1).
Comment thread src/emulator/auth/misc.spec.ts Outdated

Check failure

Code scanning / CodeQL

Hard-coded credentials

The hard-coded value "Bearer owner" is used as [authorization header](1).
Comment thread src/emulator/auth/misc.spec.ts Outdated

Check failure

Code scanning / CodeQL

Hard-coded credentials

The hard-coded value "Bearer owner" is used as [authorization header](1).
@aalej
aalej requested a review from joehan March 21, 2025 15:57

@joehan joehan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joehan
joehan merged commit 5264a78 into master Mar 21, 2025
@joehan
joehan deleted the aalej-auth-celookup branch March 21, 2025 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

admin.auth().getUserByEmail is case-insensitive against live data, but case-sensitive against emulator data

3 participants