This document outlines security best practices and configuration options for ArchDraw.
These variables must be properly configured for secure operation in production:
BETTER_AUTH_SECRET: Secret key for authentication sessions. Must be a strong, random string in production.BETTER_AUTH_URL: The canonical URL of your application. Required in production for OAuth to work correctly.DATABASE_URL: PostgreSQL connection string. Use SSL connections in production.ADMIN_PASSCODE&ADMIN_SESSION_SECRET: Required for admin panel access. Use strong, unique values.
The admin panel has enhanced security features:
- Rate Limiting: 5 login attempts per IP per 15 minutes
- Session Binding: Admin sessions are bound to user agent in production
- Secure Cookies: HttpOnly, Secure (in production), and SameSite policies
- Timing-Safe Comparison: Passcode comparison uses constant-time algorithm
Configure admin access with:
ADMIN_PASSCODE=your_strong_passcode
ADMIN_SESSION_SECRET=your_strong_session_secret
ALLOWED_ADMIN_EMAIL=admin@yourdomain.com
NEXT_PUBLIC_ADMIN_EMAIL=admin@yourdomain.comThe application uses a strict Content Security Policy (CSP) to prevent XSS attacks:
unsafe-evalhas been removed from script sourcesunsafe-inlineis retained only where necessary for inline scripts- Frame sources are restricted to trusted domains
To restrict which domains can embed your diagrams:
ALLOWED_EMBED_DOMAINS=trusted-domain.com,another-trusted-domain.comIf not set, defaults to allowing all domains (*). For production, specify exact domains.
- Groq API keys are no longer initialized with
dangerouslyAllowBrowser: true - Multiple API keys can be configured for load balancing and failover
- Keys are rotated automatically on rate limits or errors
Before deploying to production:
-
Set all required environment variables
BETTER_AUTH_SECRET(strong random string)BETTER_AUTH_URL(your production URL)DATABASE_URL(with SSL)GROQ_API_KEY
-
Configure admin access (if using admin panel)
- Set strong
ADMIN_PASSCODEandADMIN_SESSION_SECRET - Configure
ALLOWED_ADMIN_EMAIL - Set
NEXT_PUBLIC_ADMIN_EMAIL
- Set strong
-
Restrict embed domains (if using embed feature)
- Set
ALLOWED_EMBED_DOMAINSto specific domains
- Set
-
Enable OAuth providers (optional)
- Configure
GOOGLE_CLIENT_IDandGOOGLE_CLIENT_SECRET - Configure
GITHUB_CLIENT_IDandGITHUB_CLIENT_SECRET
- Configure
-
Enable Redis (recommended for production)
- Set
UPSTASH_REDIS_REST_URLandUPSTASH_REDIS_REST_TOKEN
- Set
-
Set NODE_ENV
NODE_ENV=production(enables production security features)
- OAuth 2.0 via Google and GitHub
- Session-based authentication with secure cookies
- CSRF protection via SameSite cookie policies
- Rate limiting on admin endpoints
- IP-based tracking for admin sessions
- User agent binding for admin sessions in production
- All database connections should use SSL
- API keys are never exposed to client-side code
- Sensitive environment variables are server-side only
- X-Content-Type-Options: nosniff
- X-XSS-Protection: 1; mode=block
- Referrer-Policy: strict-origin-when-cross-origin
- Permissions-Policy: restricts camera, microphone, geolocation
- Content-Security-Policy: strict CSP policy
The application includes security-focused logging:
- Admin authentication attempts
- Session validation failures
- User agent mismatches
- Rate limit violations
Monitor these logs for suspicious activity in production.
In development mode:
- Security validations are warnings rather than errors
- Cookies may use
laxSameSite policy for local testing - Embed defaults to allow all domains
In production mode:
- Security validations are enforced (will throw errors)
- Cookies use
strictSameSite policy - Admin sessions require user agent binding
- CSP and other headers are strictly enforced
If you discover a security vulnerability, please report it responsibly:
- Do not create public issues for security vulnerabilities
- Send details to the project maintainers privately
- Include steps to reproduce the vulnerability
- Allow time for the issue to be addressed before disclosure