Summary
A critical SQL injection vulnerability in Twenty CRM allows an authorized workspace administrator with DATA_MODEL permission to inject unescaped SQL through the system searchVector field configuration.
Under affected configurations, the injected expression may be incorporated into a generated PostgreSQL column definition and executed with the privileges of the application database user.
Affected context
The issue occurs in Twenty deployments that allow workspace field metadata to be updated through the REST metadata endpoint or the GraphQL updateOneField mutation. It becomes risky when a user with the DATA_MODEL permission can supply settings.asExpression for the system TS_VECTOR searchVector field and the server concatenates that value into a generated PostgreSQL expression without adequate escaping or structural validation.
Exploit preconditions
- Attack surface: REST metadata field updates and the corresponding GraphQL field mutation
- Required access: An authenticated workspace administrator or other principal holding the DATA_MODEL permission
- Trigger point: Processing and applying the
searchVectorfield definition through the workspace schema manager - Why exploitation is possible: The supplied expression is incorporated into
GENERATED ALWAYS AS (...)SQL without sufficient parameterization, allowing database statements to be interpreted as SQL rather than inert configuration
Why this happens
The underlying flaw is SQL construction from attacker-influenced metadata. The schema-generation routine concatenates the settings.asExpression value into a PostgreSQL generated-column definition instead of treating it as constrained data or a safely structured expression.
This behavior maps to CWE-89: Improper Neutralization of Special Elements used in an SQL Command, because input can alter the meaning of a database statement executed by the application connection.
Potential impact
- Arbitrary SQL statements may execute as the application database user
- Confidential CRM data may be read or modified
- Records, schemas, or database settings could be altered or deleted
- Database integrity and service availability could be disrupted
- Compromise may extend to other systems reachable through database credentials or integrations
General mitigation guidance
Mitigation generally focuses on preventing user-controlled metadata from becoming executable SQL.
Common defensive patterns include:
- Allow only predefined, server-controlled expressions for system-generated fields
- Use structured query-building and parameterization wherever values are inserted into SQL
- Apply strict allowlists for identifiers, operators, functions, and expression forms when dynamic SQL is unavoidable
- Reject expression settings that are not valid for the specific field type and lifecycle
- Enforce authorization and least privilege for schema and metadata operations
- Use a database role with only the permissions required by normal application behavior
- Apply defense-in-depth monitoring and isolation around schema-changing operations
How teams detect issues like this
Organizations can detect related risks through:
- Static analysis rules for string concatenation or interpolation into SQL statements
- Code review checks for dynamic DDL and generated-column definitions built from API or GraphQL input
- Tests that submit metacharacters and unexpected SQL constructs to metadata fields and verify rejection
- API policy enforcement that restricts expression-bearing fields to trusted, predefined values
- Database audit logging for unusual DDL, schema changes, or statements issued by the application role
- Automated security review tools that flag unparameterized query construction and missing input allowlists

