Summary
A critical SQL injection vulnerability in grocy v4.6.0 affects the product-group parameter of the /stockreports/spendings endpoint, allowing crafted input to be interpreted as part of a database query.
Under conditions where user-controlled values are concatenated into SQL statements without proper sanitization, an attacker may access or manipulate sensitive database information.
Affected context
The vulnerability occurs in grocy v4.6.0 within the stock reporting functionality, specifically when handling the product-group parameter on the /stockreports/spendings route.
It is relevant in deployments where this endpoint is exposed to users who can influence the product-group value, and where backend code builds SQL queries using that parameter without robust parameterization or validation.
Exploit preconditions
- Attack surface: HTTP interface exposing
/stockreports/spendings - Required access: Ability to send requests with attacker-controlled
product-groupparameter - Trigger point: Processing of the
product-groupvalue during construction of a SQL query for spendings/stock reports - Why exploitation is possible: The application incorporates unsanitized user input directly into SQL statements instead of using bound parameters or safe query builders, enabling crafted input to alter query structure
Why this happens
This issue stems from building SQL statements by directly interpolating or concatenating the product-group parameter into the query string.
Such patterns bypass the protections provided by prepared statements and parameterized queries, allowing user-controlled data to change the semantics of the query rather than being treated solely as data.
Conceptually, this maps to CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection'), where input is not properly constrained, escaped, or parameterized before being sent to the database.
Potential impact
- Access to sensitive database records that the attacker is not authorized to view
- Enumeration of application tables, columns, and schema metadata
- Modification or deletion of stock, inventory, or user-related data
- Bypassing of application-level access controls enforced in the business logic
- Potential pivoting to other vulnerabilities if database content is leveraged for further attacks
General mitigation guidance
Mitigation should focus on eliminating direct string concatenation of user input into SQL and enforcing strict separation between code and data.
Common defensive patterns include:
- Using parameterized queries or prepared statements for all database interactions, including reporting features
- Employing query builder or ORM layers that treat user input as bound parameters by default
- Validating and constraining the
product-groupparameter to expected identifiers or enumerated values before use - Applying least-privilege to database accounts so that queries executed by the application have only the minimal required permissions
- Centralizing database access patterns to make it easier to enforce secure defaults across all endpoints
How teams detect issues like this
Detection approaches typically combine code-level analysis with runtime monitoring:
- Static analysis rules that flag string concatenation or formatting functions used to construct SQL commands, especially with HTTP parameters like
product-group - Code review checklists emphasizing the use of parameterized queries and discouraging dynamic SQL composition without strict whitelisting
- Automated testing or fuzzing that injects SQL meta-characters into parameters and observes anomalous database responses or errors
- Database monitoring and logging policies that surface unusual query patterns, especially those containing raw user-supplied fragments

