Summary
Frappe ERPNext has an SQL injection vulnerability in an endpoint used by the Selling and Buying modules: caller-supplied data can override a value that was validated earlier and reach a database query without adequate validation. An authenticated user, including a portal user with no roles, could exploit this behavior to access sensitive data such as active session information and potentially take over other accounts.
Affected context
The issue is described in Frappe ERPNext 4.3.0 before 15.121.6 and 16.x before 16.37.0. It occurs in an endpoint associated with the Selling and Buying modules when caller-supplied request data can replace an earlier validated value and is used in a database query without adequate safeguards. The vulnerability is risky when an authenticated user can reach that endpoint.
Exploit preconditions
- Attack surface: An endpoint in the Selling or Buying modules
- Required access: Authentication; the description notes that portal users with no roles may be able to access it
- Trigger point: A request handled by the affected endpoint
- Why exploitation is possible: Caller-supplied data can override a value validated earlier and reach a database query without adequate validation or safe query handling
Why this happens
This is an SQL injection flaw, mapped to CWE-89: Improper Neutralization of Special Elements used in an SQL Command. The underlying pattern is that request data reaches a database query after a prior validation step can be bypassed or overridden. When query inputs are not safely bound or otherwise constrained, data may be interpreted as part of the SQL command rather than only as a value.
Potential impact
- An attacker may retrieve sensitive database records, including active session data.
- An attacker could use exposed information to take over other user accounts, potentially including administrator accounts.
- Data confidentiality and the integrity of affected accounts may be compromised.
General mitigation guidance
Defensive approaches focus on keeping request data separate from SQL command structure and ensuring that validation applies to the final value used by the query.
- Use parameterized queries or equivalent safe database APIs.
- Avoid allowing caller-controlled fields to shape SQL statements.
- Apply strict allowlists and type checks after request data has been normalized and resolved.
- Limit database and application permissions to the minimum needed.
- Reduce the privileges and reach of portal accounts, and restrict access to sensitive endpoints where appropriate.
How teams detect issues like this
- Use static analysis rules to flag query construction that combines SQL with request-derived values.
- Review endpoint code for fields that are validated and later overwritten, transformed, or sourced again before database use.
- Check that database access consistently uses parameter binding and that validation occurs at the final query boundary.
- Apply policy checks in code review or CI to prevent unsafe query-building patterns.
- Monitor for unusual query errors, data-access patterns, or session activity that may indicate attempted or successful abuse.

