Security Overview
Quail implements multiple layers of security to protect your data and database credentials. This guide covers essential security practices for production deployments.Encryption
All database credentials encrypted at rest using AES-256-GCM
Read-Only Access
Queries execute with read-only permissions to prevent data modification
Authentication
Supabase-powered authentication with JWT tokens
Network Security
IP whitelisting and SSL/TLS encryption for database connections
Encryption Keys
Generating a Secure Encryption Key
Quail uses AES-256-GCM encryption to protect database connection strings and credentials stored in browser localStorage. The encryption key is critical for security. Generate a cryptographically secure key:Key Management Best Practices
Secure Storage: Store the key in a secrets manager (AWS Secrets Manager, HashiCorp Vault, Azure Key Vault)
Why NEXT_PUBLIC prefix? The encryption key must be available in the browser to decrypt connection strings on the client side. While this seems counterintuitive, the security model assumes the browser environment is trusted for the authenticated user. The key is still not exposed in the codebase or version control.
Encryption Implementation
Quail’s encryption system (~/workspace/source/components/stores/utils/encrypted_store.ts) uses:- Algorithm: AES-256-GCM (Galois/Counter Mode)
- Key Size: 256 bits (32 bytes)
- IV: Randomly generated 12-byte initialization vector per encryption
- Authentication: GCM mode provides authenticated encryption (prevents tampering)
Key Rotation
If you must rotate the encryption key:Database Credential Security
Connection String Storage
Database connection strings contain sensitive credentials. Quail stores them securely:- Client-side encryption: Connection strings encrypted in browser before localStorage storage (~/workspace/source/components/stores/utils/encrypted_store.ts)
- Server-side handling: Connection strings transmitted over HTTPS to Azure Functions for query execution
- No persistent server storage: Credentials never stored on application servers or in logs
Connection strings are stored encrypted in the user’s browser localStorage. This means:
- Credentials don’t leave the user’s device except during query execution
- Each user’s database access is isolated
- Clearing browser data removes all saved connections
Creating Read-Only Database Users
PostgreSQL Read-Only User
MySQL Read-Only User
SQL Server Read-Only User
Password Requirements
For database user passwords:- Minimum 16 characters
- Mix of uppercase, lowercase, numbers, and symbols
- Generate using password manager or:
openssl rand -base64 24 - Rotate passwords quarterly
- Never reuse passwords across environments
Special Characters in Connection Strings
If passwords contain special characters, URL-encode them:@→%40#→%23!→%21:→%3A/→%2F
Environment Variable Security
Required Environment Variables
Securing Environment Variables
- Vercel
- Docker / Kubernetes
- AWS / Azure / GCP
- Go to Project Settings > Environment Variables
- Add variables individually (don’t import .env files)
- Mark sensitive keys as “Encrypted” in UI
- Use Preview/Production environments appropriately
- Enable “Sensitive” flag for:
SUPABASE_SERVICE_ROLE_KEYMONGODB_URINEXT_PUBLIC_ENCRYPTION_KEY
What NOT to Do
Network Security
IP Whitelisting
Most production databases require IP whitelisting. This prevents unauthorized access even if credentials are compromised.Whitelist in Database Provider:
- AWS RDS: Security Groups > Inbound Rules
- Azure SQL: Networking > Firewall Rules
- GCP Cloud SQL: Connections > Authorized Networks
- MongoDB Atlas: Network Access > IP Access List
For dynamic deployment platforms (e.g., serverless), you may need to whitelist a range of IPs or use a NAT gateway with a static IP.
SSL/TLS for Database Connections
Always enable SSL/TLS for database connections in production:disable- No SSL (never use in production)require- SSL required, no certificate verificationverify-ca- SSL + verify certificate authorityverify-full- SSL + verify hostname matches certificate
Authentication Security
Supabase Configuration
Quail uses Supabase for user authentication and authorization. Secure your Supabase project:Configure Auth Settings:
- Set appropriate JWT expiration (default: 1 hour)
- Enable email confirmation for new users
- Configure password requirements (min length, complexity)
Secure API Keys:
- Use
anonkey for client-side (limited access) - Protect
service_rolekey (full database access) - Rotate keys if compromised
Session Management
The middleware (~/workspace/source/middleware.ts) handles session validation on every request:- JWT tokens validated on each request
- Expired sessions automatically redirect to login
- Cookies secured with
httpOnly,secure, andsameSiteflags
Query Security
Read-Only Enforcement
Quail enforces read-only access by design:
- Database users should only have
SELECTprivileges - Query execution happens on Azure Functions with tier-based rate limiting (~/workspace/source/utils/actions/runSQL.ts)
- No write operations (INSERT, UPDATE, DELETE, DROP) should be permitted
- Database-level: Use read-only user permissions
- Network-level: Firewall rules allowing only SELECT queries
- Application-level: UI doesn’t provide write interfaces
- Monitoring: Log all queries for audit trails
SQL Injection Prevention
While Quail uses AI to generate SQL queries, security measures are in place:- Parameterized queries where possible
- Input validation on connection strings
- Query execution through trusted Azure Function endpoint
- User database credentials never exposed to other users
Monitoring & Auditing
Security Monitoring
Implement monitoring for security events:Audit Logs
Enable audit logging in your infrastructure:- Application logs: Next.js application logs (stdout/stderr)
- Database logs: Query logs in your database (enabled separately)
- Supabase logs: Auth events and API requests
- MongoDB logs: User metadata changes
Compliance Considerations
For regulated industries (HIPAA, SOC 2, GDPR):- Data encryption: At rest (database) and in transit (SSL/TLS)
- Access controls: Role-based access, read-only database users
- Audit trails: Log all data access and authentication events
- Data residency: Choose database regions that comply with requirements
- User consent: Implement consent flows for data collection
- Data retention: Configure automatic data deletion policies
Incident Response
If Encryption Key is Compromised
Immediate: Rotate the encryption key (see Key Rotation)
