Summary
ERPNext contains a SQL injection vulnerability in the Inactive Customers report because an authenticated user's doctype filter is not validated before being inserted into raw SQL queries.
An attacker with valid ERPNext access may exploit this behavior to alter database queries and extract sensitive information.
Affected context
The issue occurs in ERPNext's Inactive Customers report, specifically where the doctype filter is processed by sales-detail and last-sales-amount queries. Deployments may be at risk when authenticated users can submit or influence this filter and the application constructs SQL statements through direct string interpolation rather than parameterized query handling.
Exploit preconditions
- Attack surface: The ERPNext Inactive Customers report
- Required access: An authenticated ERPNext account with permission to reach the affected reporting functionality
- Trigger point: Processing of the doctype filter in the sales-detail and last-sales-amount database queries
- Why exploitation is possible: The filter is accepted without adequate validation and is interpolated into raw SQL, allowing user-controlled input to influence query structure
Why this happens
The underlying bug is an unsafely constructed database query that combines user-controlled input with SQL text. Because the doctype filter is not constrained through strict allowlisting or safely bound as a query parameter, an attacker may affect the meaning of the resulting statement. This behavior maps to CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection').
Potential impact
- An attacker may retrieve sensitive business or customer information
- Database queries could be altered or broadened beyond their intended scope
- Confidentiality and integrity of ERP data could be affected
- Application availability may be impacted by resource-intensive or malformed queries
- Compromised data could support further attacks against business workflows
General mitigation guidance
Mitigation generally focuses on removing user influence over SQL syntax and reducing trust in report filters.
Common defensive patterns include:
- Use parameterized queries or framework query builders for all dynamic values
- Apply strict allowlists for fields, doctypes, and other query-shaping inputs
- Separate identifiers from values and avoid direct string interpolation
- Validate inputs against expected types, formats, and permitted application context
- Enforce least-privilege database permissions for the application account
- Restrict report access according to business need and role permissions
- Prefer secure-by-default reporting APIs that do not expose raw query construction
How teams detect issues like this
Organizations can look for this weakness through:
- Static analysis rules identifying string interpolation or concatenation in SQL statements
- Code review checks for report filters passed directly into query-building logic
- Tests that verify invalid doctypes and unexpected filter values are rejected
- Runtime monitoring for anomalous report queries, broad data access, and unusual database errors
- Policy enforcement requiring parameterized queries or approved database abstraction layers
- Automated security review tools that flag CWE-89 patterns during development

