Summary
Some ERPNext HTTP endpoints prior to version 16.9.0 are vulnerable to SQL injection when handling specially crafted requests, allowing untrusted input to be embedded directly into database queries.
Under these conditions, a malicious actor may extract sensitive information from the ERP database and potentially pivot to broader data exposure depending on query context and permissions.
Affected context
The vulnerability affects ERPNext deployments using versions prior to 16.9.0 where certain web-accessible endpoints build SQL queries using request parameters without robust parameterization or validation.
It is most relevant in environments where these endpoints are exposed over a network (e.g., Internet-facing or intra-organization) and backed by a relational database containing business-critical ERP data such as financial records, customer details, or operational information.
Exploit preconditions
- Attack surface: HTTP(S) endpoints in ERPNext that accept query-related parameters (e.g., filters, search parameters, or identifiers).
- Required access: Ability to send crafted HTTP requests to the affected endpoints; this may be possible to both authenticated and unauthenticated users depending on how the site is configured.
- Trigger point: The application concatenates or embeds user-controlled parameters into SQL queries that are executed by the backend database.
- Why exploitation is possible: Input is not consistently parameterized or sanitized, allowing attacker-controlled syntax to alter the structure of the SQL query instead of being treated purely as data.
Why this happens
The issue stems from constructing SQL statements using string concatenation or interpolation of request parameters instead of using parameterized queries or a safe query abstraction.
This aligns with CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection'), where the application mixes control and data channels and fails to neutralize metacharacters like quotes, operators, or logical expressions.
In abstract terms, any code path that directly embeds user input into SQL without binding it as a parameter makes the query interpreter treat attacker input as executable query logic, enabling unauthorized data reading and manipulation.
Potential impact
- Unauthorized reading of sensitive records such as customer data, financial information, or internal operational data.
- Enumeration of database schema, including table names, column names, and metadata.
- Circumvention of application-level access controls at the data layer by directly querying tables.
- Potential chaining with other weaknesses to escalate impact, such as discovering credentials or secrets stored within the database.
General mitigation guidance
Mitigations generally focus on separating data from control in all database access layers and shrinking the trust boundary of user input:
- Use parameterized queries or ORM abstractions that bind values separately from SQL structure in every data-access path.
- Apply strict input validation and allowlisting on request parameters that influence filtering, sorting, or selection logic.
- Centralize query-building utilities to reduce ad-hoc string-based SQL construction and to enforce safe patterns by default.
- Configure database accounts used by the application with least-privilege, limiting the scope of data accessible through any single compromised query.
- Implement consistent secure coding guidelines and training around query construction for developers working on ERPNext extensions or custom endpoints.
How teams detect issues like this
Organizations can approach detection through a combination of code-level and runtime techniques:
- Static analysis: Configure rules to flag string-built SQL queries, concatenation of request parameters into query strings, or dynamic WHERE/ORDER BY clauses without parameter binding.
- Code review: Pay particular attention to custom endpoints, reporting features, and search/filter functions that directly transform request parameters into SQL fragments.
- Policy enforcement: Introduce coding standards that mandate use of a standard query abstraction layer and forbid raw SQL concatenation, enforced via linters or pre-commit hooks.
- Runtime monitoring: Analyze database logs and application logs for anomalous queries containing suspicious patterns (e.g., tautologies, UNION clauses, or comment markers originating from user input).

