Summary
The Piwigo installer writes database configuration values from POST parameters directly into a PHP file, without robust validation or sanitization.
On PHP 8+, legacy addslashes() protection is bypassed, allowing unauthenticated attackers to inject arbitrary PHP code that is executed on every page load.
Affected context
This vulnerability appears during fresh installations or reconfiguration workflows of Piwigo up to version 16.3.0, especially when running on PHP 8 or later.
The installer accepts database-related POST parameters and persists them into local/config/database.inc.php as executable PHP, assuming the inputs are benign.
In environments where the installer is exposed over the network and not restricted to trusted administrators, arbitrary user-supplied data can end up embedded in server-side code.
Exploit preconditions
- Attack surface: Publicly accessible Piwigo installation or setup scripts.
- Required access: Network access to the installer endpoint; no prior authentication needed when installation is not yet locked down.
- Trigger point: Submission of crafted POST parameters (e.g.,
prefix,dbpasswd,dbhost,dbname,dbuser) during the installation or configuration process. - Why exploitation is possible: The installer performs only legacy escaping via
addslashes()conditional onget_magic_quotes_gpc(), which no longer exists on PHP 8+, so raw input is interpolated into a PHP configuration file and then executed.
Why this happens
The underlying bug is a failure to treat installer configuration input as untrusted and potentially hostile data.
Instead of separating data from code or using a non-executable configuration format, the installer injects user-controlled strings directly into a PHP source file with inadequate validation.
The protection strategy relies on deprecated behavior (get_magic_quotes_gpc()), meaning that on modern PHP versions the input is effectively unescaped and can break out of string contexts to form executable PHP statements.
This pattern maps to CWE-20: Improper Input Validation, where insufficient checks and assumptions about input safety allow malicious content to be processed as trusted configuration and ultimately as code.
Potential impact
- An attacker may execute arbitrary PHP code on the server with the privileges of the web application.
- An attacker could create backdoors that persist across updates by embedding malicious logic in the configuration file.
- An attacker can access or modify application data, including photo libraries, user records, and session information.
- An attacker may escalate impact by reading local files, interacting with the underlying OS, or pivoting to adjacent services, depending on server configuration.
- An attacker could disrupt site availability by introducing fatal errors or destructive behaviors in the executed configuration code.
General mitigation guidance
Effective mitigation centers on preventing user input from becoming executable code and tightening trust boundaries around installation workflows.
Common defensive patterns include:
- Using non-executable configuration formats (e.g., INI, JSON, or environment variables) rather than PHP source files for storing database credentials and settings.
- Strictly validating installer inputs against expected formats (hostnames, usernames, alphanumeric prefixes) and rejecting any content containing control characters or PHP-specific syntax.
- Applying context-aware escaping when generating configuration files so that untrusted data cannot break out of quoted strings.
- Restricting access to installation and setup scripts to trusted administrators through access controls, temporary firewall rules, or one-time tokens.
- Locking or disabling the installer after initial setup so configuration cannot be re-written through public endpoints.
How teams detect issues like this
Detection typically focuses on identifying unsafe handling of configuration inputs and execution of dynamically generated files:
- Static analysis rules can flag patterns where user-controlled data is concatenated into PHP files or passed through weak escaping routines tied to deprecated functions.
- Code reviews should question any design that uses executable code files to store configuration and look for direct interpolation of HTTP parameters.
- Security linters or policy engines can enforce a rule that configuration is stored in non-executable formats and that installer endpoints validate and sanitize all inputs.
- Runtime monitoring can watch for unexpected modifications to
local/config/database.inc.phpor other configuration files, alerting when they change outside planned maintenance.

