Summary
A command injection vulnerability in Coolify's PostgreSQL healthcheck logic allows attacker-controlled database settings to be embedded directly into shell-form commands.
An authenticated user who can configure PostgreSQL connection parameters may inject arbitrary commands that execute inside the database container.
Affected context
The vulnerability appears in environments running Coolify versions prior to 4.0.0-beta.474 where PostgreSQL healthchecks are implemented as shell-form commands.
In these setups, user-configurable fields such as postgres_user and postgres_db are interpolated directly into command strings that run inside the PostgreSQL container.
The issue becomes relevant when users have permissions to create or edit database configurations and when these configurations are used to drive healthcheck or management commands.
Exploit preconditions
- Attack surface: Coolify PostgreSQL integration and healthcheck mechanism
- Required access: Authenticated access with the ability to define or modify PostgreSQL connection settings (e.g.,
postgres_user,postgres_db) - Trigger point: Execution of the generated PostgreSQL healthcheck command within the database container
- Why exploitation is possible: Unvalidated and unsanitized user-controlled values are embedded into shell-form commands, allowing shell metacharacters and additional commands to be interpreted by the shell.
Why this happens
The core problem stems from constructing shell commands by concatenating or interpolating user-supplied values without robust validation or escaping.
This maps to CWE-78: Improper Neutralization of Special Elements used in an OS Command, where attacker-controlled input is passed to a shell interpreter and treated as part of the command line.
Instead of treating PostgreSQL connection parameters as data passed to a safe API, the implementation relies on shell parsing, allowing crafted input to break out of the intended command and inject additional operations.
Potential impact
- An authenticated attacker may execute arbitrary shell commands within the PostgreSQL container.
- Attackers could read or modify data accessible from the compromised container.
- The attacker can establish persistence or deploy additional tooling inside the container.
- Depending on container privileges and network topology, the attacker could pivot to other services or hosts reachable from the database container.
- Application availability could be disrupted by stopping services, corrupting data, or exhausting resources.
General mitigation guidance
Effective mitigation focuses on eliminating the dependency on shell parsing for operational commands and strictly separating code from data.
Recommended defensive patterns include:
- Avoid constructing shell-form command strings with user-supplied values; instead use parameterized APIs (e.g., direct database drivers) or exec-form process invocation where arguments are passed as an array.
- Treat all configuration values, such as usernames and database names, as untrusted data and apply strict allowlists for expected formats (e.g., alphanumeric plus a small set of safe characters).
- Centralize command creation logic with a small, well-reviewed abstraction that handles quoting or, preferably, does not use a shell at all.
- Run containers with least privilege, minimizing filesystem, network, and OS capabilities to reduce blast radius if command execution occurs.
- Limit which roles or tenants are permitted to create or change sensitive connectivity parameters used by automated healthchecks or maintenance jobs.
How teams detect issues like this
Detection typically involves both code-centric and runtime approaches:
- Static analysis: Search for shell execution APIs (e.g.,
sh,bash,exec,child_process, or similar) where arguments are built from configuration fields likepostgres_userandpostgres_db. Flag any concatenation or interpolation into a single string. - Code review: Pay attention to healthcheck, monitoring, and automation code that often escapes direct security review; verify that configuration values are passed as data, not as part of shell command strings.
- Security policy enforcement: Introduce linters or CI policies that disallow shell-form command construction with untrusted input or require explicit justification and review for such patterns.
- Runtime monitoring: Observe container logs and command execution traces for unusual arguments or unexpected processes spawned by healthcheck routines, which may indicate attempted command injection.

