Summary
SiYuan's block search API endpoint improperly concatenates user-controlled path values into SQL predicates, enabling SQL injection within certain search modes.
An unauthenticated visitor of a published workspace can craft requests that inject UNION queries and exfiltrate rows from otherwise hidden documents.
Affected context
The vulnerability appears in SiYuan deployments that expose the full-text block search API (POST /api/search/fullTextSearchBlock) to publish visitors or other unauthenticated users.
It specifically affects non-SQL search modes where the backend builds SQL predicates by concatenating path values derived from the request body.
When hidden or private documents share the same underlying database as visible content, injected predicates can cause sensitive rows to be returned through otherwise allowed search responses.
Exploit preconditions
- Attack surface: HTTP API endpoint
POST /api/search/fullTextSearchBlockon a SiYuan instance. - Required access: Ability to act as an unauthenticated publish visitor or any user allowed to invoke the block search endpoint.
- Trigger point: Submitting search requests containing specially crafted
pathsor related parameters that are concatenated into SQL predicates. - Why exploitation is possible: The application directly embeds attacker-controlled path values into SQL fragments without robust parameterization or validation, allowing UNION SELECT and other injected clauses to influence query results.
Why this happens
This issue stems from constructing SQL predicates by string concatenation using untrusted input from the search request.
Instead of using parameterized queries or safely constrained expressions, the backend treats path components as trusted fragments and appends them to the query used in non-SQL search modes.
This pattern maps to CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection'), where user-supplied data is interpreted as part of the SQL syntax rather than as data.
Potential impact
- Unauthorized reading of rows from hidden or private documents.
- Disclosure of internal metadata about documents, boxes, or paths not intended for publish visitors.
- Potential exposure of sensitive personal notes or knowledge base content.
- Information useful for further attacks, such as understanding data structure or internal identifiers.
General mitigation guidance
Mitigation focuses on treating all search parameters, including paths and box identifiers, strictly as data rather than query syntax.
Common defensive patterns include:
- Using parameterized queries or query builders that separate SQL logic from data values.
- Restricting allowed path values to a fixed, validated set and rejecting or normalizing unexpected input.
- Applying server-side authorization checks that filter results by the caller's visibility rules, independent of client-supplied predicates.
- Designing search modes so that higher-level filters (like visible boxes and paths) are applied after core query execution, not merged as raw SQL fragments.
How teams detect issues like this
Detection typically involves a combination of code and behavior analysis:
- Static analysis rules that flag manual SQL string construction using request-derived fields (e.g.,
path,box,filter) concatenated into WHERE or UNION clauses. - Code review checklists that require parameterized queries for all search and filtering operations, especially in public or unauthenticated endpoints.
- Dynamic testing and fuzzing of search endpoints with payloads containing quotes, parentheses, and UNION patterns to observe anomalous responses.
- Automated security testing integrated into CI/CD that scans for SQL injection patterns and enforces policies against ad-hoc query building.

