Summary
Coolify's PostgreSQL initialization flow insufficiently restricted script file paths, allowing authenticated users to write initialization files outside the intended directory.
In environments where database init scripts are executed automatically, a malicious user could leverage this path traversal to run arbitrary commands on the underlying server.
Affected context
The vulnerability appears in Coolify deployments that rely on its built-in PostgreSQL management and initialization scripting.
It is relevant when authenticated users can supply or influence initialization script names or locations, and when those scripts are later executed by the database startup process without additional validation.
The issue manifests at the boundary where application-level file creation meets underlying OS paths, especially in multi-tenant or shared Coolify instances.
Exploit preconditions
- Attack surface: Coolify's PostgreSQL management and initialization features exposed through the authenticated application interface.
- Required access: Valid authenticated access to a Coolify instance with permissions to configure or start PostgreSQL databases.
- Trigger point: Creation or regeneration of PostgreSQL initialization scripts via the
generate_init_scripts()routine, which writes files based on user-influenced filenames. - Why exploitation is possible: The filename handling lacks robust path normalization and restriction to a dedicated directory, enabling directory traversal sequences to escape the intended folder and deposit executable initialization content elsewhere that the startup process will run.
Why this happens
This issue stems from improper validation and normalization of file paths before writing initialization scripts.
User-controlled or user-influenced input is incorporated into filesystem paths without rejecting directory traversal patterns, symbolic link abuse, or other mechanisms that break confinement to a designated directory.
Conceptually, this maps to CWE-22: Improper Limitation of a Pathname to a Restricted Directory, where code assumes that a target directory boundary is enforced but fails to sanitize or canonicalize the path, allowing attackers to escape the intended location and place files in more sensitive locations.
Potential impact
- Authenticated users could write arbitrary files outside the intended PostgreSQL init directory.
- Attackers may place malicious shell or SQL scripts that are executed during database initialization.
- Arbitrary command execution on the database host under the privileges of the database or application service account.
- Escalation of access within the managed server, including tampering with application data or configuration.
- Establishment of persistence mechanisms by placing backdoored scripts or configuration files.
General mitigation guidance
Mitigation focuses on strict confinement of file operations and reduction of trust in user-supplied paths.
Defensive patterns include:
- Enforcing canonical path resolution and verifying that resulting paths reside strictly under a pre-defined, whitelisted directory.
- Rejecting any input that contains directory traversal sequences, absolute paths, or null bytes, and only allowing a constrained, validated filename set.
- Separating user-controlled names from actual filesystem paths by mapping logical identifiers to server-generated filenames.
- Ensuring that any automatically executed initialization scripts are sourced only from directories that the application fully controls and that are not writable by untrusted users.
- Running database initialization and management routines under least-privilege accounts with limited filesystem access to reduce the blast radius of misdirected writes.
How teams detect issues like this
Detection commonly involves both code-centric and operational approaches:
- Static analysis: Rules that flag direct concatenation of user input into filesystem paths, especially for initialization scripts or configuration files, without normalization and directory checks.
- Code review: Looking for file creation or write operations in database management components, ensuring they use hardened helper functions to validate paths and enforce directory boundaries.
- Configuration review: Verifying that init script directories are not world-writable and that only trusted components can modify startup scripts.
- Operational monitoring: Logging and alerting on unusual file creations near database binaries or configuration directories, and tracking unexpected changes to init scripts.
Automated secure coding tools and CI checks can be configured to detect directory traversal patterns and unsafe file path handling before deployment.

