Summary
FacturaScripts contained a critical SQL injection vulnerability in its autocomplete functionality, where user-controlled parameters were directly embedded into SQL queries.
An authenticated attacker could abuse this flaw to extract sensitive data from the database, including user credentials, configuration values, and stored business records whenever autocomplete endpoints are invoked with crafted input.
Affected context
The vulnerability occurs in FacturaScripts deployments that expose autocomplete features backed by the CodeModel::all() method.
In affected versions, this method constructs SQL queries by concatenating request parameters coming from authenticated users, without applying adequate validation, sanitization, or parameter binding.
Installations where users have access to autocomplete-driven forms or search fields, especially in multi-user or internet-facing environments, are more exposed to this risk.
Exploit preconditions
- Attack surface: HTTP endpoints implementing autocomplete or search behavior that rely on
CodeModel::all(). - Required access: Valid authenticated user account with permission to use affected autocomplete features (no special admin privileges are necessarily required).
- Trigger point: Submission of crafted input values in autocomplete-related parameters, which are passed directly into SQL query construction.
- Why exploitation is possible: The implementation concatenates user-supplied data into SQL strings without using prepared statements or robust input validation, allowing attackers to alter the intended query logic and read arbitrary data.
Why this happens
This issue stems from building SQL queries through string concatenation using untrusted parameters inside CodeModel::all().
Because the input is not strictly validated (CWE-20) and is incorporated directly into SQL expressions (CWE-89), the database interprets parts of the user input as executable SQL rather than as data.
The absence of a strong query abstraction or whitelist-based control of allowed fields and operators (CWE-943) further broadens the degree of control the attacker has over the final query shape.
Conceptually, this reflects the classic SQL injection bug class: treating user input as part of the query syntax instead of binding it as a parameter.
Potential impact
- Unauthorized reading of sensitive tables, including user account data and hashed passwords.
- Disclosure of business-critical data such as invoices, customer records, accounting entries, and configuration settings.
- Enumeration of database schema (tables, columns, indices) to support broader abuse.
- Potential pivoting to other weaknesses if sensitive configuration secrets or connection details are stored in the database.
- Integrity risks if the injection point can be extended to modify or delete data, depending on the precise query context and permissions.
General mitigation guidance
Effective mitigation focuses on eliminating ad-hoc SQL string concatenation and tightening input handling around query construction:
- Use parameterized queries or ORM-style query builders for all dynamic values, including search terms, ordering, and filtering parameters.
- Introduce strict server-side validation for autocomplete inputs, enforcing type checks, maximum length, and a whitelist of allowed fields and operators.
- Centralize query-building logic in well-reviewed helper functions to avoid repeated error-prone concatenation patterns in different models or controllers.
- Apply least-privilege principles to the database user account so that application queries cannot access or modify more data than necessary.
- Design autocomplete features to return only minimal, non-sensitive fields and limit result sizes to reduce data exposure if other controls fail.
How teams detect issues like this
Organizations can look for this and similar issues using several complementary approaches:
- Static analysis: Configure rules to flag raw SQL construction that interpolates request parameters or variables derived from user input, especially in shared model methods like
CodeModel::all(). - Code review: During manual review, pay close attention to autocomplete, search, and reporting features where dynamic filters, sorting, or conditions are built; verify that all dynamic parts use bound parameters or vetted whitelists.
- Security testing: Use parameter tampering in QA and staging environments, sending typical SQL injection patterns through autocomplete endpoints and inspecting responses for error messages or unexpected data.
- Policy enforcement: Establish coding standards that prohibit direct SQL concatenation in favor of safer query abstractions, and enforce these via pre-commit hooks, CI checks, or automated code review tools.

