HIGH missing tlsmongodb

Missing Tls in Mongodb

How Missing TLS Manifests in MongoDB

Missing TLS in MongoDB environments creates multiple attack vectors that directly exploit the database's communication protocols. When MongoDB instances accept unencrypted connections, attackers can intercept traffic between applications and the database, exposing sensitive data in transit. This vulnerability is particularly dangerous in cloud environments where MongoDB instances are often exposed to the internet without proper network segmentation.

The most common attack pattern involves man-in-the-middle (MITM) attacks where an attacker positioned on the same network segment can intercept database queries and responses. Since MongoDB's wire protocol transmits data in cleartext when TLS is disabled, credentials, query parameters, and result sets are all exposed. Attackers can capture authentication credentials during the initial connection handshake, then use these credentials to establish their own connections to the database.

Another critical attack pattern involves database enumeration through unencrypted connections. Without TLS, attackers can use tools like mongostat or custom scripts to probe MongoDB instances, discovering database names, collection structures, and document contents. This reconnaissance phase often precedes more sophisticated attacks like data exfiltration or ransomware deployment.

Replica set communication represents another significant risk vector. MongoDB replica sets use internal replication protocols that, when unencrypted, allow attackers to intercept data synchronization traffic. This can reveal not just current data but also historical changes and transaction logs. In multi-region deployments, unencrypted replication traffic traveling across public networks becomes particularly vulnerable.

Connection string exposure through application logs or error messages creates additional risks. When applications connect to MongoDB without TLS, connection strings containing hostnames, ports, and sometimes credentials may appear in plaintext logs. These logs can be accessed by unauthorized personnel or exposed through application errors, providing attackers with the information needed to connect directly to the database.

MongoDB-Specific Detection

Detecting missing TLS in MongoDB environments requires examining both configuration files and network traffic patterns. The primary detection method involves scanning MongoDB instances for their TLS configuration status. MongoDB exposes this information through the buildInfo command and connection metadata, allowing security scanners to determine whether TLS is properly configured.

Network-based detection focuses on identifying MongoDB instances that accept connections on standard ports (27017, 27018, 27019) without requiring TLS. Security scanners can attempt connections to these ports and analyze the server's response to determine encryption requirements. MongoDB instances configured without TLS will accept plaintext connections and respond with protocol negotiation messages that don't include TLS requirements.

Configuration file analysis provides another detection vector. MongoDB's configuration files (mongod.conf, configsvr.conf) contain TLS-related settings that can be examined for proper configuration. Key settings include net.tls.mode, net.tls.certificateKeyFile, and net.tls.CAFile. Missing or misconfigured values indicate potential TLS vulnerabilities.

middleBrick's API security scanner includes specialized MongoDB TLS detection that goes beyond basic port scanning. The scanner attempts to establish connections to MongoDB endpoints and analyzes the server's TLS negotiation behavior. It checks for proper certificate validation, cipher suite support, and TLS version compatibility. The scanner also examines MongoDB-specific headers and response patterns that indicate whether encryption is enforced at the protocol level.

For MongoDB Atlas and cloud-managed instances, detection involves examining the service's network security settings through API endpoints. These managed services often provide TLS configuration through web interfaces, but the underlying network settings must still be verified to ensure encryption is actually enforced rather than merely configured.

Application-level detection examines how MongoDB connections are established in code. Many applications use MongoDB drivers that may have TLS disabled by default or through configuration. Scanning application code and configuration files can reveal connections that bypass TLS requirements, even when the database server itself is properly configured.

MongoDB-Specific Remediation

Remediating missing TLS in MongoDB requires both server-side configuration and application-level changes. The primary server-side fix involves enabling TLS mode in MongoDB's configuration. For standalone instances, add these settings to mongod.conf:

net:
tls:
mode: requireTLS
certificateKeyFile: /path/to/server.pem
certificateKeyFilePassword: password
CAFile: /path/to/ca.pem
disabledProtocols: TLS1.0,TLS1.1
minimumTLSVersion: TLS1.2

This configuration enforces TLS for all connections and specifies modern TLS versions while rejecting outdated protocols. The requireTLS mode prevents any unencrypted connections, ensuring all traffic is encrypted.

For replica sets, TLS must be configured on all members consistently. Each member needs its own certificate, and the replica set configuration must include TLS settings. The net.tls.clusterFile option specifies a PEM file containing all member certificates, enabling encrypted internal replication traffic.

Application-level remediation involves updating MongoDB driver configurations to enforce TLS connections. Using the official MongoDB Node.js driver as an example:

const { MongoClient } = require('mongodb');

const client = new MongoClient('mongodb://your-host:27017', {
ssl: true,
sslValidate: true,
sslCA: fs.readFileSync('/path/to/ca.pem'),
checkServerIdentity: true,
minTLSVersion: 'TLS1.2'
});

This configuration ensures the application verifies server certificates and uses modern TLS versions. Similar configurations exist for other language drivers, with options for certificate validation, cipher suites, and TLS version requirements.

Certificate management represents a critical remediation aspect. MongoDB requires proper certificate chains with valid expiration dates and correct subject alternative names (SANs). Self-signed certificates should be avoided in production environments. Instead, use certificates from trusted certificate authorities that include the database server's hostname in the SAN field.

Network-level controls provide additional protection. Configure firewalls to block port 27017 on public interfaces, allowing MongoDB connections only from trusted networks or through VPN tunnels. This defense-in-depth approach ensures that even if TLS configuration is temporarily compromised, network access remains restricted.

For MongoDB Atlas and cloud services, remediation involves enabling the service's built-in encryption features through the management console. These services typically provide automatic certificate management and enforce TLS connections by default, but verification through API scanning ensures the configuration is properly applied.

Regular security scanning with tools like middleBrick helps verify that TLS configurations remain effective over time. The scanner can detect configuration drift, expired certificates, or changes that might weaken encryption requirements. Continuous monitoring ensures that remediation efforts remain effective as environments evolve.

Related CWEs: encryption

CWE IDNameSeverity
CWE-319Cleartext Transmission of Sensitive Information HIGH
CWE-295Improper Certificate Validation HIGH
CWE-326Inadequate Encryption Strength HIGH
CWE-327Use of a Broken or Risky Cryptographic Algorithm HIGH
CWE-328Use of Weak Hash HIGH
CWE-330Use of Insufficiently Random Values HIGH
CWE-338Use of Cryptographically Weak PRNG MEDIUM
CWE-693Protection Mechanism Failure MEDIUM
CWE-757Selection of Less-Secure Algorithm During Negotiation HIGH
CWE-261Weak Encoding for Password HIGH

Frequently Asked Questions

What happens if MongoDB TLS certificates expire?
When MongoDB TLS certificates expire, clients with strict certificate validation will be unable to connect to the database. MongoDB will continue accepting connections, but modern drivers with sslValidate: true will reject them. This creates application downtime until certificates are renewed. Certificate rotation should be automated with at least 30 days of overlap between old and new certificates to prevent service interruptions.
Can I use self-signed certificates for MongoDB TLS?
Self-signed certificates are technically supported but not recommended for production. They require distributing the CA certificate to all clients and don't provide the same trust guarantees as certificates from public CAs. For internal environments, self-signed certificates can work if properly managed, but they increase administrative overhead and create risks if the CA certificate is compromised. Public CAs provide better scalability and trust verification.