fix: fail loudly on malformed Firebase credential JSON (#613) - #760
fix: fail loudly on malformed Firebase credential JSON (#613)#760saurabhhhcodes wants to merge 1 commit into
Conversation
…36singh#613) Replaced the silent fallback-to-ADC on malformed GOOGLE_APPLICATION_CREDENTIALS_JSON with a thrown critical error. Extracted initFirebaseAdmin() for testability and added unit tests covering: malformed JSON, structurally invalid creds, valid env init, ADC fallback, and the already-initialized no-op. Also skip app.listen() when NODE_ENV=test so the module is importable in tests.
|
Warning Review limit reached
Next review available in: 49 minutes You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|



Closes #613
Problem
When
GOOGLE_APPLICATION_CREDENTIALS_JSONwas set but malformed,server.tslogged the parse error and silently fell back to Application Default Credentials — hiding misconfigurations and risking running production with unintended privileges.Fix
initFirebaseAdmin(); malformed JSON now throws a critical error naming the env var and explicitly refuses to fall back to default credentials.admin.credential.cert()failures (structurally invalid credential) also throw instead of falling back.app.listen()underNODE_ENV=test, so the init logic is unit-testable.Verification
cloud-functions/src/server.test.ts(malformed JSON throws, no init; invalid credential throws; valid env init; ADC fallback; already-initialized no-op) — all pass.npx eslintclean;tsc -p tsconfig.build.json --noEmitclean.