Skip to content

Security: Hack-Pac/Mural

Security

SECURITY.md

Mural Security Implementation

This document outlines the security measures implemented in the Mural collaborative pixel art application.

Security Vulnerabilities Addressed

1. Input Validation & Sanitization

Implemented Fixes:

  • XSS Prevention: All user-generated content is now rendered using textContent instead of innerHTML
  • 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

2. Authentication & Authorization

Implemented Fixes:

  • 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

3. Data Protection

Implemented Fixes:

  • 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

4. Client-Side Security

Implemented Fixes:

  • 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

5. Communication Security

Implemented Fixes:

  • 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

Security Headers

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)

Environment Variables for Security

# 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

Best Practices

  1. Keep Dependencies Updated: Regularly update Flask, Flask-SocketIO, and other dependencies
  2. Environment Separation: Use different configurations for development and production
  3. Secret Management: Never commit secrets to version control
  4. Regular Audits: Periodically review security measures and update as needed

Remaining Considerations

While comprehensive security measures have been implemented, consider these additional steps:

  1. API Authentication: Implement API keys or OAuth for programmatic access
  2. DDoS Protection: Use services like Cloudflare for additional protection
  3. Database Security: If migrating from JSON to database, implement proper parameterized queries
  4. Monitoring: Implement security monitoring and alerting
  5. Backup: Regular backups of canvas data

Testing Security

To test the implemented security measures:

  1. XSS Testing: Try injecting <script>alert('XSS')</script> in various inputs
  2. Rate Limiting: Send rapid requests to test rate limiting
  3. Session Security: Try manipulating session cookies
  4. CORS: Test cross-origin requests from unauthorized domains

There aren’t any published security advisories