Summary
A privilege escalation issue in the SiYuan publish service allows read-only publish users (RoleReader) to modify notebook content through the /api/block/appendHeadingChildren endpoint.
Because this endpoint only checks a generic authorization role and not stricter admin or read-only constraints, authenticated low-privilege users can append new blocks to existing documents and compromise note integrity.
Affected context
The vulnerability appears in SiYuan's publish service API, specifically in deployments where:
- Publish accounts are granted RoleReader (read-only) access,
- The /api/block/appendHeadingChildren endpoint is exposed to authenticated publish users, and
- Authorization middleware relies on model.CheckAuth without additional role checks like CheckAdminRole or CheckReadonly.
In these conditions, users assumed to have read-only permissions can still trigger content-modifying operations on shared notebooks.
Exploit preconditions
- Attack surface: Remote HTTP(S) access to the SiYuan publish service API.
- Required access: Valid authenticated publish account with RoleReader (read-only) permissions.
- Trigger point: Sending a crafted request to the /api/block/appendHeadingChildren endpoint targeting an existing document or block ID.
- Why exploitation is possible: The endpoint only verifies that the user passes a generic authorization check (model.CheckAuth) and does not verify that the caller has write or admin-level privileges, allowing state-changing operations from read-only accounts.
Why this happens
The underlying issue is an authorization design flaw where a state-changing endpoint is protected only by a coarse-grained "is authenticated" style check.
This maps to CWE-284: Improper Access Control and is closely related to CWE-862: Missing Authorization, as the API fails to enforce that only users with appropriate write or admin roles can modify notebook content.
Conceptually, the bug is that the publish service conflates any authenticated session with sufficient permission, omitting role- or operation-specific checks for content-modifying actions.
Potential impact
- Read-only publish users may append new content blocks to existing notes.
- Integrity of published notebooks and documents could be compromised or vandalized.
- Stored information can be subtly altered, potentially leading to misinformation or loss of trust in shared notes.
- Auditability and change attribution may be impacted if content changes appear to come from supposedly read-only accounts.
General mitigation guidance
Effective mitigation focuses on enforcing least privilege and operation-specific authorization on all state-changing endpoints:
- Require explicit write or admin roles (e.g., CheckAdminRole or equivalent) for any API that creates, updates, or deletes content.
- Implement fine-grained, per-endpoint authorization rules, ensuring that read-only roles are rejected for modification operations.
- Centralize authorization logic in reusable middleware so that role checks cannot be accidentally omitted on new endpoints.
- Adopt a "deny by default" strategy where endpoints require explicit permission grants instead of allowing generic authenticated access.
- Periodically review role definitions and mappings to ensure that "read-only" roles cannot reach write-capable code paths.
How teams detect issues like this
Detection typically involves both code-centric and behavior-centric approaches:
- Code review: Look for content-modifying handlers that only call generic auth checks (e.g., CheckAuth) without verifying role/permission scopes such as admin or write.
- Static analysis: Configure rules to flag HTTP handlers that perform database writes or block mutations but lack explicit role/permission enforcement.
- Access control tests: Implement automated security tests that exercise APIs with low-privilege accounts to confirm that write operations are rejected.
- Logging and monitoring: Monitor for unexpected content changes originating from accounts designated as read-only, and alert on such anomalies.

