Cloud Functions Security¶
This section covers security best practices for Firebase Cloud Functions, including common vulnerabilities and how to prevent them.
Overview¶
Cloud Functions provide server-side logic for your Firebase application, but they also introduce security risks if not properly configured. This section covers comprehensive security practices for Cloud Functions.
Common Security Issues¶
Authentication and Authorization¶
- Missing Authorization Checks - No access control validation
- Flawed Custom Claims Authorization - Improper custom claims usage
- Insecure Custom Claims Management - Unsafe claims modification
- Open User Creation via Admin SDK - Unrestricted user creation
App Check Integration¶
- Missing App Check Verification - HTTP triggers not protected
- App Check Context Mishandling - Improper App Check usage
Input Validation and Security¶
- Unvalidated Input to Sensitive Sinks - No input sanitization
- Insecure Deserialization - Unsafe data parsing
- Unbounded Operations from User Input - DoS vulnerability
Secrets and Configuration¶
- Hardcoded Secrets - Secrets in source code
- Exposure of API Keys - Client-side key exposure
- Logging of Sensitive Environment Variables - Secret leakage in logs
Resource Management¶
- Excessive Timeout Value - Functions running too long
- Missing or High MaxInstances - No scaling limits
- Inefficient Database Queries - Performance issues
Permissions and Access¶
- Admin SDK Bypass of Security Rules - Improper Admin SDK usage
- Overly Permissive Admin SDK IAM - Excessive permissions
- Use of Default Service Account - Default service account risks
- Overly Permissive CORS Policy - Insecure CORS settings
Triggers and Events¶
- Overly Broad Event Trigger - Too many trigger conditions
- Potential Infinite Loop - Recursive trigger calls
Dependencies and Logging¶
- Vulnerable Third Party Dependencies - Outdated packages
- Logging of Full Complex Objects - Excessive logging
- Logging of Sensitive Environment Variables - Secret exposure
Best Practices¶
Security Fundamentals¶
- Always validate input from clients and external sources
- Implement proper authentication and authorization checks
- Use environment variables for secrets and configuration
- Enable App Check for HTTP and callable functions
- Follow principle of least privilege for permissions
Performance and Reliability¶
- Set appropriate timeouts and memory limits
- Implement proper error handling and logging
- Use connection pooling for database connections
- Monitor function performance and costs
- Implement circuit breakers for external services
Development Practices¶
- Keep dependencies updated and scan for vulnerabilities
- Use TypeScript for better type safety
- Implement comprehensive testing including security tests
- Use separate environments for development and production
- Regular security audits of function code