Summary
Trilium's sync update handling can interpret crafted entity names and column keys as SQL, rather than treating them strictly as data. A malicious sync partner who can submit data to the affected sync endpoints may be able to read sensitive database records or write arbitrary rows.
Affected context
The vulnerability affects Trilium through version 0.107.0 in the updateNormalEntity() sync update path. It may arise when data submitted through /api/sync/changed or PUT /api/sync/update is used to construct database queries without safely separating SQL syntax from supplied entity names and column keys.
Exploit preconditions
- Attack surface: Trilium synchronization API endpoints
- Required access: The ability to submit sync data as a partner; the exact authentication requirements depend on deployment configuration
- Trigger point: Processing crafted entity names or column keys during a sync update
- Why exploitation is possible: If supplied values are incorporated into SQL structure without safe parameterization or strict validation, they may alter the resulting query
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 insecure pattern is building or modifying SQL statements using externally supplied identifiers or values without safely constraining them to expected database fields and binding values as parameters.
Potential impact
- An attacker may be able to read sensitive records, including session, API-token, or user-data information
- Database rows could be created or modified without authorization
- Application data integrity and confidentiality could be compromised
- Changes to stored data could disrupt synchronization or application behavior
General mitigation guidance
Mitigation generally focuses on preventing untrusted sync data from influencing SQL syntax.
Common defensive patterns include:
- Using parameterized queries for all user-controlled values
- Mapping permitted entity and column names through strict allowlists, since SQL parameters do not safely substitute identifiers
- Validating sync records against explicit schemas before database operations
- Limiting sync-partner permissions and database privileges to the minimum required
- Treating data from connected or trusted partners as untrusted at the database boundary
How teams detect issues like this
Detection approaches may include:
- Static analysis for SQL statements assembled through string concatenation or interpolation
- Code review of sync handlers, especially uses of entity names and column keys in query construction
- Tests that verify malformed or unexpected identifiers are rejected and values cannot alter query structure
- Policy checks requiring parameterized SQL and allowlisted database identifiers
- Monitoring sync requests and database activity for unexpected query patterns or changes to sensitive tables

