Directors Palette now includes comprehensive security measures to protect against common vulnerabilities and enable safe API monetization.
Copy .env.example to .env.local and configure:
# CRITICAL: Set these immediately
API_RATE_LIMIT_ENABLED=true
API_AUTH_REQUIRED=true
CORS_ORIGIN=https://directorspal.com
# REQUIRED: Add your API keys (never commit these!)
OPENAI_API_KEY=sk-proj-your-actual-key
REPLICATE_API_TOKEN=r8_your-actual-token
SUPABASE_SERVICE_ROLE_KEY=your-actual-service-role-keyRun the API keys migration:
# Apply security database schema
supabase migration upFirst API key for testing:
# This creates your master API key (change immediately after testing)
# Key: dp_admin_master_key_change_immediately- β
API Key Format:
dp_[64-character-hex]format - β Multiple Auth Methods: Bearer token, X-API-Key header, query param (dev only)
- β Secure Storage: SHA256 hashed keys in database
- β Permission System: Granular permissions per API key
- β Per-API-Key Limits: Configurable requests per minute
- β Free Tier: 10 req/min, Pro Tier: 60 req/min, Enterprise: 600 req/min
- β Automatic Reset: 1-minute rolling windows
- β Headers: Standard rate limit headers in responses
- β Zod Schemas: Type-safe validation for all inputs
- β XSS Prevention: HTML sanitization with DOMPurify
- β Prompt Injection Protection: AI prompt sanitization
- β File Upload Security: MIME type, size, content validation
- β CORS Protection: Configurable origin restrictions
- β XSS Protection: Content-Security-Policy headers
- β Click-jacking Protection: X-Frame-Options
- β HTTPS Enforcement: Strict-Transport-Security
// Using Authorization header (recommended)
fetch('https://directorspal.com/api/v1/generate/story', {
method: 'POST',
headers: {
'Authorization': 'Bearer dp_your-api-key-here',
'Content-Type': 'application/json'
},
body: JSON.stringify({
story: "A detective enters a warehouse...",
director: "christopher-nolan"
})
})
// Using X-API-Key header (alternative)
fetch('https://directorspal.com/api/v1/generate/story', {
headers: {
'X-API-Key': 'dp_your-api-key-here'
}
})// Generate new API key
const newKey = generateApiKey() // Returns: dp_[64-chars]
// Store in database (hashed)
const hashedKey = hashApiKey(newKey)
await supabase.from('api_keys').insert({
user_id: userId,
name: 'My App Integration',
key_hash: hashedKey,
permissions: ['story:generate', 'image:generate:basic'],
rate_limit: 60
})POST /post-production/api/gen4- AI image generation- Cost: $0.01-0.05 per image (based on model)
POST /api/v1/story/generate- Story breakdown- Cost: $0.05 per story generation
POST /api/v1/music-video/generate- Music video concepts- Cost: $0.10 per music video generation
POST /api/upload-media- Secure file uploads- Limits: 10MB images, 25MB audio
- π¨ NEVER commit .env.local - Already in .gitignore
- π¨ Rotate API keys regularly - Every 90 days minimum
- π¨ Monitor usage - Watch for unusual API patterns
- π¨ Use HTTPS only - No HTTP in production
- All API keys rotated and secured
- Rate limiting enabled (
API_RATE_LIMIT_ENABLED=true) - CORS origin restricted (
CORS_ORIGIN=https://directorspal.com) - Error details disabled in production
- Security headers active
- Database RLS policies enabled
- GDPR: User data protection, right to deletion
- CCPA: California privacy compliance
- SOC 2: Enterprise customer requirements
- OWASP Top 10: Protection against common vulnerabilities
-- Monitor API usage patterns
SELECT
endpoint,
COUNT(*) as requests,
SUM(cost_usd) as total_cost,
AVG(duration_ms) as avg_response_time
FROM api_usage
WHERE created_at > NOW() - INTERVAL '24 hours'
GROUP BY endpoint;- Rate Limit Exceeded: Monitor for abuse patterns
- Failed Authentication: Track invalid API key attempts
- Large File Uploads: Monitor for potential attacks
- Unusual Usage Patterns: AI generation spikes
- β Usage Tracking: Every API call logged with cost
- β Credit System: Pre-paid credit deduction
- β Overage Protection: Automatic limiting when credits exhausted
- β Billing Analytics: Revenue tracking per customer
- Custom Rate Limits: Higher limits for enterprise customers
- Dedicated API Keys: Multiple keys per organization
- Usage Analytics: Detailed reporting dashboards
- SLA Guarantees: Contractual uptime commitments
- β API Authentication: Implemented with middleware
- β Rate Limiting: In-memory (upgrade to Redis for scale)
- β Input Validation: Zod schemas for all endpoints
- β File Security: Upload validation and sanitization
- β Security Headers: CORS, XSS, clickjacking protection
- β Environment Protection: Secure configuration management
Next Steps for Production:
- Generate and configure production API keys
- Enable security features in environment variables
- Test API endpoints with authentication
- Monitor security logs and usage patterns
Security implementation ready for enterprise customers and API monetization.