HIGH ssrf server sidefibercockroachdb

Ssrf Server Side in Fiber with Cockroachdb

Ssrf Server Side in Fiber with Cockroachdb — how this specific combination creates or exposes the vulnerability

Server-side request forgery (SSRF) in a Fiber service that uses CockroachDB can occur when user-supplied input is used to build database connection parameters or to drive HTTP requests on behalf of the service. CockroachDB connection strings often include hostnames, ports, and network addresses. If an attacker can influence these values — for example, by providing a malicious hostname that resolves to an internal service — the application may be tricked into connecting to unintended internal endpoints. In a typical Fiber app, this can happen when connection configuration is read from request parameters, headers, or query strings without strict validation.

Consider a handler that accepts a host query parameter and constructs a CockroachDB connection string dynamically:

// Unsafe: host from request directly used in connection string
host := c.QueryParam("host")
connStr := fmt.Sprintf("postgresql://root@%s:26257/defaultdb?sslmode=disable", host)
db, err := gorm.Open(postgres.Open(connStr), &gorm.Config{})

An attacker could supply host=internal-metadata-service.default.svc.cluster.local to reach a service that is not externally routable. Even if CockroachDB itself is not directly exploitable via SSRF, the application may be co-located with other internal services, and the database driver may follow redirects or use auxiliary network calls. Because middleBrick tests unauthenticated attack surfaces, it can flag endpoints where database connection parameters are influenced by client input, highlighting potential SSRF paths that could lead to unauthorized internal network probing.

Additionally, if the Fiber app uses HTTP clients to call external services based on user input, and those calls are co-hosted or share networking namespaces with CockroachDB clients, the SSRF surface may extend to database-related operations. middleBrick’s SSRF and related checks look for endpoints where network destinations are derived from user data, providing visibility into how an attacker might pivot from an HTTP SSRF to affect database-facing channels.

Cockroachdb-Specific Remediation in Fiber — concrete code fixes

To mitigate SSRR in a Fiber app using CockroachDB, ensure that all database connection parameters are static or explicitly configured from server-side sources, never derived from client-controlled input. Validate and whitelist allowed hosts if dynamic host selection is required, and avoid constructing connection strings via string concatenation or formatting with user data.

Use a fixed connection string defined in configuration or environment variables:

// Safe: connection string from environment, not user input
connStr := os.Getenv("COCKROACH_URL")
if connStr == "" {
    connStr = "postgresql://root@localhost:26257/defaultdb?sslmode=disable"
}
db, err := gorm.Open(postgres.Open(connStr), &gorm.Config{})
if err != nil {
    c.Status(fiber.StatusInternalServerError)
    return c.JSON(fiber.Map{"error": "unable to connect to database"})
}

If you must accept a hostname, enforce a strict allowlist and use a controlled mapping to a predefined set of connection strings:

// Safe: whitelisted allowed hosts mapped to predefined connection strings
allowed := map[string]string{
    "us-east": "postgresql://root@us-east-cockroach:26257/defaultdb?sslmode=disable",
    "eu-west": "postgresql://root@eu-west-cockroach:26257/defaultdb?sslmode=disable",
}
region := c.QueryParam("region")
connStr, ok := allowed[region]
if !ok {
    c.Status(fiber.StatusBadRequest)
    return c.JSON(fiber.Map{"error": "invalid region"})
}
db, err := gorm.Open(postgres.Open(connStr), &gorm.Config{})

Also ensure that any HTTP client used within the same service respects network boundaries and does not inadvertently forward requests to internal CockroachDB or other internal endpoints based on user input. Apply timeouts and disable unnecessary redirect behavior where appropriate.

Because middleBrick scans unauthenticated attack surfaces, it can highlight endpoints that accept network-related parameters and trace how they affect downstream connections, helping you identify and isolate SSRF risks tied to CockroachDB deployment patterns.

Frequently Asked Questions

Can SSRF in a Fiber app lead to direct CockroachDB exposure?
Direct exposure is unlikely because CockroachDB does not speak HTTP, but SSRF can allow an attacker to probe internal network addresses that host CockroachDB nodes if connection parameters are derived from user input.
How does middleBrick detect SSRF risks related to database connections?
middleBrick tests endpoints where network destinations can be influenced by user data, such as host or URL parameters used in database connection logic, and reports findings that may enable internal network probing.