Summary
A SQL injection vulnerability in Chatwoot's conversation and contact filter APIs allows authenticated users to inject arbitrary SQL when filtering on custom attributes of type date or number using comparison operators.
Because user-supplied filter values are interpolated directly into SQL without parameterization, an attacker can perform time-based blind SQL injection to exfiltrate or manipulate data within the application database.
Affected context
The vulnerability appears in Chatwoot deployments where:
- Users can authenticate and access at least one account
- Conversation and contact filtering is exposed via:
POST /api/v1/accounts/{account_id}/conversations/filterPOST /api/v1/accounts/{account_id}/contacts/filterPOST /api/v1/accounts/{account_id}/custom_attribute_definitions- Custom attributes of type date or number are used in filters
- The
is_greater_thanoris_less_thanoperators are accepted and processed
In these contexts, filter payloads are transformed into SQL where user-controlled values end up directly embedded into query fragments.
Exploit preconditions
- Attack surface: Application API endpoints for conversation, contact, and custom attribute filters.
- Required access: Valid authenticated user account with permission to call the affected APIs for a given
account_id. - User-controlled input: The
valuesfield in the filter payload when filtering on custom attributes of type date or number withis_greater_thanoris_less_than. - Trigger point: Server-side request handling that builds dynamic SQL strings from filter conditions and interpolates the
valuesarray without using prepared statements or parameter binding. - Why exploitation is possible: The filter implementation concatenates raw user input into SQL expressions, allowing crafted values to alter the query structure and enabling time-based blind SQL injection techniques.
Why this happens
The core issue is dynamic SQL construction without proper parameterization, an instance of CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection').
Instead of using bound parameters or an ORM query builder, the filtering logic for custom attributes constructs SQL fragments by directly interpolating user-supplied values into comparison expressions for date and numeric fields. Because this logic does not enforce strict typing or escape special characters at the query layer, attackers can craft values that break out of the expected literal context and inject additional SQL. The bug is conceptual: treating query structure and untrusted filter data as a single concatenated string rather than separating them via parameter binding and whitelisted operators.
Potential impact
- Attackers may read sensitive data from tables accessible to the application, including conversations, contacts, and related metadata.
- Attackers could modify or delete records (e.g., conversations, contacts, or custom attribute definitions) within the database.
- Attackers may escalate their logical permissions by manipulating account-related data, depending on schema and business logic.
- Attackers could perform time-based blind probing of the database schema and configuration, aiding further compromise.
- Attackers might impact application availability by crafting queries that cause long-running operations or lock contention.
General mitigation guidance
Effective mitigation focuses on structurally separating query logic from untrusted data and minimizing the scope of dynamic SQL:
- Use parameterized queries or ORM query builders so that all user-supplied values, including filter
values, are passed as bound parameters rather than concatenated into SQL strings. - Restrict filter operators and fields to a well-defined whitelist and avoid building arbitrary SQL fragments based on user-controlled strings.
- Enforce strict type handling for numeric and date inputs at the API boundary, rejecting values that cannot be safely parsed into expected native types before reaching the data access layer.
- Implement centralized query-construction utilities for dynamic filtering instead of ad hoc string concatenation, ensuring consistent use of parameterization patterns.
- Apply least-privilege database roles so that the application account only has the minimum required permissions, reducing the blast radius of any injection.
How teams detect issues like this
Detection can focus on both code-level and operational signals:
- Static analysis: Configure rules to flag any SQL construction patterns that use string concatenation or interpolation with request-derived data (e.g., filter parameters, JSON fields), especially in filtering or reporting modules.
- Code review: During manual review, pay attention to dynamic filter/query builders and ensure they rely on prepared statements or ORM abstractions rather than raw SQL strings assembled from user input.
- Unit and integration tests: Add tests that supply unexpected characters and SQL metacharacters in filter
valuesto verify they are safely handled or rejected. - Runtime monitoring: Use database logs or an intrusion detection layer (e.g., WAF or database firewall) to detect anomalous queries, such as those containing time-delay functions or unusual control structures that suggest time-based blind probing.
- Policy enforcement: Adopt coding standards that prohibit direct concatenation of user input into SQL and enforce them via automated checks in the CI/CD pipeline.

