Repository navigation
fix(auth): accept URL-safe Base64 in auth:import validation - #11577
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
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.
joehan
approved these changes
Nov 23, 2026
avolkovi
force-pushed
the
avolkovi/auth-import-urlsafe-base64
branch
from
November 30, 2026 23:04
14cf342 to
0d0f1f0
Compare
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
force-pushed
the
avolkovi/auth-import-urlsafe-base64
branch
from
December 2, 2026 19:33
0d0f1f0 to
513a43f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Firebase Admin SDK
listUsers()returnspasswordHashandpasswordSaltencoded in URL-safe Base64 (RFC 4648 Section 5, using-and_), whereasfirebase auth:importpreviously 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 withPassword salt should be base64 encoded.orPassword hash should be base64 encoded., even thoughgenUploadAccountPostBodyimmediately converts both fields to web-safe Base64 before callinguploadAccount.This change normalizes
-to+and_to/inisValidBase64soauth:importaccepts both standard Base64 and URL-safe Base64 (padded or unpadded) while still rejecting invalid Base64 strings.Scenarios Tested
src/accountImporter.spec.tscovering padded and unpadded URL-safe Base64passwordHashandsaltvalues in both CSV (transArrayToUser) and JSON (validateUserJson) import paths, as well as invalid Base64 rejection.Sample Commands