Skip to content

Security: gusdeyw/pgbridge-go

Security

SECURITY.md

Security Improvements and Best Practices

This document outlines the security improvements implemented in PGBridge-Go and provides recommendations for production deployment.

Security Fixes Implemented

1. Authentication Security

  • Fixed: Replaced plain text password comparison with bcrypt hashing
  • Added: Constant-time password comparison to prevent timing attacks
  • Added: Rate limiting for authentication attempts (5 attempts per 5 minutes per IP)
  • Added: Input validation for username and password lengths
  • Added: Proper password strength requirements

2. Credential Management

  • Removed: Hardcoded plain text credentials
  • Added: Bcrypt-hashed default admin credentials
  • Added: Environment variable support for admin credentials
  • Added: Secure credential loading mechanism

3. Input Validation

  • Added: Comprehensive input validation for user registration
  • Added: Username format validation (alphanumeric, underscore, dash only)
  • Added: Password complexity requirements
  • Added: Input sanitization to prevent injection attacks

4. Security Headers

  • Added: Complete security headers middleware including:
    • X-Frame-Options (DENY) - prevents clickjacking
    • X-Content-Type-Options (nosniff) - prevents MIME type sniffing
    • X-XSS-Protection - enables browser XSS protection
    • Content-Security-Policy - controls resource loading
    • Referrer-Policy - controls referrer information
    • Permissions-Policy - restricts browser features

5. Dependency Updates

  • Updated: All dependencies to latest secure versions
  • Resolved: Known vulnerability issues in outdated packages

Production Security Checklist

Required Actions Before Production:

  1. Change Default Credentials

    # Generate a secure password hash:
    go run -c "package main; import \"golang.org/x/crypto/bcrypt\"; import \"fmt\"; func main() { hash, _ := bcrypt.GenerateFromPassword([]byte(\"YOUR_SECURE_PASSWORD\"), bcrypt.DefaultCost); fmt.Println(string(hash)) }"

    Set ADMIN_USERNAME and ADMIN_PASSWORD_HASH environment variables.

  2. Generate Secure Master Key

    # Generate a 32-byte encryption key:
    openssl rand -hex 32

    Set the MASTER_KEY environment variable.

  3. Enable HTTPS

    • Uncomment the Strict-Transport-Security header in security_headers.go
    • Use a reverse proxy like Nginx with SSL certificates
    • Update Content-Security-Policy to use 'https:' sources only
  4. Database Security

    • Use strong database passwords
    • Restrict database access to application only
    • Enable database connection encryption (SSL/TLS)
    • Regular database backups
  5. Environment Variables

    • Never commit .env files to version control
    • Use proper secret management in production
    • Rotate credentials regularly

Additional Security Recommendations:

  1. Logging and Monitoring

    • Implement comprehensive logging for security events
    • Monitor for suspicious authentication attempts
    • Set up alerts for security violations
  2. Network Security

    • Use firewalls to restrict access
    • Implement DDoS protection
    • Use VPN for administrative access
  3. Regular Security Audits

    • Scan for dependency vulnerabilities regularly
    • Perform periodic security assessments
    • Keep dependencies up to date
  4. Backup and Recovery

    • Regular encrypted backups
    • Test backup restoration procedures
    • Document incident response procedures

Environment Variables Configuration

# Required for production
MASTER_KEY=your_32_byte_hex_key_here
ADMIN_USERNAME=your_admin_username
ADMIN_PASSWORD_HASH=your_bcrypt_hashed_password

# Database (use strong credentials)
DB_HOST=your_db_host
DB_PORT=5432
DB_USER=secure_db_user
DB_PASSWORD=secure_db_password
DB_NAME=your_db_name

# Application
APP_PORT=5000
DEFAULT_CALLBACK=https://yourdomain.com/callback

Security Contact

For security-related issues or questions, please follow responsible disclosure practices and contact the maintainers privately before public disclosure.

Security Updates

This application has been audited and updated as of December 2024. Regular security reviews should be conducted, and this document should be updated accordingly.

There aren’t any published security advisories