A Comprehensive Guide to Firebase Security¶
If you're building with Firebase, you're standing on the shoulders of giants. But with great power comes the need for great security. A single misconfiguration can expose data, lead to staggering bills, or bring your app to a halt.
This guide introduces a mental framework used by security professionalsβSTRIDEβto help you think systematically about threats to your Firebase application. We'll break down each threat and link you to the specific rules and configurations that form your shield.
What is STRIDE?
STRIDE is a threat modeling methodology for identifying and categorizing security threats. It stands for:
- **S**poofing
- **T**ampering
- **R**epudiation
- **I**nformation Disclosure
- **D**enial of Service
- **E**levation of Privilege
We've also added a special category crucial for cloud developers: Denial of Wallet.
Table of Contents¶
- A Comprehensive Guide to Firebase Security
- Table of Contents
- π₯ Spoofing: Pretending to Be Someone You're Not
- π₯ Tampering: Changing Data You Shouldn't
- π₯ Information Disclosure: Exposing Secrets
- π₯ Denial of Service and Denial of Wallet: The Silent Killers
- π₯ Elevation of Privilege: Gaining Powers You Shouldn't Have
- Ready to Secure Your App?
π₯ Spoofing: Pretending to Be Someone You're Not¶
Spoofing is about illegitimate actors (users or services) gaining access by faking their identity. In Firebase, this often means an unverified app or script interacting with your backend as if it were your legitimate client. Firebase App Check is your primary defense here.
- Threat: Unidentified clients (bots, scripts, tampered apps) directly calling your backend.
- Impact: Abuse of resources, billing fraud, data poisoning, and bypassing your security rules.
Core Spoofing Vulnerabilities & Defenses¶
- App Check Not Enabled for Application: The front door is unlocked. If you haven't enabled App Check, you have no verification that requests come from your genuine app.
- App Check Not Enforced for Services: Even if App Check is on, it's useless until you enforce it for each service.
- Enforce for Firestore
- Enforce for Storage
- Enforce for Functions
- Enforce for AI Logic
- Misconfigured Attestation: A faulty setup can render App Check ineffective.
- Incorrect reCAPTCHA Key for Web
- Misonfigured App Attest for iOS
- Email Enumeration Protection Disabled: Attackers can "guess" valid user emails by analyzing error messages, a form of user identity spoofing.
π₯ Tampering: Changing Data You Shouldn't¶
Tampering involves the unauthorized modification of data. This could be a user changing their role in their profile, altering a file after upload, or corrupting data used by your AI models. Your primary defense is rigorous, server-side validation in your Security Rules, a cornerstone of effective Firebase security.
- Threat: Users or attackers modifying data to bypass application logic or corrupt its integrity.
- Impact: Data corruption, application errors, and potential for privilege escalation.
Core Tampering Vulnerabilities & Defenses¶
- Missing Write Validation: The most common data tampering vulnerability. If your rules don't validate the schema of incoming data, users can write anything they want (e.g.,
isAdmin: true
). - Missing Validation on File Update: An attacker could upload a safe file, then update it to be a malicious or oversized one, bypassing initial checks.
- Mutable Content-Type on Update: Allowing a user to change a file's type from
image/png
totext/html
could enable content spoofing or XSS attacks. - Insecure Delete Operations: Deleting a document without cleaning up references leaves orphaned data, a form of data integrity tampering.
- Unprotected Data Source for AI (RAG): A form of "data poisoning" where an attacker tampers with the knowledge base your AI uses, causing it to generate false or malicious responses.
π₯ Information Disclosure: Exposing Secrets¶
This is the classic data breach. It happens when someone can read data they are not authorized to see, from sensitive user information to your system's inner workings like hardcoded API keys.
- Threat: Unauthorized access to sensitive data stored in Firestore, Storage, or even in your Function's source code.
- Impact: Privacy violations, data leakage, and providing attackers with intel for further attacks.
The Critical Threats
Universal access rules are the #1 cause of major Firebase data breaches. - Universal Public Access in Firestore: allow read: if true;
is a recipe for disaster. - Firebase Storage Publicly Readable: Exposing an entire bucket when you only meant to expose a few files.
Core Information Disclosure Vulnerabilities & Defenses¶
- Unrestricted Authenticated Access (IDOR): The second most common breach. A rule like
allow read: if request.auth != null;
allows any logged-in user to read any other user's data. - Overly Broad Recursive Wildcard: A recursive wildcard (
{document=**}
) can accidentally grant access to sensitive subcollections you didn't intend to expose. - Hardcoded Secrets in Functions: Embedding API keys or passwords in your code makes them visible to anyone with source code access.
- Logging Sensitive Data: Accidentally logging entire
process.env
objects or other secrets to your logging provider. - Prompt Injection Attacks: A clever user could craft input that tricks your AI model into revealing its system prompt or other sensitive contextual data.
π₯ Denial of Service and Denial of Wallet: The Silent Killers¶
Denial of Service (DoS) aims to make your app unavailable to legitimate users. In Firebase, this often transforms into a Denial of Wallet (DoW) attack, where an attacker exploits your app's scalable nature to run up a massive bill.
- Threat: A malicious user (or faulty code) performing a huge number of operations, triggering excessive function invocations, reads, or writes.
- Impact: A frozen application, loss of user trust, and a bill that could bankrupt your business.
Core DoS / DoW Vulnerabilities & Defenses¶
- The Kill-Switch: Your Ultimate Defense: Flames Shield allows you to set a hard billing limit that automatically detaches your billing account, shutting down paid services before costs spiral out of control.
- Rate Limiting Your Functions: A crucial first line of defense to prevent abuse of individual functions.
- Unbounded Operations from User Input: A function that performs a loop or fetches data based on unvalidated user input (e.g.,
count=1000000
) is a prime DoW target. - Excessive Reads in Security Rules: A single query can trigger thousands of
get()
orexists()
calls within your rules, leading to huge costs and slow performance. - Potential Infinite Loops: A function that writes to a location it's also triggered by can create a recursive loop that will run until your project hits its limits.
- Unrestricted File Size on Upload: Without limits, users can fill your storage bucket with massive files, incurring high storage costs.
- Missing Per-User Rate Limits for AI Logic: AI calls can be expensive. A single user making thousands of requests can create a significant bill.
π₯ Elevation of Privilege: Gaining Powers You Shouldn't Have¶
This threat involves a user gaining the ability to perform actions beyond their authorized permissions. This often happens when a user can modify their own roles or permissions.
- Threat: A standard user finding a way to make themselves an administrator or gain access to admin-only functions.
- Impact: Complete compromise of your application's integrity and data.
Core Elevation of Privilege Vulnerabilities & Defenses¶
- Privilege Escalation Through Write Access: The classic example. A user can write to their own profile document, including the
role
field, changing it from'user'
to'admin'
. - Insecure Custom Claims Management: Custom claims are the right way to handle roles, but the function that sets these claims must be strictly protected so only admins can call it.
- Open User Sign-up on Admin Apps: If your app is an internal tool, but you leave open sign-up enabled, an attacker can register an account and may gain default internal access.
- Admin SDK Bypasses Security Rules: Remember, code running in a function with the Admin SDK has god-mode access. The function's own internal logic is the only thing preventing unauthorized actions.
- Overly Permissive IAM on Service Accounts: Using the default service account with a broad "Editor" role for your functions is risky. If a function is compromised, the attacker has extensive control over your entire Google Cloud project.
Ready to Secure Your App?¶
Understanding the threats is the first step. Now it's time to build your defenses.
- Start Here: Follow our Quickstart Guide to get Flames Shield set up for your project.
- Set Your Guardrail: Configure your Billing Kill-Switch immediately. It's the most important safety net you can have.
- Dive Deeper: Use the links in this guide to explore each vulnerability and ensure your Firebase configuration is secure, resilient, and cost-effective.