Skip to content
This repository was archived by the owner on Jan 28, 2026. It is now read-only.

Security: caioocesar/catscribe-translate-prototype

Security

SECURITY.md

πŸ” Security Features & Best Practices

Security Enhancements Implemented

1. API Key Encryption

Implementation: AES-256-CBC encryption for all API keys

How it works:

  • All API keys are encrypted before being stored in the SQLite database
  • Uses industry-standard AES-256-CBC encryption algorithm
  • Each encryption includes a random initialization vector (IV)
  • Keys are only decrypted when needed for API calls
  • Encryption key derived from machine-specific identifier

Affected fields:

  • deepl_api_key
  • openai_api_key
  • chatgpt_api_key

Code location:

  • backend/utils/encryption.js - Encryption utility
  • backend/models/Settings.js - Automatic encryption/decryption

Storage format: IV:EncryptedData (hex encoded)

2. Secure Key Storage

Database level:

  • API keys never stored in plain text
  • SQLite database file protected by OS file permissions
  • No API keys in logs or error messages

Application level:

  • Keys only loaded into memory when needed
  • Automatic garbage collection after use
  • No keys in frontend state longer than necessary

3. Environment Variables

Configuration: backend/.env

# Optional: Custom encryption key (recommended for production)
ENCRYPTION_KEY=your-256-bit-key-here

# Optional: Machine-specific identifier
MACHINE_ID=your-unique-machine-id

Best practice: Use environment variables for additional security layer

4. Frontend Security

Password fields:

  • All API key inputs use type="password"
  • Keys masked in UI
  • Never displayed in console logs

HTTPS recommendation:

  • For production deployment, always use HTTPS
  • Prevents man-in-the-middle attacks
  • Encrypts all data in transit

5. API Key Validation

Test Connection Feature:

  • Validates API keys before saving
  • Prevents storing invalid credentials
  • Shows success/failure feedback
  • Available in both Translation and Settings tabs

Security benefits:

  • Detects compromised keys early
  • Prevents unnecessary API charges
  • Validates before sensitive operations

Security Best Practices

For Users

  1. Protect Your API Keys

    • Never share your API keys
    • Don't commit .env files to version control
    • Rotate keys regularly
    • Use different keys for different applications
  2. Database Security

    • Keep backend/data/translator.db secure
    • Don't share database file
    • Backup encrypted, not plain text
    • Use OS-level file encryption if needed
  3. Network Security

    • Use on trusted networks
    • Consider VPN for public Wi-Fi
    • Don't expose ports to public internet
    • Use firewall rules
  4. Access Control

    • Keep your computer password-protected
    • Lock screen when away
    • Use full-disk encryption if available
    • Limit user access to application directory

For Developers

  1. Encryption Key Management

    # Generate secure encryption key
    node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"
    
    # Add to .env
    echo "ENCRYPTION_KEY=<your-key>" >> backend/.env
  2. Production Deployment

    • Use environment variables for all secrets
    • Enable HTTPS with valid certificates
    • Use reverse proxy (nginx/Apache)
    • Implement rate limiting
    • Add authentication if multi-user
  3. Database Backups

    # Backup database (still encrypted)
    cp backend/data/translator.db backups/translator_backup_$(date +%Y%m%d).db
  4. Audit Logs

    • Monitor API usage
    • Check for unusual patterns
    • Review failed authentication attempts

Testing Security

Automated Security Tests

The application includes automated tests that run on startup:

βœ“ Encryption/Decryption
βœ“ Settings Encryption for API Keys
βœ“ Database Connection
βœ“ All tables properly created

Run tests manually:

# Via API
curl http://localhost:5000/api/health/test

# Results show encryption is working

Manual Security Verification

  1. Verify Encryption:
# Check database - should see encrypted data
sqlite3 backend/data/translator.db "SELECT value FROM settings WHERE key='deepl_api_key';"
# Output should be encrypted (not plain text)
  1. Test API Key Protection:
    • Save an API key in Settings
    • Close and restart application
    • Verify key still works (decrypted properly)
    • Check database (should still be encrypted)

Security Checklist

Before using in production:

  • Generate custom ENCRYPTION_KEY
  • Set NODE_ENV=production in .env
  • Enable HTTPS
  • Set up firewall rules
  • Use strong OS passwords
  • Enable full-disk encryption
  • Backup database securely
  • Review API provider security docs
  • Test API key rotation
  • Monitor API usage logs

Threat Model

Threats Mitigated

βœ… Database Theft: Keys encrypted, useless without encryption key βœ… Memory Dumps: Keys cleared after use βœ… Network Sniffing: Use HTTPS in production βœ… Unauthorized Access: OS-level file permissions βœ… Key Leakage: Never in logs or console βœ… Insider Threats: Encrypted at rest

Threats to Be Aware Of

⚠️ Physical Access: Someone with physical access to running app ⚠️ Memory Analysis: Keys in memory during active translation ⚠️ OS Compromise: If OS compromised, encryption key accessible ⚠️ Side-Channel Attacks: Advanced timing/power analysis

Limitations

This is client-side security for a personal use application:

  • Not suitable for multi-tenant systems
  • Not enterprise-grade secret management
  • Encryption key stored locally
  • Best effort protection for personal use

For enterprise deployment, consider:

  • Hardware Security Modules (HSM)
  • Centralized secret management (HashiCorp Vault, AWS Secrets Manager)
  • Multi-factor authentication
  • Role-based access control
  • Audit logging
  • Intrusion detection systems

Security Updates

Version 1.0.0 (Current)

  • βœ… AES-256-CBC encryption for API keys
  • βœ… Secure password input fields
  • βœ… Test connection before save
  • βœ… Automated security tests
  • βœ… No keys in error messages
  • βœ… Encrypted database storage

Planned Future Enhancements

  • Optional master password
  • Key derivation function (PBKDF2)
  • Encrypted exports
  • Session timeout
  • Audit logging
  • 2FA for sensitive operations

Reporting Security Issues

If you discover a security vulnerability:

  1. DO NOT open a public issue
  2. Document the vulnerability
  3. Include steps to reproduce
  4. Describe potential impact
  5. Suggest a fix if possible

Remember: This is a personal-use application. Focus on protecting your own data first.

Additional Resources


Last Updated: November 2025
Security Level: Personal Use - Client-Side Encryption
Compliance: Not certified for regulated industries

There aren't any published security advisories