Skip to main content

Common Misconfiguration

Exposed NoSQL database credentials can lead to data breaches, ransomware attacks, and complete database compromise.

Vulnerable Example

Secure Example

Detection Patterns

  • MongoDB URI: mongodb(\+srv)?://[^:]+:[^@]+@
  • Redis URL: redis://[^:]*:[^@]+@
  • Elasticsearch: https?://[^:]+:[^@]+@.*:9200
  • CouchDB: https?://[^:]+:[^@]+@.*:5984

Prevention Best Practices

  1. Use Secrets Management: Never hardcode credentials. Load them from environment variables or a secrets manager (like HashiCorp Vault, AWS Secrets Manager, etc.) at runtime.
  2. Implement Connection Pooling: Use a connection pool to efficiently manage and reuse database connections, reducing the overhead of repeated authentication.
  3. Use SSL/TLS: Encrypt all data in transit between your application and the database to prevent sniffing.
  4. Enforce Strong Authentication: Don’t run with authentication disabled. Use modern, strong mechanisms like SCRAM-SHA-256 for MongoDB.
  5. Implement IP Whitelisting: Configure your database (or its firewall/security group) to only accept connections from your application’s specific IP addresses.
  6. Use Least Privilege: Create dedicated database users for your application that only have the permissions they need (e.g., readWrite, not dbAdmin).
  7. Monitor Access: Log and alert on failed login attempts and connections from unexpected sources.
  8. Implement High Availability: Use features like replica sets (MongoDB) or Sentinel (Redis) to ensure your database is resilient to failure.
  9. Audit and Rotate Credentials: Regularly audit who has access and automatically rotate all passwords and API keys.