Security Guide
Overview
This document outlines the security measures implemented in Dashtray to protect user data and prevent common vulnerabilities.Authentication & Authorization
Session Management
- HTTP-only cookies: Session tokens stored in HTTP-only cookies to prevent XSS attacks
- Secure flag: Cookies marked as secure in production (HTTPS only)
- SameSite: Cookies use SameSite=Lax to prevent CSRF attacks
- Session expiration: Sessions expire after 30 days of inactivity
- Token rotation: Refresh tokens rotated on each use
Password Security
- Hashing: Passwords hashed using bcrypt (handled by Better Auth)
- Minimum length: 8 characters required
- Strength checking: Client-side password strength validation
- No password storage: Passwords never stored in plain text or logs
OAuth Security
- State parameter: CSRF protection for OAuth flows
- PKCE: Proof Key for Code Exchange for public clients
- Token storage: OAuth tokens stored in HTTP-only cookies
- Scope limitation: Minimal scopes requested
Role-Based Access Control (RBAC)
Three roles with distinct permissions:-
Owner
- Full access to project
- Manage billing and subscription
- Delete project
- Manage team members
-
Editor
- Create/edit dashboards
- Manage integrations
- Invite team members (viewer/editor only)
- Cannot access billing or delete project
-
Viewer
- Read-only access to dashboards
- View metrics and reports
- Cannot modify anything
- API level (Convex functions)
- UI level (hide/disable actions)
- Route level (redirect unauthorized users)
Data Protection
Encryption at Rest
Sensitive data encrypted using AES-256-GCM:- API keys and credentials
- OAuth tokens
- User AI API keys
- Webhook URLs
Encryption in Transit
- HTTPS only: All traffic encrypted with TLS 1.3
- HSTS: HTTP Strict Transport Security headers
- Certificate pinning: Cloudflare managed certificates
Key Management
- Master key: Stored in environment variable (never in code)
- User-specific salts: Each user’s data encrypted with unique salt
- Key rotation: Master key can be rotated without re-encrypting all data
Input Validation
Frontend Validation
All user input validated using Zod schemas:Backend Validation
All Convex functions validate inputs:Sanitization
User-generated content sanitized before display:XSS Prevention
Content Security Policy (CSP)
Strict CSP headers configured:Output Encoding
- Svelte automatically escapes HTML in templates
- Use
{@html}only with sanitized content - Never use
innerHTMLwithout sanitization
Dangerous Patterns to Avoid
CSRF Protection
SameSite Cookies
Cookies use SameSite=Lax to prevent CSRF:State Tokens
OAuth flows use state parameter for CSRF protection.SQL Injection Prevention
Convex handles query parameterization automatically:Rate Limiting
API Endpoints
Rate limits enforced per project:- Scale/Agency: 1000 requests/hour
- Pro: 100 requests/hour
- Free: No API access
Authentication Endpoints
- Login: 5 attempts per 15 minutes per IP
- Password reset: 3 attempts per hour per email
- Email verification: 5 attempts per hour per email
Manual Sync
- Free tier: 3 manual syncs per day
- Pro+: Unlimited manual syncs
Webhook Security
Signature Verification
All webhooks verify signatures:HTTPS Only
Webhook URLs must use HTTPS:Idempotency
Webhooks processed idempotently using event IDs to prevent duplicate processing.API Security
Authentication
API requests require Bearer token:API Key Management
- Keys hashed using SHA-256 before storage
- Only last 4 characters shown in UI
- Keys can be revoked at any time
- Expiration dates supported
Request Validation
All API requests validated:CORS Policy
Strict CORS policy:Clickjacking Prevention
X-Frame-Options
CSP frame-ancestors
Security Headers
All responses include security headers:Logging and Monitoring
Audit Logs (Scale+)
All sensitive actions logged:- Dashboard creation/deletion
- Connection addition/removal
- Team member changes
- Subscription changes
- API key creation/revocation
Error Logging
Errors logged to Sentry:- Never log sensitive data (passwords, API keys)
- Mask sensitive fields in error context
- Include request ID for tracing
Security Monitoring
Monitor for:- Failed login attempts
- Rate limit violations
- Invalid API key usage
- Webhook signature failures
- Unusual access patterns
Dependency Security
Regular Updates
- Dependencies updated monthly
- Security patches applied immediately
- Automated vulnerability scanning (GitHub Dependabot)
Audit
Minimal Dependencies
- Only essential dependencies included
- Regular review of dependency tree
- Prefer well-maintained packages
Secrets Management
Environment Variables
All secrets stored in environment variables:.env Files
.env.localin .gitignore.env.production.templatefor documentation- Never commit actual secrets
Rotation
Regular rotation of:- Master encryption key (annually)
- API keys (as needed)
- OAuth client secrets (as needed)
Incident Response
Security Incident Procedure
- Detect: Monitor logs and alerts
- Contain: Disable affected systems
- Investigate: Determine scope and impact
- Remediate: Fix vulnerability
- Notify: Inform affected users
- Review: Post-mortem and improvements
Contact
Report security issues to: security@dashtray.comSecurity Checklist
- All passwords hashed with bcrypt
- Sensitive data encrypted at rest
- HTTPS enforced everywhere
- CSP headers configured
- CORS policy restrictive
- Rate limiting implemented
- Input validation on all endpoints
- Output encoding for user content
- Webhook signatures verified
- API keys hashed before storage
- Audit logging for sensitive actions
- Security headers on all responses
- Dependencies regularly updated
- No secrets in code or git
- Error messages don’t leak info
- Session management secure