Skip to content

fix(auth): accept URL-safe Base64 in auth:import validation - #11577

Merged
avolkovi merged 2 commits into
mainfrom
avolkovi/auth-import-urlsafe-base64
Dec 2, 2026
Merged

avolkovi merged 2 commits into
mainfrom
avolkovi/auth-import-urlsafe-base64

Conversation

@avolkovi

Copy link
Copy Markdown
Contributor

Description

Firebase Admin SDK listUsers() returns passwordHash and passwordSalt encoded in URL-safe Base64 (RFC 4648 Section 5, using - and _), whereas firebase auth:import previously validated those fields using a strict standard Base64 round-trip (Buffer.from(str, "base64").toString("base64") === str). As a result, importing user records exported via the Admin SDK failed with Password salt should be base64 encoded. or Password hash should be base64 encoded., even though genUploadAccountPostBody immediately converts both fields to web-safe Base64 before calling uploadAccount.

This change normalizes - to + and _ to / in isValidBase64 so auth:import accepts both standard Base64 and URL-safe Base64 (padded or unpadded) while still rejecting invalid Base64 strings.

Scenarios Tested

  • Added unit tests in src/accountImporter.spec.ts covering padded and unpadded URL-safe Base64 passwordHash and salt values in both CSV (transArrayToUser) and JSON (validateUserJson) import paths, as well as invalid Base64 rejection.

Sample Commands

firebase auth:import users.json --hash-algo=SCRYPT --hash-key=<key> --salt-separator=<sep> --rounds=8 --mem-cost=14

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request updates the auth:import Base64 validation to accept URL-safe Base64 (-, _) in addition to standard Base64 (+, /) for passwordHash and salt, along with adding corresponding unit tests and a changelog entry. Feedback on the changes suggests making isValidBase64 more robust by changing its parameter type to unknown and adding a defensive type check to prevent potential runtime TypeError crashes when non-string values are passed from loosely-typed JSON inputs.

Comment thread src/accountImporter.ts Resolved
@avolkovi
avolkovi requested a review from joehan November 23, 2026 19:01
@avolkovi
avolkovi force-pushed the avolkovi/auth-import-urlsafe-base64 branch from 14cf342 to 0d0f1f0 Compare November 30, 2026 23:04
@avolkovi
avolkovi enabled auto-merge (squash) November 30, 2026 23:06
Firebase Admin SDK `listUsers()` returns `passwordHash` and `passwordSalt` encoded in URL-safe Base64 (RFC 4648 Section 5, using `-` and `_`), whereas `firebase auth:import` previously validated those fields using a strict standard Base64 round-trip (`Buffer.from(str, "base64").toString("base64") === str`). As a result, importing user records exported via the Admin SDK failed with `Password salt should be base64 encoded.` or `Password hash should be base64 encoded.`, even though `genUploadAccountPostBody` immediately converts both fields to web-safe Base64 before calling `uploadAccount`.

This change normalizes `-` to `+` and `_` to `/` in `isValidBase64` so `auth:import` accepts both standard Base64 and URL-safe Base64 (padded or unpadded) while still rejecting invalid Base64 strings.

- Added unit tests in `src/accountImporter.spec.ts` covering padded and unpadded URL-safe Base64 `passwordHash` and `salt` values in both CSV (`transArrayToUser`) and JSON (`validateUserJson`) import paths, as well as invalid Base64 rejection.

```bash
firebase auth:import users.json --hash-algo=SCRYPT --hash-key=<key> --salt-separator=<sep> --rounds=8 --mem-cost=14
```
@avolkovi
avolkovi force-pushed the avolkovi/auth-import-urlsafe-base64 branch from 0d0f1f0 to 513a43f Compare December 2, 2026 19:33
@avolkovi
avolkovi merged commit 05ca200 into main Dec 2, 2026
42 checks passed
@avolkovi
avolkovi deleted the avolkovi/auth-import-urlsafe-base64 branch December 2, 2026 19:50
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.

2 participants