Production Checklist
Before deploying AllSafe Fast to production, verify that every item on this checklist is complete. Each item addresses a specific security or operational concern that could compromise your application if overlooked.
AllSafe Fast includes built-in production guards that will refuse to start if the secret key is default or cookies are insecure. However, many items on this checklist are operational — they require your action outside of AllSafe Fast's configuration. Do not skip any item.
Secret Key
The secret key is used to sign JWTs. If it is compromised, an attacker can forge valid tokens for any user.
# Generate a secure secret key
terminal
# Using the AllSafe CLI
allsafe secret
# Or using openssl
openssl rand -hex 32
# Set as environment variable
export ALLSAFE_SECRET_KEY="generated-secret-key-here"
Cookie Security
Cookies carry access and refresh tokens. Insecure cookie settings can lead to token theft via XSS or man-in-the-middle attacks.
# Cookie configuration for production
# ALLSAFE_COOKIE_SECURE=true
# ALLSAFE_COOKIE_HTTP_ONLY=true
# ALLSAFE_COOKIE_SAME_SITE=lax
config = AuthConfig(
secret_key="your-secure-secret-key",
env="production",
cookie_secure=True, # HTTPS only
cookie_http_only=True, # No JavaScript access
cookie_same_site="lax", # CSRF protection
)
HTTPS
All authentication traffic must be encrypted in transit. Without HTTPS, cookies and tokens can be intercepted.
Database Configuration
The database stores user accounts, sessions, and verification tokens. Proper configuration ensures data integrity and performance.
Redis Configuration
Redis powers the distributed rate limiter. Without Redis, rate limiting is per-process and ineffective in multi-worker deployments.
Email Service Configuration
Email is used for verification tokens, password resets, and magic links. In development, AllSafe Fast can print emails to the console, but production requires a real email service.
Rate Limiting
Rate limiting protects against brute force attacks, OTP flooding, and reset email spam.
CORS Configuration
Cross-Origin Resource Sharing (CORS) controls which origins can access your API. Misconfigured CORS can expose your API to unauthorized origins.
from fastapi.middleware.cors import CORSMiddleware
app.add_middleware(
CORSMiddleware,
allow_origins=["https://yourapp.com", "https://www.yourapp.com"],
allow_credentials=True, # Required for cookies
allow_methods=["GET", "POST", "PUT", "DELETE"],
allow_headers=["Authorization", "Content-Type"],
)
Trusted Hosts
Trusted host validation prevents HTTP host header attacks, which can be used for cache poisoning or password reset link manipulation.
from starlette.middleware.trustedhost import TrustedHostMiddleware
app.add_middleware(
TrustedHostMiddleware,
allowed_hosts=["yourapp.com", "www.yourapp.com"],
)
Logging Configuration
Proper logging helps detect security incidents, debug issues, and audit authentication events.
import logging
import json
# Structured JSON logging for production
class JSONFormatter(logging.Formatter):
def format(self, record):
log_data = {
"timestamp": self.formatTime(record),
"level": record.levelname,
"message": record.getMessage(),
"module": record.module,
}
return json.dumps(log_data)
logging.basicConfig(level=logging.INFO)
for handler in logging.getLogger().handlers:
handler.setFormatter(JSONFormatter())
Session Cleanup
Expired sessions and verification tokens accumulate in the database over time. Regular cleanup prevents table bloat and ensures expired tokens cannot be used.
import asyncio
from datetime import datetime, timezone
# Background task for session and token cleanup
async def cleanup_task(auth):
while True:
await asyncio.sleep(3600) # Run every hour
try:
await auth.storage.sessions.delete_expired()
await auth.storage.verifications.delete_expired()
logging.info("Session and token cleanup completed")
except Exception as e:
logging.error(f"Cleanup failed: {e}")
# Start cleanup task on application startup
@app.on_event("startup")
async def start_cleanup():
asyncio.create_task(cleanup_task(auth))
Final Verification
After completing all items above, run the AllSafe Fast doctor command to verify your configuration:
Review this checklist before every deployment, not just the first one. New security considerations may arise as your application grows. Treat this as a living document and add items specific to your application's needs.