This document outlines the security measures implemented in the Mural collaborative pixel art application.
- XSS Prevention: All user-generated content is now rendered using
textContentinstead ofinnerHTML - Coordinate Validation: Strict type checking and bounds validation for pixel placement
- Color Format Validation: Hex color format validation with regex pattern
#[0-9A-Fa-f]{6} - Server-side Validation: All inputs are validated on both client and server sides
- Session Security:
- Server-side session generation with UUID
- Session metadata tracking (created_at)
- HttpOnly, Secure, and SameSite cookie flags
- Session validation on each request
- Rate Limiting: Implemented per-user rate limiting (60 requests/minute default)
- WebSocket Authentication: WebSocket connections require valid session
- User Privacy: User IDs are hashed (SHA256) before broadcasting to other clients
- Secure Headers: Implemented security headers including CSP, X-Frame-Options, etc.
- HTTPS Enforcement: HSTS header for production environments
- DOM-based XSS Prevention: All dynamic content uses safe DOM manipulation methods
- Content Security Policy: Restrictive CSP that only allows necessary resources
- Safe Event Handlers: Event listeners attached via addEventListener instead of inline handlers
- CORS Configuration: Production uses whitelist of allowed origins
- WebSocket Validation: Connections rejected without valid session
- Large Data Handling: Large canvas data redirected to API endpoint
The following security headers are implemented:
Content-Security-Policy: default-src 'self'; script-src 'self' 'unsafe-inline' https://cdn.tailwindcss.com https://cdnjs.cloudflare.com; style-src 'self' 'unsafe-inline' https://cdn.tailwindcss.com; font-src 'self' data:; img-src 'self' data: blob:; connect-src 'self' ws: wss:; frame-ancestors 'none';
X-Content-Type-Options: nosniff
X-Frame-Options: DENY
X-XSS-Protection: 1; mode=block
Referrer-Policy: strict-origin-when-cross-origin
Strict-Transport-Security: max-age=31536000; includeSubDomains (production only)
# Required for production
SECRET_KEY=<strong-random-key>
SESSION_COOKIE_SECURE=true
CORS_ORIGINS=https://yourdomain.com,https://anotherdomain.com
# Optional
RATE_LIMIT_PIXELS_PER_MINUTE=10- Keep Dependencies Updated: Regularly update Flask, Flask-SocketIO, and other dependencies
- Environment Separation: Use different configurations for development and production
- Secret Management: Never commit secrets to version control
- Regular Audits: Periodically review security measures and update as needed
While comprehensive security measures have been implemented, consider these additional steps:
- API Authentication: Implement API keys or OAuth for programmatic access
- DDoS Protection: Use services like Cloudflare for additional protection
- Database Security: If migrating from JSON to database, implement proper parameterized queries
- Monitoring: Implement security monitoring and alerting
- Backup: Regular backups of canvas data
To test the implemented security measures:
- XSS Testing: Try injecting
<script>alert('XSS')</script>in various inputs - Rate Limiting: Send rapid requests to test rate limiting
- Session Security: Try manipulating session cookies
- CORS: Test cross-origin requests from unauthorized domains