Summary
A SQL injection vulnerability in Piwigo's date filter parameters allows attacker-controlled input to be concatenated directly into SQL queries without escaping or type validation.
When exploited, an unauthenticated attacker could extract the full database contents, including user password hashes, by manipulating specific web service parameters.
Affected context
This vulnerability occurs in Piwigo's web service layer within ws_std_image_sql_filter(), where four date filter parameters are used to build image selection queries.
The issue is present when the application:
- Accepts
f_min_date_available,f_max_date_available,f_min_date_created, andf_max_date_createdfrom HTTP requests - Concatenates these values directly into SQL strings
- Does not enforce robust server-side type checks, whitelisting, or parameter binding
In this context, maliciously crafted values can influence the structure of the SQL query instead of being treated purely as data.
Exploit preconditions
- Attack surface: Public HTTP endpoints exposing Piwigo's web service features that rely on
ws_std_image_sql_filter(). - Required access: No authentication required; the vulnerable parameters are reachable by unauthenticated users in affected configurations.
- Input vector: Attacker supplies crafted values for:
f_min_date_availablef_max_date_availablef_min_date_createdf_max_date_created- Trigger point: The server constructs and executes SQL queries using these parameters without escaping or parameterization.
- Why exploitation is possible: User-controlled strings are directly concatenated into SQL, allowing the attacker to alter query logic, access additional tables, and exfiltrate data.
Why this happens
The root cause is the construction of SQL queries by string concatenation using untrusted input, without proper escaping, parameter binding, or type enforcement.
Instead of treating the four date parameters strictly as typed values (e.g., validated date strings bound to placeholders), the implementation injects them directly into the query text.
This pattern corresponds to CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection'), where special characters or segments in user input can terminate or extend SQL statements.
The vulnerability exists at the abstraction level of query construction, not in the database engine itself, and is independent of the specific SQL dialect used.
Potential impact
- An attacker may read arbitrary database tables, including users and configuration data.
- An attacker could access user password hashes for offline cracking and potential account takeover.
- An attacker may enumerate internal schema details (table names, column names, relationships).
- An attacker could combine data exposure with other weaknesses to escalate to full application compromise.
- Depending on the database and query context, an attacker might be able to modify or delete data.
General mitigation guidance
Effective mitigation focuses on eliminating direct concatenation of untrusted input into SQL and enforcing strict data typing:
- Adopt parameterized queries or prepared statements for all database access paths, including filters and search endpoints.
- Treat date filters as typed values; validate them against strict server-side date formats and reject or normalize invalid input.
- Use query builders or ORM layers that generate parameterized SQL by default, reducing the need for manual string assembly.
- Centralize database access logic so that low-level query construction is not reimplemented in multiple places.
- Apply least-privilege to the database account used by the application, limiting which tables and operations can be performed.
- Implement robust error handling that avoids exposing detailed SQL errors or schema information in responses.
How teams detect issues like this
Organizations can detect similar SQL injection risks using a mix of code-centric and runtime approaches:
- Static analysis: Configure rules to flag:
- String concatenation involving SQL keywords and variables derived from HTTP request parameters.
- Direct interpolation of user-controlled values into
WHERE,ORDER BY, orLIMITclauses. - Code review: During manual reviews, focus on:
- Functions that construct dynamic SQL, especially filter or search helpers (like
ws_std_image_sql_filter()). - Endpoints that are unauthenticated but interact with the database.
- Inconsistent use of parameterized queries across the codebase.
- Security testing: Use automated DAST or fuzzing tools to probe parameters with SQL meta-characters and detect anomalous responses.
- Logging and monitoring: Monitor database query logs for:
- Unusual patterns, such as concatenated literals, tautological conditions, or union-like constructs.
- Sudden spikes in query volume or schema-discovery queries.
Applying these strategies in CI/CD (e.g., via SAST tools or pre-merge checks) can help prevent similar vulnerabilities from being introduced.

