This document outlines the security measures implemented in DocMagic and best practices for maintaining a secure deployment.
- Supabase Auth Integration: Secure JWT-based authentication
- Protected Routes: Middleware-based route protection
- Session Management: Automatic token refresh and secure session handling
- Password Requirements: Strong password validation (8+ chars, mixed case, numbers)
- Zod Schema Validation: Type-safe input validation for all API endpoints
- SQL Injection Protection: Pattern detection and input sanitization
- XSS Prevention: HTML sanitization and Content Security Policy
- Rate Limiting: API endpoint protection against abuse
- Content Security Policy (CSP): Prevents XSS and code injection
- X-Frame-Options: Prevents clickjacking attacks
- X-Content-Type-Options: Prevents MIME type sniffing
- Strict-Transport-Security: Enforces HTTPS connections
- X-XSS-Protection: Browser XSS filtering
- Referrer-Policy: Controls referrer information
- CORS Configuration: Restrictive cross-origin policies
- Webhook Signature Verification: Stripe webhook security
- Environment Variable Validation: Runtime checks for required secrets
- Error Handling: Secure error responses without sensitive data exposure
- Environment Variables: No hardcoded secrets in code
- Secure Headers: All sensitive data transmitted securely
- Input Length Limits: Prevents buffer overflow attacks
- File Upload Validation: Type and size restrictions
Ensure these environment variables are properly configured:
# Required Security Variables
NEXTAUTH_SECRET=your-nextauth-secret-here-use-openssl-rand-base64-32
NEXT_PUBLIC_SUPABASE_URL=https://your-project-id.supabase.co
NEXT_PUBLIC_SUPABASE_ANON_KEY=your-supabase-anon-key-here
SUPABASE_SERVICE_ROLE_KEY=your-supabase-service-role-key-here
GEMINI_API_KEY=your-gemini-api-key-here
# Optional but Recommended
STRIPE_WEBHOOK_SECRET=whsec_your_webhook_secret_hereCurrent rate limits (per IP address):
- Authentication endpoints: 10 requests per 15 minutes
- Generation endpoints: 20 requests per 15 minutes
- General API endpoints: 100 requests per 15 minutes
The CSP header allows:
- Scripts from self and Stripe
- Styles from self and Google Fonts
- Images from self, data URLs, and HTTPS sources
- Connections to Supabase, Stripe, and Gemini API
- Never commit secrets: Use environment variables for all sensitive data
- Validate all inputs: Use the validation schemas in
lib/validation.ts - Sanitize user content: Use provided sanitization functions
- Check authentication: Verify user sessions in protected API routes
- Log security events: Use
logSecurityEvent()for monitoring
- Use HTTPS: Always deploy with SSL/TLS certificates
- Environment isolation: Separate development and production environments
- Regular updates: Keep dependencies updated for security patches
- Monitor logs: Watch for security events and failed authentication attempts
- Backup strategy: Regular database backups with encryption
- Strong passwords: Enforce minimum password requirements
- Account security: Monitor for suspicious login attempts
- Data privacy: Only collect necessary user information
- Secure sessions: Automatic logout after inactivity
Security events are logged for:
- Failed authentication attempts
- Rate limit violations
- Invalid input detection
- Webhook signature failures
- CSRF protection triggers
- Review authentication logs regularly
- Monitor API rate limit violations
- Check for unusual traffic patterns
- Verify webhook signature validations
- Monitor database access patterns
{
"headers": [
{
"source": "/(.*)",
"headers": [
{ "key": "X-Frame-Options", "value": "DENY" },
{ "key": "X-Content-Type-Options", "value": "nosniff" },
{ "key": "Strict-Transport-Security", "value": "max-age=31536000" }
]
}
]
}Security headers are configured in netlify.toml with:
- CSP policy
- Frame protection
- XSS protection
- CORS restrictions
- Test authentication flows
- Verify rate limiting works
- Check input validation
- Test CORS policies
- Verify webhook signatures
Consider implementing:
- Security scanning in CI/CD
- Dependency vulnerability checks
- Automated penetration testing
- Regular security audits
- Do not create a public issue
- Email security concerns to: [your-security-email]
- Include detailed reproduction steps
- Allow time for investigation and patching
- Assess the severity and impact
- Implement immediate containment
- Develop and test a fix
- Deploy the fix to production
- Notify affected users if necessary
- Document lessons learned
Last Updated: January 2025 Security Review: Required every 6 months