fix(app): replace node-forge with native crypto for private key validation#3111
Open
kyungseopk1m wants to merge 1 commit intofirebase:mainfrom
Open
fix(app): replace node-forge with native crypto for private key validation#3111kyungseopk1m wants to merge 1 commit intofirebase:mainfrom
kyungseopk1m wants to merge 1 commit intofirebase:mainfrom
Conversation
…ation Replace the node-forge dependency with Node.js built-in crypto module for validating PEM-formatted private keys in ServiceAccount. This eliminates Math.random() calls during initializeApp(), which caused errors in environments that restrict non-deterministic APIs such as Next.js React Server Components with PPR/SSG. Fixes firebase#3075
Contributor
There was a problem hiding this comment.
Code Review
This pull request updates the package version to 13.8.0 and removes the node-forge dependency. The logic for validating service account private keys in src/app/credential-internal.ts has been refactored to use the native Node.js crypto.createPrivateKey method instead of node-forge. I have no feedback to provide as there were no review comments.
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.
Fixes #3075
Problem
initializeApp()with acert()credential callsrequire('node-forge')synchronously duringServiceAccountconstruction. Loadingnode-forgeinitializes a PRNG that usesMath.random(), which causes errors in environments that restrict non-deterministic APIs during static rendering — specifically Next.js App Router with Partial Pre-Rendering (PPR) / SSG:Solution
Replace
forge.pki.privateKeyFromPem()with Node.js built-incrypto.createPrivateKey(). This provides equivalent PEM validation while removing thenode-forgedependency entirely.Testing
All 6231 existing unit tests pass. The existing test
should throw given an object with a malformed "private_key" propertyincredential-internal.spec.tsalready covers the error path for invalid private keys.Notes
node-forge)