Skip to content

Security: Martin36/wl-viz

Security

SECURITY.md

Security Considerations

This document outlines the security measures implemented in the WL-Viz application and areas for potential improvement.

Implemented Security Measures

Backend Security

  1. Input Validation

    • Max iterations parameter validated (1-50 range) to prevent DoS attacks
    • Type checking for all user inputs
    • Graph structure validation through NetworkX
  2. Error Handling

    • Generic error messages to prevent information leakage
    • Detailed errors only logged server-side
    • Proper HTTP status codes (400, 500)
  3. Secure Hashing

    • SHA-256 used for deterministic color generation in WL algorithm
    • Prevents hash collisions and ensures consistency across runs
  4. Configuration Security

    • Environment variables for debug mode and host configuration
    • Default to localhost (127.0.0.1) instead of public (0.0.0.0)
    • Debug mode disabled by default
  5. CORS Protection

    • Flask-CORS configured for controlled cross-origin requests

Frontend Security

  1. XSS Prevention

    • HTML escaping utility function for user-controlled content
    • Node IDs and labels escaped before insertion
    • Safe DOM manipulation methods used where possible
  2. Data Sanitization

    • All API responses validated before rendering
    • User inputs sanitized before transmission

Known Limitations & Future Improvements

Low Priority

  1. Template Literals in HTML Generation

    • Some innerHTML usage with template literals remains
    • Mitigation: Data comes from trusted backend API
    • Future: Consider migrating to a framework with safer templating (React, Vue)
  2. Native prompt() Usage

    • Uses browser's prompt() for node label editing
    • Mitigation: Input is sanitized before use
    • Future: Implement custom modal dialog
  3. Graph Size Performance

    • Full graph sent in each API request
    • Mitigation: Typical use case involves small graphs
    • Future: Implement graph caching or delta updates
  4. ID Management

    • Node IDs increment indefinitely without reset
    • Mitigation: Acceptable for typical use cases
    • Future: Implement ID recycling or UUID-based system

Non-Issues

  1. SHA-256 Performance
    • SHA-256 chosen over MD5 for security, even though non-cryptographic use
    • Performance impact negligible for typical graph sizes (< 1000 nodes)
    • Deterministic hashing required for consistent WL algorithm results

Deployment Recommendations

Development

export FLASK_DEBUG=true
export FLASK_HOST=127.0.0.1
python app.py

Production

  1. Use a Production WSGI Server

    pip install gunicorn
    gunicorn -w 4 -b 127.0.0.1:5000 app:app
  2. Reverse Proxy (Nginx/Apache)

    • Place behind a reverse proxy for SSL/TLS
    • Configure rate limiting
    • Set up proper CORS policies
  3. Environment Configuration

    export FLASK_DEBUG=false
    export FLASK_HOST=127.0.0.1
    export FLASK_PORT=5000
  4. Additional Security Layers

    • Enable HTTPS/TLS
    • Implement rate limiting
    • Add authentication if needed
    • Configure CSP headers
    • Regular dependency updates

Reporting Security Issues

If you discover a security vulnerability, please report it by creating a private security advisory on GitHub rather than opening a public issue.

Security Audits

  • Last Review: 2025-11-24
  • Tools Used:
    • CodeQL Security Scanning
    • Manual Code Review
    • Flask Security Best Practices
  • Status: No critical vulnerabilities identified

There aren’t any published security advisories