Summary
SiYuan before v3.7.3 exposes a critical SQL injection flaw in the fullTextSearchAssetContent endpoint, allowing untrusted input to be concatenated directly into database queries.
An unauthenticated attacker or a holder of a RoleReader publish token can execute arbitrary SQL against the read-write asset-content database, making cross-notebook data readable, modifiable, or deletable under vulnerable configurations.
Affected context
This vulnerability appears in SiYuan deployments that expose the fullTextSearchAssetContent endpoint over a network interface, including instances reachable from the internet or shared workspaces.
It is particularly relevant where RoleReader publish tokens are used to grant read access to asset content, and where the asset-content database runs in a read-write mode with broad access to notebook data.
The risk increases when the search API constructs SQL queries directly from request parameters or token-scoped filters without robust sanitization or query parameterization.
Exploit preconditions
- Attack surface: HTTP API endpoint fullTextSearchAssetContent used for asset content search.
- Required access: Network access to the SiYuan instance; exploitation can occur unauthenticated or via valid RoleReader publish tokens depending on configuration.
- Trigger point: Invocation of the search endpoint with crafted parameters influencing SQL query fragments and REGEXP clauses.
- Why exploitation is possible: User-controlled method parameters are interpolated into SQL statements without proper escaping or parameter binding, allowing arbitrary SQL fragments to be injected and executed by the database engine.
Why this happens
The root cause is reliance on dynamically constructed SQL queries that embed user-supplied values directly into WHERE and REGEXP clauses.
Instead of using parameterized queries or well-defined query builders, the implementation appears to concatenate search parameters into SQL strings, trusting that inputs will be benign.
This pattern maps to CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection'), where metacharacters and operators (such as quotes, wildcards, and regex syntax) are not neutralized or correctly bound, enabling attackers to alter query structure.
Potential impact
- Attackers may read sensitive cross-notebook data stored in the asset-content database.
- Malicious queries could modify or corrupt notebook entries, metadata, or shared assets.
- Asset content and related structures can be deleted, leading to data loss across multiple notebooks.
- Compromised data integrity may undermine collaboration, auditability, and user trust in stored notes.
- Under certain database configurations, injected SQL could affect other schemas or auxiliary tables connected to the same instance.
General mitigation guidance
Effective mitigation focuses on eliminating direct string-based SQL construction and tightening access boundaries around search endpoints.
Common defensive patterns include:
- Using parameterized queries or ORM query builders that separate SQL structure from data values.
- Restricting and validating all search parameters against a strict schema, including allowed operators and formats for REGEXP usage.
- Applying least-privilege to database accounts so that search operations have minimal write or delete capabilities.
- Introducing application-level permission checks to ensure publish tokens and anonymous access cannot drive powerful data-manipulating queries.
- Designing APIs to expose high-level search capabilities without directly translating user input into raw SQL fragments.
How teams detect issues like this
Detection typically relies on recognizing insecure query construction and abnormal query behavior.
Organizations can:
- Use static analysis rules to flag string concatenation or template interpolation in SQL-building code paths, especially around search endpoints.
- Include security-focused code review checklists that call out unparameterized SQL, dynamic REGEXP clauses, and direct injection of request parameters into queries.
- Monitor database logs for unusually complex or malformed queries originating from search endpoints, including UNIONs, subselects, or DDL statements that should not occur in normal usage.
- Employ automated application security testing tools to exercise search APIs with injection-style payloads and detect deviations from expected behavior.

