Skip to content

Latest commit

 

History

History
89 lines (78 loc) · 6.55 KB

File metadata and controls

89 lines (78 loc) · 6.55 KB

Attack Surface Analysis for mongodb/mongo

Description: Attackers manipulate application queries by injecting malicious code or commands into user-supplied data, leading to unauthorized data access, modification, or execution of arbitrary code. * How MongoDB Contributes: MongoDB's flexible query language (especially with features like $where and server-side JavaScript) can be exploited if user input is not properly sanitized. The Go driver is the conduit for these queries. * Example: * NoSQL Injection: A user input field for searching is directly used in a bson.M filter: filter := bson.M{"name": userInput}. If userInput is {$ne: null}, the query returns all documents. * Server-Side JavaScript Injection: User input in a $where clause: bson.M{"\$where": "this.name == '" + userInput + "'"} . If userInput is ' || true || ', the clause always evaluates to true. * Impact: * Data breach (unauthorized access). * Data modification/deletion. * Arbitrary code execution (server-side JavaScript). * Denial of service. * Risk Severity: Critical * Mitigation Strategies: * Parameterized Queries: Always use the Go driver's bson.D, bson.M, and builder methods. Never concatenate user input directly. * Input Validation: Strictly validate and sanitize all user input. Use whitelisting. * Avoid Server-Side JavaScript: Minimize or eliminate its use. If unavoidable, apply extremely rigorous input validation. * Principle of Least Privilege: Database users should have minimal permissions.

Description: Attackers gain access to or manipulate the connection string, allowing unauthorized database access or redirection to a malicious server. * How MongoDB Contributes: The connection string contains all information to connect to a MongoDB instance, including credentials. The Go driver uses this string. * Example: * Exposure: Hardcoded connection string in publicly accessible source code. * Injection: User input directly used to construct part of the connection string without validation. * Impact: * Unauthorized database access. * Data breach, modification, or deletion. * Connection to a malicious server. * Risk Severity: Critical * Mitigation Strategies: * Secure Storage: Never hardcode connection strings. Use environment variables, secure configuration files, or a secrets management service. * Secure Transmission: Use TLS/SSL for all connections. * Input Validation (if applicable): If any part of the connection string is influenced by user input, strictly validate it. Use the driver's connection option builders. * Principle of Least Privilege: Use database users with minimal permissions.

Description: Data transmitted between the application and MongoDB is unencrypted, vulnerable to eavesdropping. * How MongoDB Contributes: MongoDB supports both encrypted and unencrypted connections. The Go driver's configuration determines which is used. * Example: The connection string omits tls=true, and the server doesn't enforce TLS/SSL. * Impact: * Data breach (sensitive data intercepted). * Man-in-the-Middle (MITM) attacks. * Risk Severity: High * Mitigation Strategies: * Enforce TLS/SSL: Always use TLS/SSL. Configure the MongoDB server to require it. * Connection String: Use tls=true (or equivalent). * Certificate Verification: Configure the Go driver to verify the server's certificate. * Strong Ciphers: Use strong, modern TLS/SSL ciphers and protocols (TLS 1.2 or 1.3).

Description: Attackers overwhelm the MongoDB server or the application's connection pool, preventing legitimate access. * How MongoDB Contributes: MongoDB is susceptible to resource exhaustion. The Go driver's connection pooling and query execution are potential targets. * Example: * Connection Exhaustion: Repeatedly opening connections without closing them. * Resource-Intensive Queries: Complex, unindexed queries consuming excessive resources. * Impact: * Application unavailability. * Service disruption. * Risk Severity: High * Mitigation Strategies: * Connection Pooling: Configure the Go driver's connection pool appropriately. Set maximum connection limits. * Query Timeouts: Use $maxTimeMS and driver timeouts. * Rate Limiting: Implement rate limiting on the application side. * Input Validation: Prevent excessively long/complex queries. * Indexing: Optimize queries with indexes. * Resource Monitoring: Monitor server resources and set alerts. * MongoDB Server Configuration: Limit resource consumption (e.g., maxConns).

Description: Sensitive data is stored unencrypted at rest, vulnerable if the database is compromised. * How MongoDB Contributes: MongoDB doesn't automatically encrypt data at rest (except MongoDB Enterprise with encryption at rest). The Go driver supports Client-Side Field Level Encryption (CSFLE). * Example: PII stored in plain text. * Impact: * Data breach. * Compliance violations. * Risk Severity: High * Mitigation Strategies: * Client-Side Field Level Encryption (CSFLE): Use the Go driver's CSFLE to encrypt sensitive fields before sending them to the server. * MongoDB Enterprise Encryption at Rest: If using Enterprise, enable encryption at rest. * Data Minimization: Store only essential data. * Tokenization: Replace sensitive data with tokens.