/

CVE-2026-25513

Severity:

HIGH RISK

(8.8)

SQL Injection in FacturaScripts REST API

CVE-2026-25513

Analyzed

Vulnerability type

Category:

SQL Injection

CWE:

CWE-20, CWE-89, CWE-943, CWE-1286

Impact:

Authenticated SQL Injection with Potential Data Exposure and Manipulation

Severity:

HIGH RISK

(8.8)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

FacturaScripts REST API contained an authenticated SQL injection flaw where the sort parameter was concatenated directly into the ORDER BY clause of dynamically built queries.

Authenticated API clients could abuse this to execute crafted SQL, potentially accessing or manipulating data beyond their intended permissions whenever sortable API endpoints were invoked.

Affected context

The vulnerability occurs in FacturaScripts deployments that expose the REST API and allow authenticated users or API integrations to specify a sort parameter on list or search endpoints.

The issue lies in the ModelClass::getOrderBy() method, which constructs the SQL ORDER BY clause by concatenating user-controlled sorting fields without robust validation.

Any endpoint that supports sorting and relies on this helper is affected, especially where database users have broad read or write privileges.

Exploit preconditions

  • Attack surface: REST API endpoints that accept a sort or similar parameter for ordering results.
  • Required access: Valid, authenticated API credentials (user, integration token, or similar).
  • Trigger point: Supplying crafted sorting input that is passed to ModelClass::getOrderBy() and incorporated into the SQL ORDER BY clause.
  • Why exploitation is possible: The application directly interpolates user-controlled input into SQL without sufficient validation, quoting, or whitelisting, violating robust query construction practices and enabling SQL injection in the ORDER BY context.

Why this happens

This vulnerability stems from constructing SQL queries by concatenating untrusted input into the ORDER BY clause in ModelClass::getOrderBy().

Instead of restricting sorting to a predefined set of column names and using parameterized or safely quoted identifiers, the method trusts the client-supplied sort parameter and appends it directly into the SQL string.

This pattern corresponds to CWE-89: Improper Neutralization of Special Elements used in an SQL Command, with contributing issues from CWE-20 (Improper Input Validation) and CWE-943 (Improper Neutralization in SQL Calls).

The lack of defensive checks on allowed columns and direction flags, combined with dynamic SQL construction, enables crafted input to alter the intended query structure.

Potential impact

  • Authenticated users could execute crafted SQL expressions within the ORDER BY clause, potentially leading to data exposure or logic abuse.
  • Attackers may infer or exfiltrate sensitive data through error-based, timing-based, or boolean behavior differences, depending on database configuration.
  • Data integrity could be impacted if the same database connection is used for both read and write operations and the injected fragment permits write-capable statements.
  • Application stability may be affected by expensive or malformed queries, leading to performance degradation or denial of service for affected endpoints.
  • In some environments, SQL injection could be combined with other misconfigurations to escalate privileges or pivot to other parts of the infrastructure.

General mitigation guidance

Mitigation focuses on treating sort parameters as untrusted input and enforcing strict control over how they are translated into SQL:

  • Restrict sortable fields to a whitelist of known column names and map external parameter values to internal identifiers (e.g., via an array or enum).
  • Normalize sort direction (e.g., asc/desc) and validate it against a fixed set of allowed tokens instead of trusting arbitrary strings.
  • Build queries using parameterized statements and safe identifier handling where supported; avoid concatenating user input into raw SQL fragments.
  • Encapsulate query construction in a dedicated data-access layer or ORM that exposes high-level ordering APIs rather than manual SQL assembly.
  • Apply least-privilege to the database account used by the application so that even if injection occurs, accessible operations and data are minimized.
  • Treat API parameters, including those used for non-filtering purposes like sorting or pagination, as fully untrusted and subject to consistent validation rules.

How teams detect issues like this

Detection can leverage both code-centric and behavior-centric approaches:

  • Static analysis: Configure rules to flag dynamic SQL construction where user input influences ORDER BY, GROUP BY, or other structural clauses without whitelisting or proper validation.
  • Code review: Look for helper methods (such as getOrderBy() or similar) that accept client parameters and return SQL fragments; verify that they enforce an explicit, finite set of allowed fields and directions.
  • Unit and integration tests: Add tests that send intentionally malformed or SQL-like sort parameters and assert that the application rejects them safely without altering the query structure.
  • Database monitoring: Enable query logging or use a database proxy to detect anomalous patterns in ORDER BY clauses (e.g., unexpected functions, subqueries, or injected operators originating from API requests).
  • Automated scanning: Use API-focused security testing tools that attempt injection through non-obvious parameters (sort, order, page, filter) and monitor for errors, timing differences, or data leakage.

Sources

SourceLink
github.comgithub.com/NeoRazorX/facturascripts/commit/1b6cdfa9ee1bb3365ea4a4ad753452035a027605
github.comgithub.com/NeoRazorX/facturascripts/security/advisories/GHSA-cjfx-qhwm-hf99

Frequently asked

questions

Yes, but only through authenticated access. Any remote client or integration with valid API credentials and access to affected endpoints can potentially exploit the flaw by manipulating the sort parameter.

The attacker must have authenticated access to the REST API endpoints that support sorting. They do not require administrative privileges, only the ability to send crafted requests with controlled sort values.

The safest pattern is to avoid concatenating user input into SQL entirely. Instead, define a fixed mapping of allowed sort fields and directions, validate incoming parameters against that mapping, and use parameterized statements or ORM abstractions to generate the ORDER BY clause.

Establish a development standard that treats all client input as untrusted, including non-obvious fields like sorting and pagination. Centralize query construction in vetted helper functions, enforce strict input validation and whitelisting, integrate static analysis for injection patterns into CI pipelines, and regularly review API endpoints that assemble dynamic SQL.

Find out what's already
exploitable in your codebase.