Summary
The SiYuan kernel WebSocket server accepts unauthenticated connections when a specific "auth keepalive" query parameter is present, then parses attacker-controlled JSON using unchecked type assertions.
A remote attacker can send malformed messages that trigger a runtime panic, potentially crashing the kernel process and causing denial of service against the SiYuan kernel.
Affected context
This vulnerability affects SiYuan deployments exposing the kernel WebSocket server, particularly when reachable over a network interface (e.g., localhost proxies, LAN, or remote access setups).
The issue occurs when the server treats the presence of a specific "auth keepalive" query parameter as sufficient for accepting a WebSocket connection without enforcing full authentication.
Once connected, the kernel uses unchecked type assertions on incoming JSON messages, so malformed or unexpected message structures can cause runtime panics and terminate the kernel process.
Exploit preconditions
- Attack surface: SiYuan kernel WebSocket endpoint, accessible over HTTP(S)/WebSocket from the attacker's network location.
- Required access: Network-level access to the WebSocket server; no valid user credentials or prior session needed when the "auth keepalive" parameter is abused.
- Trigger point: Establishing a WebSocket connection with the special query parameter and sending crafted JSON messages containing unexpected types or structures.
- Why exploitation is possible:
- The server treats a query parameter as a de facto authentication bypass condition (CWE-306: Missing Authentication for Critical Function).
- The message handler performs unchecked type assertions on attacker-controlled JSON, allowing malformed data to trigger runtime panics (CWE-248: Uncaught Exception or Error Condition).
Why this happens
The vulnerability stems from two interacting design flaws:
- Weak authentication gate for a critical interface (CWE-306):
The WebSocket kernel interface is a sensitive control plane surface. Instead of enforcing robust authentication and session validation, it uses the presence of an "auth keepalive" query parameter as a proxy signal, allowing unauthenticated clients to establish a connection.
- Unchecked type assertions on untrusted JSON (CWE-248):
Once connected, the server assumes that incoming messages conform to expected JSON schemas and uses direct type assertions without validating the actual runtime types. When an attacker sends JSON shaped to violate these assumptions, the resulting failed type assertion triggers a runtime panic. Because the panic is not properly caught and handled, it propagates to the kernel process, terminating it and causing denial of service.
Potential impact
- Remote denial of service against the SiYuan kernel by repeatedly triggering panics.
- Loss of availability of the personal knowledge management interface and background services.
- Potential loss of unsaved data if the kernel crashes during active editing or synchronization.
- Degradation of user trust and reliability in environments where SiYuan is used as a critical knowledge store.
General mitigation guidance
Effective mitigation generally focuses on strengthening authentication and hardening error handling on critical endpoints:
- Enforce strong authentication on WebSocket endpoints:
- Tie WebSocket access to fully validated user sessions or API tokens instead of relying on special query parameters.
- Treat any query parameters used for keepalive or session hints as advisory only, not as authentication substitutes.
- Validate and sanitize all incoming message types:
- Parse JSON into well-defined request structures and validate fields before performing type assertions or business logic.
- Replace unchecked type assertions with safer patterns that perform type checks and return errors instead of panicking on mismatch.
- Introduce robust error handling and process resilience:
- Catch and handle runtime errors at boundaries between the network layer and core logic, returning protocol errors rather than allowing panics to crash the kernel.
- Consider using centralized panic recovery middleware in WebSocket/message handlers to protect the process from single-request failures.
- Apply least-privilege exposure and network controls:
- Limit exposure of the kernel WebSocket server to trusted networks or localhost when possible.
- Use host firewalls, reverse proxies, or VPNs to narrow who can initiate WebSocket connections.
How teams detect issues like this
Detection strategies can combine code-centric and operational approaches:
- Static analysis and code review:
- Search for WebSocket handlers or HTTP endpoints that:
- Accept connections or perform critical actions based on query parameters alone.
- Reference fields like "auth", "keepalive", or "token" without validating against a proper authentication system.
- Identify unchecked type assertions on data originating from JSON unmarshal operations or other untrusted inputs.
- Flag any panic-prone patterns in request handlers without recovery logic.
- Runtime monitoring and logging:
- Enable detailed logging for WebSocket connection attempts, including query parameters and authentication decisions.
- Monitor application logs for panic stack traces or abnormal kernel restarts, especially correlated with WebSocket traffic.
- Security testing and policy enforcement:
- Incorporate fuzzing of WebSocket message schemas to reveal crash-prone assumptions in message handling.
- Use CI/CD policies that require security review of new network endpoints and forbid unauthenticated access to control-plane APIs.
- Optionally adopt automated security scanners that can recognize missing authentication checks and unsafe assertion patterns.

