Ssrf in Cassandra
How SSRF Manifests in Cassandra
Server-Side Request Forgery (SSRF) in Cassandra environments typically occurs when application code constructs database queries or connection strings using untrusted user input without proper validation. Cassandra's native drivers and connection patterns create specific attack surfaces that attackers can exploit.
A common vulnerability pattern involves applications that accept user-provided keyspace or table names and directly interpolate them into Cassandra queries. For example, an application might construct a query like:
const query = `SELECT * FROM ${userProvidedKeyspace}.${userProvidedTable}`;When user input flows into query construction, attackers can manipulate the input to target internal Cassandra nodes or services. A malicious user might provide input like:
userProvidedKeyspace = 'system';
userProvidedTable = 'local' UNION SELECT * FROM system.peersThis can expose internal Cassandra metadata, including node IPs, rack information, and cluster topology. More sophisticated attacks might target Cassandra's native transport protocol on port 9042 to enumerate internal services.
Another Cassandra-specific SSRF vector involves the driver's contact point resolution. Applications often accept connection strings or host lists from configuration files or environment variables. If these inputs aren't properly validated, attackers can inject internal service endpoints that the Cassandra driver will attempt to connect to, effectively turning the database driver into an SSRF proxy.
Authentication bypass through SSRF is particularly concerning in Cassandra. The driver's default behavior of attempting multiple contact points can be exploited to probe internal networks. An attacker might craft requests that cause the application to attempt connections to internal IPs like 10.0.0.1, 192.168.1.1, or even localhost, potentially exposing services that should never be accessible from the public internet.
Cassandra-Specific Detection
Detecting SSRF vulnerabilities in Cassandra applications requires both static analysis and runtime scanning. Static analysis should focus on identifying code patterns where user input flows into database connection strings or query construction.
middleBrick's scanning engine specifically tests for Cassandra SSRF vulnerabilities by examining how applications handle contact points and query construction. The scanner attempts to inject various payloads into connection strings and query parameters to identify if the application attempts to connect to internal services.
Key detection patterns include:
- Monitoring for attempts to connect to non-standard Cassandra ports (e.g., 9042 for CQL, 7000/7001 for native transport)
- Detecting queries that include system keyspaces like 'system', 'system_auth', 'system_distributed'
- Identifying attempts to resolve internal DNS names or IP addresses
- Checking for exposure of internal Cassandra metadata through error messages or query results
Runtime detection should also monitor network traffic patterns. Tools like Wireshark or network security monitoring solutions can detect when Cassandra drivers attempt connections to unexpected internal IPs. The presence of traffic to RFC 1918 addresses (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16) from application servers that shouldn't communicate with internal networks is a strong indicator of SSRF exploitation.
middleBrick's API security scanner automatically tests for these patterns by submitting crafted payloads to your API endpoints and monitoring the resulting network behavior. The scanner can identify if your application's Cassandra integration is vulnerable to SSRF without requiring any credentials or access to your database.
Cassandra-Specific Remediation
Remediating SSRF vulnerabilities in Cassandra applications requires a defense-in-depth approach. The most effective strategy combines input validation, secure configuration, and proper network segmentation.
Input validation should be implemented at multiple layers. First, validate all user-provided keyspace and table names against a whitelist of allowed values. For example:
const allowedKeyspaces = ['myapp_data', 'myapp_logs'];
const allowedTables = ['users', 'orders', 'products'];
function validateKeyspaceAndTable(ks, table) {
if (!allowedKeyspaces.includes(ks)) {
throw new Error('Invalid keyspace');
}
if (!allowedTables.includes(table)) {
throw new Error('Invalid table');
}
return true;
}For connection string validation, implement strict parsing and validation of contact points. Only allow connections to explicitly configured Cassandra nodes:
const allowedContactPoints = ['cassandra1.internal', 'cassandra2.internal'];
function validateContactPoints(input) {
const parsed = parseContactPoints(input); // your parsing logic
for (const point of parsed) {
if (!allowedContactPoints.includes(point)) {
throw new Error('Invalid contact point');
}
return parsed;
}Network segmentation is critical for preventing SSRF exploitation. Deploy Cassandra nodes in a dedicated VPC or network segment with strict firewall rules. Only allow application servers to communicate with Cassandra nodes on the required ports (9042 for CQL, 7000/7001 for native transport).
Configure Cassandra's native transport settings to bind only to specific interfaces rather than all interfaces. In cassandra.yaml:
# Bind to specific IP instead of all interfaces
native_transport_address: 10.0.1.100
# Disable native transport on nodes that don't need it
native_transport_enabled: falseImplement proper error handling to prevent information leakage. Generic error messages should be returned instead of detailed Cassandra error information that might reveal internal network structure or database schema.
For applications using the DataStax Java driver or similar, configure strict contact point validation and disable automatic discovery of nodes. This prevents the driver from attempting connections to arbitrary hosts that might be injected through SSRF attacks.
Related CWEs: ssrf
| CWE ID | Name | Severity |
|---|---|---|
| CWE-918 | Server-Side Request Forgery (SSRF) | CRITICAL |
| CWE-441 | Unintended Proxy or Intermediary (Confused Deputy) | HIGH |