Skip to content

Security: tr1ckz/PrintHive

Security

SECURITY.md

Security Policy

Security Audit Results

PrintHive has undergone a comprehensive security audit. This document outlines our security practices and vulnerability handling procedures.

Audit Date: January 13, 2026

Verified Security Controls

✅ Input Validation & Sanitization

  • Path Traversal Protection: All file paths validated with sanitizeFilePath() function
  • HTML Escaping: User input escaped with htmlEscape() to prevent XSS attacks
  • SQL Injection Prevention: All database queries use parameterized statements
  • File Upload Validation: Only .stl, .3mf, and .gcode files accepted

✅ Authentication & Authorization

  • Session-based authentication required for all protected endpoints
  • OAuth/OIDC SSO integration support (Authentik, etc.)
  • Share links use cryptographically random hashes (16 bytes)
  • Share link expiration enforced (24-hour TTL)
  • Role-based access control (admin, user roles)

✅ Secrets Management

  • ✓ No hardcoded credentials or secrets in codebase
  • ✓ Environment variables properly used for all sensitive config
  • .env file excluded from git via .gitignore
  • SESSION_SECRET, OAUTH_CLIENT_SECRET, etc. configured via environment
  • Database credentials managed securely

✅ Security Headers

X-Frame-Options: SAMEORIGIN              (Clickjacking protection)
X-Content-Type-Options: nosniff           (MIME type sniffing prevention)
X-XSS-Protection: 1; mode=block           (Legacy XSS filter)
Referrer-Policy: strict-origin-when-cross-origin
Content-Security-Policy: restricted       (Only self + trusted CDNs)
Permissions-Policy: disabled              (Camera, mic, geolocation, etc.)

✅ Dependency Security

  • Zero npm vulnerabilities (verified with npm audit)
  • Transitive dependencies pinned to secure versions
  • Regular dependency updates via Dependabot

✅ Network Security

  • Express app trusts proxy headers for X-Forwarded-*
  • HTTPS recommended in production (via reverse proxy like Nginx)
  • CORS properly configured where needed
  • Session cookies marked as httpOnly and secure

✅ Data Privacy

  • Share access tracking (for monitoring)
  • No telemetry or usage tracking
  • Database encryption recommended for sensitive deployments
  • User data stored locally (not sent to third parties)

✅ Code Quality

  • Debug logs removed from production code (console.log/debug stripped)
  • Console.error/warn retained for monitoring
  • Type-safe database operations
  • Proper error handling without leaking internals

✅ Docker Container Security

  • Alpine Linux base image (minimal attack surface)
  • Non-root user execution
  • Read-only filesystem where possible
  • Security vulnerability scanning in CI/CD
  • Health checks configured

✅ File System Security

  • .gitignore excludes:
    • .env files
    • Database files (.db)
    • Session data
    • Application data directories
    • Sensitive logs

Endpoints Security Summary

Protected Endpoints (Authentication Required)

  • /api/library/* (upload, list, edit metadata)
  • /api/settings/* (user settings, printer config)
  • /admin/* (admin panel)
  • /api/log-level (log configuration)

Public Endpoints (No Auth, Limited Scope)

  • /library/share?hash=* (share page view)
  • /api/library/share/:hash/download (download model)
  • /api/library/share/:hash/geometry (3D geometry)
  • /api/library/share/:hash/thumbnail (preview image)

Reporting Security Vulnerabilities

If you discover a security vulnerability in PrintHive, please email security concerns to the maintainers or create a private security advisory on GitHub. Please do NOT create public issues for security vulnerabilities.

Responsible Disclosure

  1. Report the vulnerability privately
  2. Allow 90 days for patch development
  3. Vulnerability will be disclosed after patch release
  4. Security advisory will credit researchers (if desired)

Security Best Practices for Deployment

1. Environment Configuration

# Generate a strong SESSION_SECRET
SESSION_SECRET=$(openssl rand -base64 32)

# Set PUBLIC_URL to your actual domain
PUBLIC_URL=https://printhive.example.com

# Configure OAuth if using SSO
OAUTH_PROVIDER=oidc
OAUTH_ISSUER=https://auth.example.com
OAUTH_CLIENT_ID=your-client-id
OAUTH_CLIENT_SECRET=your-client-secret

2. Reverse Proxy Setup (Nginx Recommended)

server {
    listen 443 ssl http2;
    server_name printhive.example.com;
    
    # SSL certificates (use Let's Encrypt)
    ssl_certificate /etc/letsencrypt/live/printhive.example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/printhive.example.com/privkey.pem;
    
    # Security headers
    add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
    add_header X-Frame-Options "SAMEORIGIN" always;
    add_header X-Content-Type-Options "nosniff" always;
    
    location / {
        proxy_pass http://localhost:3000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

3. Database Security

  • Back up database regularly
  • Encrypt database backups
  • Use strong passwords for local database access
  • Run database in read-only mode where applicable

4. Regular Maintenance

  • Keep Node.js and dependencies updated
  • Monitor logs for suspicious activity
  • Review user accounts and permissions regularly
  • Update Docker base image regularly

5. Access Control

  • Limit admin account creation
  • Use strong passwords or SSO
  • Enable MFA if available through OAuth provider
  • Regularly audit user roles

Known Limitations

  1. Rate Limiting: Not implemented - should be added at reverse proxy level
  2. Database Encryption: Application-level encryption not implemented - use full-disk encryption
  3. Audit Logging: Limited - consider implementing detailed audit trails
  4. DDOS Protection: Rely on reverse proxy and CDN
  5. Backup Integrity: Verify backups regularly

Security Roadmap

Future security improvements planned:

  • Rate limiting middleware
  • Request signing for API calls
  • Database-level encryption
  • Comprehensive audit logging
  • Security key/WebAuthn support
  • Automatic vulnerability scanning in CI/CD

References

Last Updated

January 13, 2026 - Comprehensive security audit completed

There aren’t any published security advisories