Summary
AVideo versions prior to 8.0 contain a SQL injection vulnerability where user-controlled sort parameter keys are used directly as SQL column identifiers in an ORDER BY clause.
Because identifier names are not validated or whitelisted, an attacker can manipulate the generated SQL and potentially extract or tamper with data when the affected queue endpoints are exposed.
Affected context
This vulnerability occurs in AVideo deployments using versions prior to 8.0 where the getSqlFromPost() method in Object.php processes POST requests that include a sort array.
The issue is most relevant for endpoints like queue.json.php and index.php that accept user-driven sorting options and directly translate them into SQL ORDER BY clauses.
It becomes risky when these endpoints are reachable from untrusted networks or when no additional filtering, WAF rules, or access controls are enforced on the sort parameters.
Exploit preconditions
- Attack surface: HTTP endpoints that invoke
getSqlFromPost()and accept$_POST['sort']for dynamic ordering (e.g., queue views). - Required access: Ability to send crafted POST requests to the affected endpoints; no special privileges are inherently required beyond reachability.
- Trigger point: Submission of POST data where
sort[*]keys are set to attacker-controlled values that are incorporated into the ORDER BY clause. - Why exploitation is possible: The application uses
$_POST['sort']array keys directly as SQL identifiers without a whitelist or structural validation, and identifier-oriented injection is not mitigated byreal_escape_string(), which only addresses string literals.
Why this happens
The root cause is the direct interpolation of untrusted input as SQL identifiers in an ORDER BY clause.
The getSqlFromPost() method trusts the keys of the $_POST['sort'] array as valid column names and concatenates them into SQL, relying on real_escape_string() which is designed for string literal escaping, not for controlling which identifiers are allowed.
This maps to CWE-89: Improper Neutralization of Special Elements used in an SQL Command, where user-controlled data influences SQL structure instead of being confined to parameterized values.
At an abstract level, the insecure pattern is building dynamic SQL statements with unbounded user input for structural elements (columns, directions) rather than using a fixed schema and validated, whitelisted options.
Potential impact
- An attacker could modify ORDER BY clauses to alter query behavior, potentially chaining into broader SQL injection depending on database and query structure.
- Sensitive data may be exposed through crafted injection payloads that change what is returned by a query.
- Application logic relying on predictable ordering can be subverted, potentially aiding in data enumeration or logic abuse.
- In certain database configurations, successful SQL injection could lead to data modification or deletion, impacting integrity and availability.
General mitigation guidance
Effective mitigation focuses on removing untrusted control over SQL structure, especially identifiers:
- Replace dynamic identifier construction with strict whitelisting: map allowed sort keys to a fixed set of known column names and directions.
- Use parameterized queries for values and keep SQL structure (tables, columns, clauses) static in code, not derived directly from user input.
- Normalize and validate sort inputs against a small, enumerated set (e.g.,
title,created_at,views) instead of trusting arbitrary keys from$_POST['sort']. - Apply least-privilege database accounts so that even if a query is influenced, the account cannot perform destructive or cross-schema operations.
- Where possible, layer network and application-level access controls so that administrative or queue endpoints are not exposed to the open internet.
How teams detect issues like this
Detection typically combines code-centric analysis with behavior monitoring:
- Static analysis: Search for direct concatenation of
$_POST,$_GET, or other request parameters into SQL strings, especially around ORDER BY, LIMIT/OFFSET, and other structural clauses. - Code review cues: Flag any use of dynamic column names or directions derived from user input without a whitelist or explicit mapping; review utility functions like
getSqlFromPost()that centralize query building. - Automated scanners: Use DAST and SAST tools configured with rules for SQL injection patterns, focusing on identifier injection as well as literal injection.
- Runtime monitoring: Inspect database logs for anomalous ORDER BY patterns, unexpected function calls, or error messages triggered by malformed sort parameters.

